Click and drag

Started by
0 comments, last by Nit 18 years, 1 month ago
I'm trying to make something to click and drag an object. I'm using glRasterPos2f(MousePosX, MousePosY) to draw the object at mouse position. The problem is that glRasterPosition() works only for glBitmap() or glDrawPixel(). How can I make something like that to work with any type of object (a primitive, or a gluCylinder...) Can somebody give me an example or a sugestion??? Thanks. Renato - Eng.Elétrica-UFV
Advertisement
If you are talking about click and drag in ortho, then you just take the change in x and y values from each frame, and use glTranslatef(deltaX,deltaY,0). If you are trying to click and drag something in 3d, then you are going to have to call gluUnproject(...) to unproject the mouse's window coordinates into your world's 3d coordinates every frame you are dragging. (Search google or these forums for more on how to use gluUnproject to get window coordinates into your world coordinates.) One you are successfully picking in your scene, you can just get the change in x, y, and z each frame, and translate your object using glTranslatef(deltaX,deltaY,deltaZ).

This topic is closed to new replies.

Advertisement