--- include/matrix4.h 2005-11-27 20:11:00.000000000 +0100 +++ include/matrix4.h 2005-12-20 14:04:36.000000000 +0100 @@ -166,6 +166,21 @@ /** Used to scale <-1,-1><1,1> to viewport, for example from von <-1,-1> <1,1> to the viewport <0,0><0,640> */ void buildNDCToDCMatrix( const core::rect& area, f32 zScale); + //! Builds a rotation matrix around an arbitrary axis + //! If possible, prefer the more efficient buildRotationMatrix functions + //! \param angle: angle to rotate + //! \param axis: axis to rotate around + void buildAxisRotationMatrix(f32 angle, const core::vector3df& axis); + //! Builds a rotation matrix around the X axis + //! \param angle: angle to rotate + void buildRotationXMatrix(f32 angle); + //! Builds a rotation matrix around the Y axis + //! \param angle: angle to rotate + void buildRotationYMatrix(f32 angle); + //! Builds a rotation matrix around the Z axis + //! \param angle: angle to rotate + void buildRotationZMatrix(f32 angle); + //! creates a new matrix as interpolated matrix from to other ones. //! \param b: other matrix to interpolate with //! \param time: Must be a value between 0 and 1. @@ -863,6 +878,32 @@ (*this)(3,3) = 1.0f; } + inline void matrix4::buildAxisRotationMatrix(f32 angle, const core::vector3df& axis) { + f32 x=axis.X, y=axis.Y, z=axis.Z; + f32 l=1.0f/(f32)axis.getLength(); + x*=l; y*=l; z*=l; + f32 si=sin(angle), six=si*x, siy=si*y, siz=si*z, co=cos(angle), ico=1-co; + makeIdentity(); + M[0]=co+ico*x*x; M[1]=ico*x*y+siz; M[2]=ico*z*x-siy; + M[4]=ico*x*y-siz; M[5]=co+ico*y*y; M[6]=ico*y*z+six; + M[8]=ico*x*z+siy; M[9]=ico*y*z-six; M[10]=co+ico*z*z; + } + inline void matrix4::buildRotationXMatrix(f32 angle) { + f32 si=sin(angle), co=cos(angle); + makeIdentity(); + M[5]=co; M[6]=si; M[9]=-si; M[10]=co; + } + inline void matrix4::buildRotationYMatrix(f32 angle) { + f32 si=sin(angle), co=cos(angle); + makeIdentity(); + M[0]=co; M[2]=-si; M[8]=-si; M[10]=co; + } + inline void matrix4::buildRotationZMatrix(f32 angle) { + f32 si=sin(angle), co=cos(angle); + makeIdentity(); + M[0]=co; M[1]=si; M[4]=-si; M[5]=co; + } + //! creates a new matrix as interpolated matrix from to other ones. //! \param time: Must be a value between 0 and 1.