Bonjour,
je sais convertir un coordonnée 3d en 2d screen selon la matrice.

L'inverse (2d -> 3d) ça marche mais j'ai un z immense (env 50) sachant que la caméra est de haut 10.

Comment faire :

Code qui marche pas bien.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
case WM_MOUSEMOVE:
		{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
 
			RECT rc;
			GetClientRect(hWnd,&rc);
			double x=0,y=0;
			//x=(xPos/1.0/rc.right)-1;
			//y=-1+(yPos/1.0/rc.bottom);
 
			 x = 2.0f * (float)xPos / (float)rc.right - 1.0f;
			 y = 1.0f - 2.0f * (float)yPos / rc.bottom;
 
			double hb=0;
			glm::vec3 vc(x,y,0);
 
			glm::mat4 minv=glm::inverse(shareProject*shareView);
 
			glm::vec4 ret=minv*glm::vec4(vc,1.0f);
 
 
			double rx=ret.x;
			double ry=ret.y;
			double rz=ret.z;
			char tmp[100];
			sprintf(tmp,"Screen : %d,%d %.2f,%.2f",xPos,yPos,x,y);
			SetWindowTextA(hStaticScreen,tmp);
			sprintf(tmp,"OpenGL: x:%.2f y:%.2f z:%.2f",rx,ry,rz);
			SetWindowTextA(hStaticXYZ,tmp);
Code inverse qui semble marcher ,conversion du point (-1,-1,0) -> 2d

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
double cx=-1,cy=-1; cz=0;
				glm::vec3 vc(cx,cy,cz);
 
				glm::vec4 vcu=(shareProject*shareView)*glm::vec4(vc,1.0f);
 
				vcu.x=vcu.x/vcu.z;
				vcu.y=vcu.y/vcu.z;
				int winx=((vcu.x+1)/2.0)*rc.right;
				int winy=((1-vcu.y)/2.0)*rc.bottom;
 
				sprintf(tmp,"Debug: x:%d, y:%d",winx,winy);
				SetWindowTextA(hStaticDebug,tmp);