/* http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/lookat.html http://msdn.microsoft.com/en-us/library/bb205343.aspx */ void RMtx4LookAtRH( RMtx4* out, const RVec3* eye, const RVec3* at, const RVec3* up ) { #define AX(i) RVec3GetElement( &axis_x, i ) #define AY(i) RVec3GetElement( &axis_y, i ) #define AZ(i) RVec3GetElement( &axis_z, i ) RVec3 axis_x, axis_y, axis_z; RMtx4Identity( out ); RVec3Sub( &axis_z, eye, at ); RVec3Normalize( &axis_z, &axis_z ); RVec3Cross( &axis_x, up, &axis_z ); RVec3Normalize( &axis_x, &axis_x ); RVec3Cross( &axis_y, &axis_z, &axis_x ); SET_ELEMENT( out, 0, 0, AX(0) ); SET_ELEMENT( out, 0, 1, AX(1) ); SET_ELEMENT( out, 0, 2, AX(2) ); SET_ELEMENT( out, 0, 3, -RVec3Dot(&axis_x, eye) ); SET_ELEMENT( out, 1, 0, AY(0) ); SET_ELEMENT( out, 1, 1, AY(1) ); SET_ELEMENT( out, 1, 2, AY(2) ); SET_ELEMENT( out, 1, 3, -RVec3Dot(&axis_y, eye) ); SET_ELEMENT( out, 2, 0, AZ(0) ); SET_ELEMENT( out, 2, 1, AZ(1) ); SET_ELEMENT( out, 2, 2, AZ(2) ); SET_ELEMENT( out, 2, 3, -RVec3Dot(&axis_z, eye) ); #undef AX #undef AY #undef AZ }
void RQuatToAxisAngle( const RQuat* in, struct RVec3* axis, rmReal* radian ) { if ( axis ) { RVec3 a; RVec3SetElements( &a, in->x, in->y, in->z ); RVec3Normalize( axis, &a ); } if ( radian ) { *radian = 2.0f * rmAcos( in->w ); } }