개체가 점 (이 경우 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 차원으로 좌표 :
먼저 윈도우 좌표로 변환 이것 또는 물체가 올바른 선을 따라 날아갈 수 있도록하기 위해 내가해야 할 일이 무엇인지 알아보십시오.