Jump to content
  • Advertisement
Sign in to follow this  
stringa

I suck at trig...

This topic is 3703 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 just trying to find the current angle on a sphere so i can rotate the camera by some amount and then set the new position and target for the camera. I'm getting mixed up in the inverse trig functions... precifically the range of the functions My code is messed up right here and it's taking me a while to figure out what the what is correct
  float angle = atan( proj_onto_x_z.z_ / proj_onto_x_z.x_ );

  // if x is positive we are on the right and all is well
  // if x is negative we are on the left side
  
  if( pos.x_ < 0)
  {
    if(pos.z_ > 0) // we are in quadrant II
    {
      angle =  1.57 + (1.57 - angle);
    }
    else // we are in quadrant III
    {
      angle = 3.14159 + angle;
    }
  }



Any help is appreciated thanks stringa

Share this post


Link to post
Share on other sites
Advertisement
If you want your angle to range from [0, 2pi], just do

std::atan2(y, x) + pi;

atan2 returns an angle between [-pi, +pi], maybe that will help you with your confusion of the range of the atan function?

That way you don't have to worry about divide by zero at all.

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!