How to throw object in the direction of camera? #281
-
@daniel Chappuis, Hello I hate to bother you but can you point me in the right direction with this question? If lets say my camera is pointed in a direction that I moved with my mouse, and I want to throw an object with a left click in that same direction, I cant seem to make it throw in that direction. Currently, if I leave it at default the object does throw in that direction with this:
Would I need to apply my sin and cos rotation to the updated position or would I need to update my quaternion somehow and not use identity? I apologize in advance for a trivial question but I haven't slept in days and reactphysics3d has been my obsession! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I always do this but I think I've managed to find a solution although I'm not sure if it's the correct way. There were 2 steps to this:
|
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, you are looking for the direction of your camera in world-space. Since you view matrix V transforms points from world-space to camera space. Therefore, the inverse view matrix Also note that the view matrix I hope this helps. |
Beta Was this translation helpful? Give feedback.
If I understand correctly, you are looking for the direction of your camera in world-space. Since you view matrix V transforms points from world-space to camera space. Therefore, the inverse view matrix$V^{-1}$ will transform a point from camera-space to world-space. This means that if you want to have the direction $d_w$ of the camera in world-space, you need to multiply the direction $d_c$ of the camera in camera-space (for instance the negative z-axis if the camera is looking in this direction) by the inverse of the view matrix $V^{-1}$ to get the camera direction in world-space.
Also note that the view matrix$V$ is a rotation matrix and therefore the inverse o…