Sign in to follow this  

What technique should be used? (moving 3d object in 2d space)

Recommended Posts

Hey guys, I am using glunproject for picking and have a selected item (a 3d chess piece). I am now trying to make this model move with the mouse (kind of like its bound to the mouse). any suggestions on how to go about doing this? I was looking into ortho2d but wasn't sure if that was even what i wanted to use. When we were doing 2d stuff I had to convert mouse coordinates to screen space but how do i go about doing this in conjunction with the projection? right now my display looks like this:
void display() {
    glClearColor(0.3f, 0.3f, 0.3f, 0.0f);				
    gluPerspective(45.0f, (GLfloat) 6.4/4.8, 0.1f, 100.0f);
    glViewport (0,0,640,480);			
    glRotated(rotation,0.0,1.0,0.0);  //rotating camera



Share this post

Link to post
Share on other sites
A really simple way would be to calculate the plane of the board, then just move along this plane. So instead of converting mouse coord to world coord, just move the object by how much the mouse had moved.

Share this post

Link to post
Share on other sites
Depends on what you want to do. Move the object on a 3D chessboard?

You could use gluUnproject() to transform the mouse coordinates to world space.
Do this twice - once with z = near plane, once with z = far plane. Then intersect the chessboard with the ray formed by those 2 points and move the object to the intersection point.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
In a previous related thread I suggested that you use Math to do the mouse picking by projecting a ray from the mouse cursor and intersect it with the plane of the board.

Assuming you did your picking with that method (and not using glpicking) then moving the piece is Easy.
Just keep preforming the same intersection test as the cursor moves, and redraw the chess piece at the board intersection point as it changes.

(this is what we meant in the other thread about how the ray intersection method was best because you would Need it Anyway later on.)

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