Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Drag & Drop

This topic is 5407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Help me plz. I don''t know how resolve this problem: i have to drag and drop a cube. Now i can pick it up and if i hold the left button on i can change it position, but the scene doesn''t update and i don''t see my cube moving. If i reshape the screen the cube appear in the new and correct position. Down here i post my code, with the hope someone can help me (plz do not tell me dude or lamer or something similar,..... i just know it by myself). //Convert screen coordinates to OpenGL coordinates. GLdouble *GetOGLPos(int x, int y) { GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; GLfloat winX, winY, winZ; GLdouble pos[3]; glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glGetIntegerv( GL_VIEWPORT, viewport ); winX = (float)x; winY = (float)viewport[3] - (float)y; glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); gluUnProject(winX, winY, winZ, modelview, projection, viewport, &pos[0],&pos[1], &pos[2]); return pos; } #define BUFSIZE 512 void pickPacket(int button, int state, int x, int y) { GLuint selectBuf[BUFSIZE]; GLint hits; GLint viewport[4]; if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(BUFSIZE, selectBuf); (void) glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); /* create 1x1 pixel picking region near cursor location */ gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 0.01, 0.01, viewport); //glOrtho(-8, 8, -6, 6, -100, 100); glOrtho(-8*zoomfactor-translatefactor,8*zoomfactor-translatefactor, -6*zoomfactor, 6*zoomfactor, -100, 100); drawScene(GL_SELECT); glPopMatrix(); glutSwapBuffers(); reshape(Width, Height); hits = glRenderMode(GL_RENDER); if(hits>1) { Hitten=selectBuf[7]; } processHits(hits, selectBuf); } if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) Hitten=0; } void myMovedMouse(int x, int y) { if(Hitten!=0) { Container *tmp; Packet *tmp_pkt; tmp=Cont; while(tmp->Obj->name!=Hitten) tmp=tmp->next; GLfloat X,Y,Z; X=GetOGLPos(x,y)[0]; Y=GetOGLPos(x,y)[1]; Z=GetOGLPos(x,y)[2]; Modifica_Origine(X, Y, Z, tmp->Obj); //glutPostRedisplay(); } }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!