Pages: [1]
  Print  
Author Topic: What does the method "AngleVectors" actually do?  (Read 592 times)
Tungsten
Nub


Cakes 0
Posts: 6


« on: March 14, 2018, 04:35:37 pm »

Hey there, new to the game, to the forums, to the code base, fascinated and enamored by all three, and writing a paper about vectors in OA and Q3A. This might be in the wrong section (engine, maybe?)

So I see this method in q_math.c called "AngleVectors" and it appears in methods such as "AAS_WeaponJumpZVelocity." Could someone explain to me when you would use it, what it does, and what (if anything) it returns? I've been coding Python for 5 years, C# for 4, and Java for 3, but I've never dabbled in C even a little bit, so I'm pretty unfamiliar with how it works (Method-oriented, right?).

I get the basic gist of it, but I'm really not sure what the second half of the function does.

Here it is, for convenience sake:

void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) {
   float      angle;
   static float      sr, sp, sy, cr, cp, cy;
   // static to help MS compiler fp bugs

   angle = angles[YAW] * (M_PI*2 / 360);
   sy = sin(angle);
   cy = cos(angle);
   angle = angles[PITCH] * (M_PI*2 / 360);
   sp = sin(angle);
   cp = cos(angle);
   angle = angles[ROLL] * (M_PI*2 / 360);
   sr = sin(angle);
   cr = cos(angle);

   if (forward)
   {
      forward[0] = cp*cy;
      forward[1] = cp*sy;
      forward[2] = -sp;
   }
   if (right)
   {
      right[0] = (-1*sr*sp*cy+-1*cr*-sy);
      right[1] = (-1*sr*sp*sy+-1*cr*cy);
      right[2] = -1*sr*cp;
   }
   if (up)
   {
      up[0] = (cr*sp*cy+-sr*-sy);
      up[1] = (cr*sp*sy+-sr*cy);
      up[2] = cr*cp;
   }
}

Thanks!
« Last Edit: March 14, 2018, 04:47:26 pm by Tungsten » Logged

I like the 'puters.
Tungsten
Nub


Cakes 0
Posts: 6


« Reply #1 on: March 15, 2018, 03:35:45 pm »

I think I figured it out. It takes the vectors, and changes their angles based on an input vector with an angle. The `if` statements check if the supplied fields (forward, right, and up, respectively) are not null, and if they aren't, the code runs.
Logged

I like the 'puters.
Pages: [1]
  Print  
 
Jump to: