Dragging cube

Started by
1 comment, last by qwertyPrince 8 years, 2 months ago

Hi, i recently managed to move a 3D shape using the cursor location by unprojecting the object position and adding the x and y offsets to it and then project it back into the 3d world, this seemed to work really well, however i devided to move alow the view to be rotated and the object isnt always under the mouse when i try to move it in a rotated orientation. How do i go about doing this?

Advertisement
Sounds like you need to take into account the view matrix when projecting and unprojecting your 3d shape.
My current game project Platform RPG

I used XNA project and unproject. both take the view matrix in as a parameter, what is the purpose of passing the view matrix to the two functions?

Edit:

I finally wrote some project and unproject functions.

On projecting :

-multiply cooridnates by view and projection matrices, then divide the resultant coorinate by the w component

-store the z coordinate

i then convert the mouse movement into projection space and add the offset to the projected coordinates

with the z cordinate being the one stored initially

On unprojecting:

-get the mouse in the projection space

-multiply by the (view * projection)^-1 , and then divide by the w component.

This works however any movement into along the z axis at an angle does not track the mouse, i assume it is due to the fact that i am mapping the movment of the y-screen to the z-coordinate in 3D. i dont see another way though

This topic is closed to new replies.

Advertisement