Jump to content
  • Advertisement
Sign in to follow this  
Knight Chat X

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.

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!