-
Posts
902 -
Cadastrado em
-
Última visita
Tipo de conteúdo
Artigos
Selos
Livros
Cursos
Análises
Fórum
Tudo que Cambalinho postou
-
@Lucca Rodrigues se eu precisar de um pixel especifico, nesse loop, como posso obter o pixel usando x e y?
-
1 - você usou o ponteiro 'pixels'... pode mostrar o loop para obter o RGB ou mesmo a cor(COLORREF)? 2 - você acha que o problema está aqui ou tenho de otimizar melhor as outras funções?
-
voltando um pouco atrás: o problema está mesmo no SetPixel() e GetPixel() ou também na divisão GetPointsLine()? eu sei que o SetPixel() e GetPixel() são lentos... se calhar tenho mesmo de usar DIB's. mas mesmo assim gostava de saber onde está a consumo maximo do tempo
-
Rodar uma imagem usando X, Y e Z. Mas tenho de usar a perspectiva. Não posso usar o BitBlt() para isso
-
#include <iostream> #include <string> #include <string.h> #include <windows.h> #include <math.h> #include <vector> #include <gdiplus.h> #include <stdlib.h> #include <algorithm> #include <thread> #include <future> #include "image.h" using namespace Gdiplus; using namespace std; /*const double PI = 3.14159265358979; struct point { float x,y,z; } ; struct angle { float x,y,z; } ;*/ point Convert3DTO2D(point Position, float FocalDistance=0.05) { point Point2D; Point2D.x=Position.x * FocalDistance/Position.z; Point2D.y=Position.y*FocalDistance/Position.z; return Point2D; } angle ConvertDegreesToRadians(angle Rotation) { double deg2Rad; deg2Rad = PI / 180; angle ConvertDegrees; ConvertDegrees.x = Rotation.x * deg2Rad; ConvertDegrees.y = Rotation.y * deg2Rad; ConvertDegrees.z = Rotation.z * deg2Rad; return ConvertDegrees; } point RotationPoints2(point Coordenate, const angle AngleCoordenate, const point pivot={0,0,0}) { angle radians= ConvertDegreesToRadians(AngleCoordenate); point RotatedPoint; RotatedPoint=Coordenate; Coordenate.x-=pivot.x; Coordenate.y-=pivot.y; Coordenate.z-=pivot.z; //First we rotate the Z: RotatedPoint.x=Coordenate.x * cos(AngleCoordenate.z)-Coordenate.y*sin(AngleCoordenate.z); RotatedPoint.y=Coordenate.x * sin(AngleCoordenate.z)+Coordenate.y*cos(AngleCoordenate.z); //RotatedPoint.z=Coordenate.z; //Second we rotate the Y: RotatedPoint.x=RotatedPoint.x * cos(AngleCoordenate.y)+RotatedPoint.z*sin(AngleCoordenate.y); //RotatedPoint.y=RotatedPoint.y; // pointless self assignemnt RotatedPoint.z=-RotatedPoint.x * sin(AngleCoordenate.y)+RotatedPoint.z*cos(AngleCoordenate.y); //Third we rotate the X: //RotatedPoint.x=RotatedPoint.x; // pointless self assignemnt RotatedPoint.y=RotatedPoint.y * cos(AngleCoordenate.x)-RotatedPoint.z*sin(AngleCoordenate.x); RotatedPoint.z=RotatedPoint.y * sin(AngleCoordenate.x)+RotatedPoint.z*cos(AngleCoordenate.x); RotatedPoint.x+=pivot.x; RotatedPoint.y+=pivot.y; RotatedPoint.z+=pivot.z; return RotatedPoint; } point RotationPoints(point pt, angle Angle, point pivot={0,0,0},point scale={1,1,1}) { angle radians= ConvertDegreesToRadians(Angle); Angle.x =radians.x; Angle.y =radians.y; Angle.z =radians.z; point p={pt.x-pivot.x,pt.y-pivot.y,pt.z-pivot.z}; point rot,temp; temp={(p.y)*cos(Angle.x)+(-p.z)*sin(Angle.x),(p.z)*cos(Angle.x)+(p.y)*sin(Angle.x)}; rot.y=temp.x;rot.z=temp.y; p.y = rot.y;p.z = rot.z; temp={(p.z)*cos(Angle.y)+(-p.x)*sin(Angle.y),(p.x)*cos(Angle.y)+(p.z)*sin(Angle.y)}; rot.z=temp.x;rot.x=temp.y; p.x=rot.x; temp={(p.x)*cos(Angle.z)+(-p.y)*sin(Angle.z),(p.y)*cos(Angle.z)+(p.x)*sin(Angle.z)}; rot.x=temp.x;rot.y=temp.y; return {(scale.x*rot.x+pivot.x),(scale.y*rot.y+pivot.y),(scale.z*rot.z+pivot.z)}; } float GetLineLength(point p1,point p2) { return sqrt( (p1.x-p2.x)* (p1.x-p2.x) + (p1.y-p2.y)* (p1.y-p2.y) + (p1.z-p2.z)* (p1.z-p2.z)); } //Get Points Line: point lineto(point fp,point p,float length) { point res; float L=GetLineLength(fp,p); res.x=fp.x+length*(p.x-fp.x)/L; res.y=fp.y+length*(p.y-fp.y)/L; res.z=fp.z+length*(p.z-fp.z)/L; return res; } vector<point> GetPointsLine(point origin,point destination) { point t=origin; vector<point> coordenates; float dst=GetLineLength(origin,destination); for (int i=0;i<=dst;i++) { t=lineto(t,destination,1); coordenates.push_back(t); } return coordenates; } point perspective(const point &p,const point &eyepoint) { float w=1+(p.z/eyepoint.z); return {(p.x-eyepoint.x)/w+eyepoint.x, (p.y-eyepoint.y)/w+eyepoint.y, (p.z-eyepoint.z)/w+eyepoint.z}; } //Draw a Line: void DrawLine(HDC WindowHDC,point origin,point destination,COLORREF color=RGB(0,0,255) ) { //for convert 3D to 2D we must: //have Focal Distance, in these case is 100 //float FocalDistance =100; //2D.X = 3D.X * FocalDistance / 3D.Z //2D.Y = 3D.Y * FocalDistance / 3D.Z //Getting the Points of a line: vector<point> coordenates; //origin.z=-origin.z; //destination.z=-destination.z; coordenates = GetPointsLine(origin,destination); point eyepoint={250,150,300}; //now we draw the line with a color and convert the 3D to 2D: for (point LinePoints:coordenates) { point p=perspective(LinePoints,eyepoint); //SetPixel(WindowHDC,p.x,p.y,color); std::thread thread_obj(SetPixel, WindowHDC,p.x,p.y,color); thread_obj.join(); } } void DrawRectangle(HDC WindowHDC,point Top, point Left, point Right, point Bottom,COLORREF color=RGB(255,0,0) ) { //for convert 3D to 2D we must: //have Focal Distance, in these case is 100 //2D.X = 3D.X * FocalDistance / 3D.Z //2D.Y = 3D.Y * FocalDistance / 3D.Z float FocalDistance =100; //Getting the Points of a line: vector<point> coordenates; /* coordenates = GetPointsLine(origin,destination); point eyepoint={250,150,300}; //now we draw the line with a color and convert the 3D to 2D: for (point LinePoints:coordenates) { point p=Convert3DTO2D(LinePoints); //perspective(LinePoints,eyepoint); SetPixel(WindowHDC,p.x,p.y,color); }*/ } //Draw an Image: void DrawImage(HDC HDCWindow,point corners[4], HDC HDCOrigin, int PosX, int PosY, int Width, int Height) { POINT ImageCordeners[3]; //Move Top-Left Corner: ImageCordeners[0].x=corners[0].x; ImageCordeners[0].y=corners[0].y; //Move Top-Right Corner: ImageCordeners[1].x=corners[1].x; ImageCordeners[1].y=corners[1].y; ////Move the Bottom-Right Corner: ImageCordeners[2].x=corners[2].x; ImageCordeners[2].y=corners[2].y; PlgBlt(HDCWindow,ImageCordeners,HDCOrigin,PosX,PosY,Width,Height,NULL,0,0); } //Draw image pixel a pixel: void DrawImagePoint(HDC HDCDestination,HDC HDCOrigin, point TopLeft,point TopRight,point BottomLeft,point BottomRight) { //Getting the Points of a line: vector<point> LeftLine; LeftLine = GetPointsLine(TopLeft,BottomLeft); vector<point> RgihtLine; RgihtLine = GetPointsLine(TopRight,BottomRight); for(int PosX=0; PosX<LeftLine.size(); PosX++) { vector<point> PixelLine; PixelLine=GetPointsLine(LeftLine[PosX], RgihtLine[PosX]); for (int PosY=0; PosY<PixelLine.size(); PosY++) { point Point=PixelLine[PosY]; COLORREF color; color=::GetPixel(HDCOrigin,PosY+800,PosX); ::SetPixel( HDCDestination,PosY,PosX,color); } } } int main() { //getting the HDC Console Window: HDC WindowHDC=GetDC(GetConsoleWindow()); point TopLeft={100, 200,0}; point TopRight={200,200,0}; point BottomLeft={100,300,0}; point BottomRight={200,300,0}; point RotationPoint={250,150,0};//center of rectangle angle angles; image img("c:\\test.jpg"); img.DrawImage(WindowHDC,800,0); RECT a; a.left=0; a.right=800; a.top=0; a.bottom=800; do { //angles.x+=0.1; //TopLeft: point TopLeftRotated=TopLeft;//RotationPoints(TopLeft,{angles.x,angles.y,angles.z},RotationPoint); //TopRight: point TopRightRotated=TopRight;//RotationPoints(TopRight,{angles.x,angles.y,angles.z},RotationPoint); //BottomLeft: point BottomLeftRotated=BottomLeft;//RotationPoints(BottomLeft,{angles.x,angles.y,angles.z},RotationPoint); //BottomRight: point BottomRightRotated=BottomRight;//RotationPoints(BottomRight,{angles.x,angles.y,angles.z},RotationPoint); DrawImagePoint(WindowHDC,WindowHDC,TopLeftRotated,TopRightRotated,BottomLeftRotated, BottomRightRotated); Sleep(100); FillRect(WindowHDC,&a, CreateSolidBrush(RGB(0,0,0))); }while(!(GetKeyState(VK_ESCAPE) & 0x8000));//press escape for exit cout<<"Press return to end . . ."<<endl; cin.get(); } image.h: #include <iostream> #include <string> #include <string.h> #include <windows.h> #include <math.h> #include <vector> #include <gdiplus.h> #include <stdlib.h> #include <algorithm> #include<thread> /*void foo(param) { // Do something } // The parameters to the function are put after the comma std::thread thread_obj(foo, params);*/ using namespace Gdiplus; using namespace std; const double PI = 3.14159265358979; struct point { float x,y,z; } ; struct angle { float x,y,z; } ; //Convert the std::string to std::wstring: std::wstring towstring(const std::string& v) { std::wstring out(v.size()+1,L'\0'); int size = MultiByteToWideChar(CP_UTF8, 0, v.c_str(), -1, &out[0], out.size()); out.resize(size-1); return out; } class line { public: point OriginLine; point DestinationLine; line(point origin,point destination) { OriginLine=origin; DestinationLine=destination; } float GetLineLength(point p1,point p2) { return sqrt( (p1.x-p2.x)* (p1.x-p2.x) + (p1.y-p2.y)* (p1.y-p2.y) + (p1.z-p2.z)* (p1.z-p2.z)); } //Get Points Line: point lineto(point fp,point p,float length) { point res; float L=GetLineLength(fp,p); res.x=fp.x+length*(p.x-fp.x)/L; res.y=fp.y+length*(p.y-fp.y)/L; res.z=fp.z+length*(p.z-fp.z)/L; return res; } point perspective(const point &p,const point &eyepoint={250,150,300}) { float w=1+(p.z/eyepoint.z); return {(p.x-eyepoint.x)/w+eyepoint.x, (p.y-eyepoint.y)/w+eyepoint.y, (p.z-eyepoint.z)/w+eyepoint.z}; } vector<point> GetPointsLine() { point t=OriginLine; vector<point> coordenates; float dst=GetLineLength(OriginLine,DestinationLine); for (int i=0;i<=dst;i++) { t=lineto(t,DestinationLine,1); t=perspective(t); coordenates.push_back(t); } return coordenates; } }; POINT Convert3DTo2D(point Dot, int FocalDistance=100) { POINT ptDot; ptDot.x=Dot.x/Dot.z * FocalDistance; ptDot.y=Dot.y/Dot.z * FocalDistance; } class image { public: ULONG_PTR m_gdiplusToken=NULL; Gdiplus::GdiplusStartupInput gdiplusStartupInput; Graphics *graphic=nullptr; Gdiplus::Bitmap *img; HDC ImageHDC=NULL; int Width=0; int Height=0; void GetHDC(HDC &imgHDC) { imgHDC=graphic->GetHDC(); } void ReleaseHDC(HDC &imgHDC) { graphic->ReleaseHDC(imgHDC); } COLORREF GetPixel(int PosX, int PosY) { Color clr; img->GetPixel(PosX, PosY, &clr); return clr.ToCOLORREF(); } void SetPixel(int PosX, int PosY, COLORREF color) { Color *clr; clr->SetFromCOLORREF(color); img->SetPixel(PosX, PosY,clr); } image() { //nothing: } image(int SizeWidth, int SizeHeight) { New(SizeWidth, SizeHeight); } image(string strFile) { FromFile(strFile); } void Clear(Color BackColor=Color::White) { SolidBrush *Fill=new SolidBrush(BackColor); graphic->FillRectangle(Fill,0,0,Width,Height); } void New(int Width, int Height,Color BackColor=Color::White) { Dispose(); Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); img=new Gdiplus::Bitmap(Width, Height); graphic=new Gdiplus::Graphics(img); SolidBrush *Fill=new SolidBrush(BackColor); graphic->FillRectangle(Fill,0,0,Width,Height); delete Fill; } void Dispose() { //clear all objects for avoid memory leaks: if(m_gdiplusToken) { Gdiplus::GdiplusShutdown(m_gdiplusToken); } //by some reason, i can't delete the 'new' values: 'img' and 'graphic' //the program terminates with an exit error } ~image() { Dispose(); } void FromFile(string strFile) { Dispose(); Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); img =new Bitmap(towstring(strFile).c_str()); Width=img->GetWidth(); Height=img->GetHeight(); graphic= Graphics::FromImage(this->img); } void DrawImage(HDC DestinationHDC, float PosX, float PosY) { if(!img || !m_gdiplusToken) return; Gdiplus::Graphics graphics2(DestinationHDC); graphics2.DrawImage(img , PosX, PosY, img->GetWidth(), img->GetHeight()); } void DrawImage(Graphics *Destination, float PosX, float PosY) { if(!img || !m_gdiplusToken) return; Destination->DrawImage(img, PosX, PosY, img->GetWidth(), img->GetHeight()); } //Draw image pixel a pixel: void DrawImagePoint(HDC hdcDestination,point TopLeft,point TopRight,point BottomLeft,point BottomRight, angle angles={0,0,0}) { //Getting the Points of a line: vector<point> LeftLine; //TopLeft = RotationPoints(TopLeft,angles); //TopRight = RotationPoints(TopRight,angles); //BottomLeft = RotationPoints(BottomLeft,angles); //BottomRight = RotationPoints(BottomRight,angles); line LineLeft(TopLeft,BottomLeft); LeftLine = LineLeft.GetPointsLine(); vector<point> RgihtLine; line LineRight(TopRight,BottomRight); RgihtLine=LineRight.GetPointsLine(); for(int PosX=0; PosX<LeftLine.size(); PosX++) { vector<point> PixelLine; line LinePixel(LeftLine[PosX], RgihtLine[PosX]); PixelLine=LinePixel.GetPointsLine(); for (int PosY=0; PosY<PixelLine.size(); PosY++) { point Point=PixelLine[PosY]; Color color; img->GetPixel(PosY+800,PosX,&color); COLORREF clr =color.ToCOLORREF(); ::SetPixel(hdcDestination,PosY,PosX,clr); } } } }; este codigo faz o que preciso: desenha 1 imagem pixel a pixel... mas preciso de velocidade... então queria ver como posso ganhar mais velocidade... nem 1 frame por segundo consigo e é só 1 imagem... imagine várias
-
Otimizar, penso, é evitar duplicar o código e tentar evitar muito consumo do CPU. Mas quais são os passos gerais para Otimizar uma função? Eu fiz uma função mas usa muito CPU, está lento.... gostava de entender como aumentar a velocidade da função
-
Windows 10: porque não posso pesquisar o programa?
Cambalinho respondeu ao tópico de Cambalinho em Windows 10
como se faz o reset ao menu iniciar ou á Lupa? -
Windows 10: porque não posso pesquisar o programa?
Cambalinho respondeu ao tópico de Cambalinho em Windows 10
eu posso escrever aqui normal -
Windows 10: porque não posso pesquisar o programa?
Cambalinho respondeu ao tópico de Cambalinho em Windows 10
várias vezes ja desliguei o portatil e nada... eu não devo ter nada para alterar o menu -
ao clicar na Lupa(na Barra de Ferramentas), ou no Menu Iniciar, eu tento escrever para encontrar o programa... mas o teclado é ignorado na pesquisa... como posso resolver esse problema? (a imagem é para mostrar o meu problema)
-
ACER Aspire 1690: como saber a lista de processadores compativies?
Cambalinho respondeu ao tópico de Cambalinho em Notebooks
muito obrigado por tudo -
ACER Aspire 1690: como saber a lista de processadores compativies?
Cambalinho respondeu ao tópico de Cambalinho em Notebooks
muito obrigado por tudo como você pesquisou só com o chipset? -
ACER Aspire 1690: como saber a lista de processadores compativies?
Cambalinho respondeu ao tópico de Cambalinho em Notebooks
i915pm/gm rev. 03 -
ACER Aspire 1690: como saber a lista de processadores compativies?
Cambalinho respondeu ao tópico de Cambalinho em Notebooks
-
ACER Aspire 1690: como saber a lista de processadores compativies?
Cambalinho respondeu ao tópico de Cambalinho em Notebooks
acer crane intel, BIOS acer 3c11... cpu socket 479 mpga que mais precisa? -
ACER Aspire 1690: como saber a lista de processadores compativies?
Cambalinho postou um tópico em Notebooks
apenas sei que o portatil é ACER Aspire 1690.. gostava de actualizar o processador, mas não sei a lista dos CPUs compativeis.. alguém me pode ajudar? -
Windows 9X\XP: alguém conhece o VDMSound?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
volto a perguntar: sendo o VDMSound ou SoundFX, quais são os pre-requisitos de CPU\memoria? -
Windows 9X\XP: alguém conhece o VDMSound?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
ja desinstalei e reiniciei e re-instalei o soundFX, mas noto os mesmos problemas se configurar o som fx, no setup, no DOOM, para speaker, eu não terei problemas... mas é mais erritante -
Windows 9X\XP: alguém conhece o VDMSound?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
i tested and i get the same problems -
Windows 9X\XP: alguém conhece o VDMSound?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
mais logo vou testar... muito obrigado. é melhor desinstalar o VDMSound antes de de testar? -
Windows 9X\XP: alguém conhece o VDMSound?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
Existe outro além do VDMSound? Só queria o som, porque de resto está impecável -
Windows 9X\XP: alguém conhece o VDMSound?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
Doom e Doom 2. Não sei se o delay é do CPU, mas não encontrei os requisitos necessários para usar esse emulador Pode me ajudar um pouco sobre isso? Sem falar do Doom, o Quake, Heretic e outros podem ter o mesmo problema, por isso preciso de saber se é melhor trocar o CPU do meu ACER Aspire 1690 -
alguém conhece o VDMSound? é 1 emulador que emula o Sound Blaster. e funciona... mas quando jogo o DOOM, os sons dos efeitos(como o tiro), o jogo fica mais lento enquanto executar esse som(penso que é SFX).... alguém me pode ajudar a evitar esse delay? ja fiz pesquisas e não consegui ver os requisitos minimos.
-
windows 98: porque o MS-DOS só detecta, mais ou menos, 555KB's of ram?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
existe algum patch para dar a volta a isso? -
windows 98: porque o MS-DOS só detecta, mais ou menos, 555KB's of ram?
Cambalinho respondeu ao tópico de Cambalinho em Versões até Windows 8
existe alguma forma de aumentar essa limitação? alguma aplicação para isso?
Sobre o Clube do Hardware
No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais
Direitos autorais
Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais