hello ,
i am very new in openGL, i have faced many problems while i was drawing and selecting and moving objects in 3D
first for selection , i faced a problem then it was solved correctly using processHits way (selection mode ) ,then i moved to the camera , and also it was done correctly , then one thing is left ,
moving the selected object , whatever the camera position is …
let’s suppose we have a vertex v, its current position is :
v.x,v.y,v.z
we select the vertex and we want to move it (of course i am not talking about vertex suppose it is a sphere and v is its center )
now we we move the mouse by dy, and dx, (dy =newmouseposition.y -oldmouseposition.y) and (dx =newmouseposition.x -oldmouseposition.x)
i want to move the object on plane XY
so if i did it this way :
v.x=v.x+dx ;
v.y=v.y+dy;
that is not totally okay cuz after moving a camera with some movements may be the x axis will be on vertical and y for horizantal or the become in an opposite way
i moved to raycast way ,but ait didnt work :
glm::vec3 myglwidget::raycast(int mouse_x, int mouse_y)
{
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
winX = (float)mouse_x;
winY = (float)viewport[3] - (float)mouse_y;
glReadPixels( mouse_x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
return glm::vec3(posX, posY, posZ);
}
so what is the solution for this kind of movement ?