--- src/qcommon/q_math.c 2007-10-06 14:58:52.000000000 -0700 +++ src/qcommon/q_math.c 2007-09-11 03:12:59.000000000 -0700 @@ -289,20 +289,51 @@ This is not implemented very well... =============== */ -void RotatePointAroundVector( vec3_t dst, const vec3_t dir, - const vec3_t point, vec_t degrees ) { - vec_t sind, cosd, expr; - vec3_t dxp; - - degrees = DEG2RAD( degrees ); - sind = sin( degrees ); - cosd = cos( degrees ); - expr = ( 1 - cosd ) * DotProduct( dir, point ); - CrossProduct( dir, point, dxp ); - - dst[0] = expr*dir[0] + cosd*point[0] + sind*dxp[0]; - dst[1] = expr*dir[1] + cosd*point[1] + sind*dxp[1]; - dst[2] = expr*dir[2] + cosd*point[2] + sind*dxp[2]; +void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, + float degrees ) { + float sin_a; + float cos_a; + float cos_ia; + float i_i_ia; + float j_j_ia; + float k_k_ia; + float i_j_ia; + float i_k_ia; + float j_k_ia; + float a_sin; + float b_sin; + float c_sin; + float rot[3][3]; + + cos_ia = DEG2RAD(degrees); + sin_a = sin(cos_ia); + cos_a = cos(cos_ia); + cos_ia = 1.0F - cos_a; + + i_i_ia = dir[0] * dir[0] * cos_ia; + j_j_ia = dir[1] * dir[1] * cos_ia; + k_k_ia = dir[2] * dir[2] * cos_ia; + i_j_ia = dir[0] * dir[1] * cos_ia; + i_k_ia = dir[0] * dir[2] * cos_ia; + j_k_ia = dir[1] * dir[2] * cos_ia; + + a_sin = dir[0] * sin_a; + b_sin = dir[1] * sin_a; + c_sin = dir[2] * sin_a; + + rot[0][0] = i_i_ia + cos_a; + rot[0][1] = i_j_ia - c_sin; + rot[0][2] = i_k_ia + b_sin; + rot[1][0] = i_j_ia + c_sin; + rot[1][1] = j_j_ia + cos_a; + rot[1][2] = j_k_ia - a_sin; + rot[2][0] = i_k_ia - b_sin; + rot[2][1] = j_k_ia + a_sin; + rot[2][2] = k_k_ia + cos_a; + + dst[0] = point[0] * rot[0][0] + point[1] * rot[0][1] + point[2] * rot[0][2]; + dst[1] = point[0] * rot[1][0] + point[1] * rot[1][1] + point[2] * rot[1][2]; + dst[2] = point[0] * rot[2][0] + point[1] * rot[2][1] + point[2] * rot[2][2]; } /* @@ -1259,40 +1290,38 @@ } -void AngleVectors( const vec3_t angles, vec3_t forward, - vec3_t right, vec3_t up ) { - float angle; - static float sp, sy, cp, cy, sr, cr; +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 = DEG2RAD( angles[PITCH] ); - sp = sin( angle ); - cp = cos( angle ); - - angle = DEG2RAD( angles[YAW] ); - sy = sin( angle ); - cy = cos( angle ); + 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 ) { + if (forward) + { forward[0] = cp*cy; forward[1] = cp*sy; forward[2] = -sp; } - if( right || up ) { - angle = DEG2RAD( angles[ROLL] ); - sr = sin( angle ); - cr = cos( angle ); - - 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; - } + 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; } }