Jump to content
  • Advertisement
Sign in to follow this  
chillypacman

Getting an angle from look at vectors (and other stuff)

This topic is 4071 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

I'm looking for a generel purpouse math library that takes care of most basic maths such as a function that takes in a look at vector (such as D3DXVECTOR3(0.2, 1, 0.5)) and returns an angle of the direction. I'm working with DirectX (if thats relevent)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Rattenhirn
What angle would you like to get from a vector?


basic trigonometry stuff, like:

vector of (0, 1, 0.2) -> get angle between the y and z so...

/|
/ | 0.1
<---
0.2

or something like that.

Share this post


Link to post
Share on other sites
Ok, basic trigonomy is covered by the c standard library.

Just include math.h.

To get the angle between y and z use:
double angle = atan2(y, z);

or if you don't need double precision:
float angle = atan2f(y, z);

Depending on which compiler you use, you may have to put "std::" before "atan2" or write "using namespace std;" somewhere in the file.

Hope that helps!

Share this post


Link to post
Share on other sites
Quote:
Original post by Rattenhirn
Ok, basic trigonomy is covered by the c standard library.

Just include math.h.

To get the angle between y and z use:
double angle = atan2(y, z);

or if you don't need double precision:
float angle = atan2f(y, z);

Depending on which compiler you use, you may have to put "std::" before "atan2" or write "using namespace std;" somewhere in the file.

Hope that helps!


yep that helped heaps.

Thank you :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!