Skip to content

Commit

Permalink
added func to convert roll/pitch/yaw angles to view vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
fielder committed Jan 30, 2012
1 parent 15e677c commit 2f9bb37
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions vec.c
Expand Up @@ -154,3 +154,38 @@ Vec_BoxPlaneSide (const struct plane_s *plane, float mins[3], float maxs[3])
//TODO: ...
}
}


void
Vec_AnglesVectors ( const float angles[3],
float right[3],
float up[3],
float forward[3])
{
double cr, sr;
double cp, sp;
double cy, sy;

cr = cos (angles[ROLL]);
sr = sin (angles[ROLL]);

cp = cos (angles[PITCH]);
sp = sin (angles[PITCH]);

cy = cos (angles[YAW]);
sy = sin (angles[YAW]);

//TODO: any common sub-expressions in here ?

right[0] = cy * cr;
right[1] = sp * sy * cr - cp * sr;
right[2] = cp * sy * cr + sp * sr;

up[0] = cy * sr;
up[1] = sp * sy * sr + cp * cr;
up[2] = cp * sy * sr - sp * cr;

forward[0] = -sy;
forward[1] = sp * cy;
forward[2] = cp * cy;
}
6 changes: 6 additions & 0 deletions vec.h
Expand Up @@ -71,4 +71,10 @@ Vec_MakeNormal (const float v1[3],
extern int
Vec_BoxPlaneSide (const struct plane_s *plane, float mins[3], float maxs[3]);

extern void
Vec_AnglesVectors ( const float angles[3],
float right[3],
float up[3],
float forward[3]);

#endif /* __VEC_H__ */

0 comments on commit 2f9bb37

Please sign in to comment.