Jump to content
  • Advertisement
Sign in to follow this  
dawberj3

gluUnProject on an invisible plane

This topic is 4459 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

I have objects floating around my scene. I can select each object using gluUnProject. When I have selected the object they turn blue to indicate I have selected one. I now need to move this object around. But when I move it, the object is being placed onto the floor (EG: 100.0 units below it). If the object was originally 100.0 up the y axis. I only want to be able to change its x and y coordinates. I think I need to intersect the coordinates from gluUnProject with a plane. In this case the plane would be flat but 100.0 units up the y axis. Does anyone explain or know any links of how to do this? Thx

Share this post


Link to post
Share on other sites
Advertisement
That's exactly what you want to do. If you want to translate your object along the x-y plane, then first you must draw a quad on the x-y plane that has the same z value as the object's center. This needs to be done during a mouse move event:



double lastX, lastY;
bool mDown = false;
void OnMoveDown(int X, int Y)
{
lastX = X;
lastY = Y;
mDown = true;
}

void OnMouseMove(int X, int Y)
{

if(mDown)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glBegin(GL_QUADS);
glVertex3f(-10000, 10000, object.z);
glVertex3f(10000, 10000, object.z);
glVertex3f(10000, -10000, object.z);
glVertex3f(-10000, -10000, object.z);
glEnd();

double worldX, worldY, worldZ;
// call glReadPixels to get z-value at current (X,Y) screen location
// call glUnProject using X, Y and z-value to get 3D world coordinates

// now move object based on difference b/w worldX - lastX, worldY - lastY
object.x += worldX - lastX;
object.y += worldY - lastY;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

}

}

void OnMouseUp(int X, int Y)
{
mDown = false;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!