Sign in to follow this  
Knight Chat X

How do I make Mesh Rotation Angle same as Camera Rotation Angle?

Recommended Posts

Hello, I'm trying to set a bullet projectile mesh to have the same rotation angle as my first person shooter camera, how do can I get the Heading and Pitch Angles from the camera's Position and View vectors? I'm using OpenGL.

Share this post


Link to post
Share on other sites
What I'd do is use a vector direction for your projectiles (which can be taken directly from your camera matrix - usually the Z axis basis vector).
You can extract a heading and pitch from this vector when you need to draw the projectile using something like:

hdg = -float(KRadToDeg * atan2(dir.x, -dir.z));
pitch = float(KRadToDeg * atan2(dir.y, sqrt((dir.x*dir.x) + (dir.z*dir.z))));


Share this post


Link to post
Share on other sites
Quote:
Original post by xissburg
billboarding?


Yeah that helped, spherical billboarding, at the moment I'm using this for orienting a bullet projectile and sometimes though but not often for some reason it'll fire the projectile completely sideways and not sure why, so I've gotta tweak something out somewhere, but this was a good start, thanks.

[Edited by - Knight Chat X on April 14, 2007 12:15:45 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Aph3x
What I'd do is use a vector direction for your projectiles (which can be taken directly from your camera matrix - usually the Z axis basis vector).
You can extract a heading and pitch from this vector when you need to draw the projectile using something like:
*** Source Snippet Removed ***

You mean the camera's view vector?


hdg = -float(KRadToDeg * atan2(dir.x, -dir.z));
pitch = float(KRadToDeg * atan2(dir.y, sqrt((dir.x*dir.x) + (dir.z*dir.z))));



What is the KRadToDeg value of?

I understand the conversion from Radian to Degree's.

Share this post


Link to post
Share on other sites
Yep, KRadToDeg is for conversion from radians to degrees.

If you're using a matrix for your camera, the 3x3 rotation part defines it's orientation as 3 basis vectors for x y & z. You can take the z axis straight out of the matrix and use it as the projectile direction.

Share this post


Link to post
Share on other sites
Quote:
Original post by Aph3x
Yep, KRadToDeg is for conversion from radians to degrees.

If you're using a matrix for your camera, the 3x3 rotation part defines it's orientation as 3 basis vectors for x y & z. You can take the z axis straight out of the matrix and use it as the projectile direction.


So KRadToDeg is the Matrix Z-Axis value/angle converted from Radian to Degrees?

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