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

This topic is 4259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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.

billboarding?

##### 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 on other sites
Quote:
 Original post by xissburgbillboarding?

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 on other sites
Quote:
 Original post by Aph3xWhat 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 on other sites

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 on other sites
Quote:
 Original post by Aph3xYep, 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 on other sites
No - KRadToDeg is a constant for radians to degrees conversion (180/Pi to be precise), as atan2 returns a value in radians.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013440
×