-\f
-//////////////////////////////////////////////////////////////////
-// Norman's Optimized matrix rotators! //
-//////////////////////////////////////////////////////////////////
-
-
-// Since these are pure rotation matrices we can save some bookwork
-// by considering them to be 3x3 until the very end -- NHV
-static void MakeVIEW_OFFSET( sgMat4 dst,
- const float angle1, const sgVec3 axis1,
- const float angle2, const sgVec3 axis2,
- const float angle3, const sgVec3 axis3 )
-{
- // make rotmatrix1 from angle and axis
- float s = (float) sin ( angle1 ) ;
- float c = (float) cos ( angle1 ) ;
- float t = SG_ONE - c ;
-
- sgMat3 mat1;
- float tmp = t * axis1[0];
- mat1[0][0] = tmp * axis1[0] + c ;
- mat1[0][1] = tmp * axis1[1] + s * axis1[2] ;
- mat1[0][2] = tmp * axis1[2] - s * axis1[1] ;
-
- tmp = t * axis1[1];
- mat1[1][0] = tmp * axis1[0] - s * axis1[2] ;
- mat1[1][1] = tmp * axis1[1] + c ;
- mat1[1][2] = tmp * axis1[2] + s * axis1[0] ;
-
- tmp = t * axis1[2];
- mat1[2][0] = tmp * axis1[0] + s * axis1[1] ;
- mat1[2][1] = tmp * axis1[1] - s * axis1[0] ;
- mat1[2][2] = tmp * axis1[2] + c ;
-
- // make rotmatrix2 from angle and axis
- s = (float) sin ( angle2 ) ;
- c = (float) cos ( angle2 ) ;
- t = SG_ONE - c ;
-
- sgMat3 mat2;
- tmp = t * axis2[0];
- mat2[0][0] = tmp * axis2[0] + c ;
- mat2[0][1] = tmp * axis2[1] + s * axis2[2] ;
- mat2[0][2] = tmp * axis2[2] - s * axis2[1] ;
-
- tmp = t * axis2[1];
- mat2[1][0] = tmp * axis2[0] - s * axis2[2] ;
- mat2[1][1] = tmp * axis2[1] + c ;
- mat2[1][2] = tmp * axis2[2] + s * axis2[0] ;
-
- tmp = t * axis2[2];
- mat2[2][0] = tmp * axis2[0] + s * axis2[1] ;
- mat2[2][1] = tmp * axis2[1] - s * axis2[0] ;
- mat2[2][2] = tmp * axis2[2] + c ;
-
-
- // make rotmatrix3 from angle and axis (roll)
- s = (float) sin ( angle3 ) ;
- c = (float) cos ( angle3 ) ;
- t = SG_ONE - c ;
-
- sgMat3 mat3;
- tmp = t * axis3[0];
- mat3[0][0] = tmp * axis3[0] + c ;
- mat3[0][1] = tmp * axis3[1] + s * axis3[2] ;
- mat3[0][2] = tmp * axis3[2] - s * axis3[1] ;
-
- tmp = t * axis2[1];
- mat3[1][0] = tmp * axis3[0] - s * axis3[2] ;
- mat3[1][1] = tmp * axis3[1] + c ;
- mat3[1][2] = tmp * axis3[2] + s * axis3[0] ;
-
- tmp = t * axis3[2];
- mat3[2][0] = tmp * axis3[0] + s * axis3[1] ;
- mat3[2][1] = tmp * axis3[1] - s * axis3[0] ;
- mat3[2][2] = tmp * axis3[2] + c ;
-
- sgMat3 matt;
-
- // multiply matrices
- for ( int j = 0 ; j < 3 ; j++ ) {
- matt[0][j] = mat2[0][0] * mat1[0][j] +
- mat2[0][1] * mat1[1][j] +
- mat2[0][2] * mat1[2][j];
-
- matt[1][j] = mat2[1][0] * mat1[0][j] +
- mat2[1][1] * mat1[1][j] +
- mat2[1][2] * mat1[2][j];
-
- matt[2][j] = mat2[2][0] * mat1[0][j] +
- mat2[2][1] * mat1[1][j] +
- mat2[2][2] * mat1[2][j];
- }
-
- // multiply matrices
- for ( int j = 0 ; j < 3 ; j++ ) {
- dst[0][j] = mat3[0][0] * matt[0][j] +
- mat3[0][1] * matt[1][j] +
- mat3[0][2] * matt[2][j];
-
- dst[1][j] = mat3[1][0] * matt[0][j] +
- mat3[1][1] * matt[1][j] +
- mat3[1][2] * matt[2][j];
-
- dst[2][j] = mat3[2][0] * matt[0][j] +
- mat3[2][1] * matt[1][j] +
- mat3[2][2] * matt[2][j];
- }
- // fill in 4x4 matrix elements
- dst[0][3] = SG_ZERO;
- dst[1][3] = SG_ZERO;
- dst[2][3] = SG_ZERO;
- dst[3][0] = SG_ZERO;
- dst[3][1] = SG_ZERO;
- dst[3][2] = SG_ZERO;
- dst[3][3] = SG_ONE;
-}
-