Sign in to follow this  
dawberj3

gluUnProject on an invisible plane

Recommended Posts

dawberj3    122
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
soconne    105
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this