Ivan Ermolaev
Ivan Ermolaev

Reputation: 1032

Radian or Degrees?

When I create matrix of rotation from Euler angles, Should I convert a degrees(Euler angles) to radians, and then count matrix of rotation for OpenGL? But what should I do with a quaternions? Should I do following:

void setQuaternionsFromEuler(float bank, float heading, float attitude)
{
   float DegreeToRadian = 3.14f/180.0f;
   double c1 = cos(heading/2*DegreeToRadian);
   double c2 = cos(attitude/2*DegreeToRadian);
   //...
   double s3 = sin(bank/2*DegreeToRadian);

   this.w = c1*c2*c3 - s1*s2*s3;
   //...
}

And,

void setMatrixFromEuler(float x, float y, float z)
{
   float DegreeToRadian = 3.14f/180.0f;
   x *= DegreeToRadian;
   y *= DegreeToRadian;

   //...
}

Or not?

Upvotes: 1

Views: 3901

Answers (2)

Antoine
Antoine

Reputation: 14064

Rotation matricies don't have angles anymore, so it's not really related with OpenGL, but the trigonometric functions you use from the standard library in C or C++ are defined on radians, so if your user-facing API works with degrees, then yes you should convert to take the cos/sin.

Upvotes: 2

ratchet freak
ratchet freak

Reputation: 48196

It depends on how you define your input.

The trig functions of C++ take radian exclusively, so you need to convert to radian eventually but that may be done before the data even enters your program (such that the angle values in the resources are all in radian)

Upvotes: 2

Related Questions