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

Started by
6 comments, last by MGB 17 years ago
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.
Advertisement
billboarding?
.
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))));

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]
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.
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.
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?
No - KRadToDeg is a constant for radians to degrees conversion (180/Pi to be precise), as atan2 returns a value in radians.

This topic is closed to new replies.

Advertisement