2014-08-30 1 views
0

개체가 점 (이 경우 0,0,0)에서 시작되어 OpenGL 응용 프로그램을 작성하려고합니다. 마우스의 x, y 위치 이것은 현재 사용중인 시스템입니다. 점에서 객체 만들기 마우스의 x, y 위치를 가져옵니다. 마우스를 3D 좌표로 변환하십시오. 원위 평면이 4,294,967,295로 설정된 시작점과 (마우스 -X, 마우스 -Y, 먼 평면) 사이의 선을 가져옵니다. 파라 메트릭 선 방정식을 사용하여이 선을 따라 객체를 이동합니다.한 점에서 OpenGL, C++의 x, y에 벡터 만들기

멀리있는 평면의 x, y는 x, y 마우스 위치와 일치하지 않는 것처럼 보이므로 개체가 잘못된 선으로지나갑니다. 나는 라인/파라, 에릭 방정식 부분이 잘 작동한다고 확신하지만, 2 차원과 3 차원 공간 사이의 변환은 그렇지 않을 수도 있습니다. 여기에 내가 시도 것입니다 : 내가 어떤 몸이 유사한 아무것도 할 수있다 궁금

GLint viewport[4]; 
GLdouble modelview[16]; 
GLdouble projection[16]; 
GLfloat winX, winY, winZ; 
GLdouble posX, posY, posZ; 
OBJ_TriCo returnMe; 

//All matrices in use need to be retrived 
glGetDoublev(GL_MODELVIEW_MATRIX, modelview); 
glGetDoublev(GL_PROJECTION_MATRIX, projection); 
glGetIntegerv(GL_VIEWPORT, viewport); 
//Set the co-ords to lookup, based on the mouse position passed to this 
winX = (float)x; 
winY = (float)viewport[3] - (float)y; 
//Set the z to 0.99, for some reason the object will fly totally incorrectly otherwise 
winZ = 0.999; //Get a point on the bettween FAR and NEAR-Clipping planes 
//Convert the co-ords 
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); 
//Return there values 
returnMe.x = posX; 
returnMe.y = posY; 
returnMe.z = posZ; 
return returnMe; 

다음
POINT *mouse = new POINT(); 
mouse->x = mousePosition3D.x; 
mouse->y = mousePosition3D.y; 
ScreenToClient(windowHandle, mouse); 

3 차원으로 좌표 :

먼저 윈도우 좌표로 변환 이것 또는 물체가 올바른 선을 따라 날아갈 수 있도록하기 위해 내가해야 할 일이 무엇인지 알아보십시오.

답변

0

하면 스크린 공간 좌표로부터 월드 스페이스 선 방향을 계산할 수있다 (범위 정규화 [-1, 1])이 같은

vec4f r = projection_to_view_matrix * vec4f(screen_x, screen_y, 0, 1); 
vec3f rdir = transpose(world_to_view_rotation_matrix) * vec3f(r.x, r.y, r.z); 
관련 문제