opengl - GlunUnproject moving object with the mouse -
i'm trying move objects mouse using gluunproject method opengl 2.1 , i'm struggling here; here's code wrote :
int viewport[4]; double modelview[16], projection[16], x1, y1, z1; double realy; glfloat depth[2]; for(_compt=_ojebctscene.begin();_compt!=_ojebctscene.end();_compt++) { if ((*_compt)->isselected()) { gldouble mousex=event.x; gldouble mousey=event.y; glgetintegerv(gl_viewport, viewport); glgetdoublev(gl_modelview_matrix, modelview); glgetdoublev(gl_projection_matrix, projection); realy = viewport[3] - (glint) mousey - 1; glreadpixels(mousex, realy, 1, 1, gl_depth_component, gl_float, depth); gluunproject(mousex, realy, 0, modelview, projection, viewport, &x1, &y1, &z1); (*_compt)->setx(x1); (*_compt)->sety(y1); (*_compt)->setz(z1); } }
i use loop check objects on scene (i've pushed them vector) , when find selected object , try move using mouse.
i set coordinates of object position of mouse in 3d space (x1 , y1 , z1); doesn't work.
i think i've fixed passing depth[0] gluunproject method. here's i've done , change :
gluunproject(mousex, realy, 0, modelview, projection, viewport, &x1, &y1, &z1);
by :
gluunproject(mousex, realy,depth[0], modelview, projection, viewport, &x1, &y1, &z1);
i don't understand means though , if explain me nice.
Comments
Post a Comment