Sign in to follow this  
BatVink

Screen coordinates to 3D movement

Recommended Posts

BatVink    122
Hi all, this is my first post here, hopefully of many in the months to come. I can't get my head around this mathemetical problem. Firstly, I have created 2 vectors that allow me to convert mouse X/Y movement into 3D movement of an object. So, no matter which direction the camera faces, the object will always travel across the screen in the same orientation as the screen. In a nutshell... * Take Camera position and angle. * Take a point that is one unit to the right of the camera, using the camera's local axes. * Vector x,y and z is the difference between these 2 points. This represents the Mouse X movement. * Repeat for y movement by taking a point 1 unit below the camera. When I move the mouse 1 unit in the X direction, the 3D movement of the object is the x, y and z components of the X mouse Vector. The same applies for the Y movement, and this works perfectly. ===================================================== So here is the problem. I now want to suppress movement in a given axis of the object. When the object is perfectly oriented (0,0,0), it's easy. I simply don't record any movement in the Y axis, if the Y axis is suppressed. This would, for example, keep the object on a flat surface... Illustration 1 But if the object is at any other angle, I need to somehow calculate how I would prevent any movement in the object's local Y axis, when the camera could be facing any direction. Illustration 2 Any help on how I achieve this last part of the calculation would be appreciated! I believe I need to create a further vector representing the objects orientation, ensuring it represents 0 movement in it's y-plain in this example. But producing the combined result is beating me. Thanks in advance.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
your images are not visible to the rest of us
because we do not have accounts on that forum

I will say though, that by 'limiting an axis' what you probably really mean is: Constraining motion to a Plane (planes are defined by their Normal (the axis))

This is *probably* a case of, taking the mouse cursor position on screen, and using it to project a ray from the camera
then interesecting that ray with the aforementioned plane to find the resulting position...

Share this post


Link to post
Share on other sites
BatVink    122
Sorry about the images, however they just try and back up the detail.

I have had a reply from another forum, suggesting that the way to do this is with a rotation matrix. In this matrix, I can set the local axes to a zero length to suppress them, and then multiply the movement vector by the rotation matrix.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
the rotation matrix math they describe is probably being used to project the mouse from screenspace into the 3d world as a ray coming from the camera

the idea is to use a rotation (more properly termed 'orientation') matrix to represent how the camera is pointed
a mouse cursor coordinate can then be easily placed into the 3d world by multiplying it thorugh that matrix to take account the cam's orientation on top of whatever the mouse motion is...

Share this post


Link to post
Share on other sites
Hexer    133
Assuming you have two vectors that represent the last mouse position and the current mouse position projected from screen space to world space, I'll denote them with V1, and V2.

And let's say you have a delta vector derived from them

D = V2 - V1


this vector represents your movement direction and magnitude in world space right?

in order to restrict it to your object's local axis all you have to do is dot it with the axis normal of the object you are trying to move and then scale that normal by the result of the dot product. This is called projection.

You can then add the resulting vector to your object's position. This will move your object restricted along its local axis.

You can obtain your object's local axes from its world transformation matrix. For row-major matrices, x,y,z axis normals are rows 0, 1, 2 respectively.

Hope this helps, if not let me know and I'll elaborate it further in detail.

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