nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef QUATERNION_H 00024 #define QUATERNION_H 00025 00026 #include "Vector3.h" 00027 #include "Vector4.h" 00028 00029 namespace nux 00030 { 00031 00032 /***************************************************************************************\ 00033 Class: Quaternion 00034 00035 Description: Define basic quaternion initialization and function. 00036 00037 Comments: Member functions uses input angles in radian. 00038 \***************************************************************************************/ 00039 class Quaternion 00040 { 00041 public: 00042 Quaternion(); 00043 Quaternion (const Quaternion &s); 00044 Quaternion (const Vector3 &vec, float angle); 00045 Quaternion (const Vector4 &vec); 00046 00047 // creates a Quaternion from an angle axis -- note that if angle > 2*PI the resulting 00048 // rotation is angle mod 2*PI 00049 Quaternion (t_float axis_x, t_float axis_y, t_float axis_z, t_float angle_radian); 00050 // creates a Quaternion from an angle-around-XYZ euler triple using roll-pitch-yaw order 00051 Quaternion (t_float euler_x, t_float euler_y, t_float euler_z); 00052 ~Quaternion(); 00053 00054 Quaternion &operator = (const Quaternion &quat); 00055 00056 // binary operators 00057 Quaternion operator + (const Quaternion &quat) const; 00058 Quaternion operator - (const Quaternion &quat) const; 00059 Quaternion operator * (const Quaternion &quat) const; 00060 Quaternion operator * (const t_float &f) const; 00061 Quaternion operator / (const t_float &f) const; 00062 00063 // assignment operators 00064 Quaternion &operator += (const Quaternion &quat); 00065 Quaternion &operator -= (const Quaternion &quat); 00066 Quaternion &operator *= (const Quaternion &quat); 00067 Quaternion &operator *= (const t_float &f); 00068 Quaternion &operator /= (const t_float &f); 00069 00070 // unary operators 00071 Quaternion operator + () const; 00072 Quaternion operator - () const; 00073 //const Quaternion operator / (const Quaternion& quat); 00074 00075 00076 bool operator == ( const Quaternion & ) const; 00077 bool operator != ( const Quaternion & ) const; 00078 00079 void Conjugate(); 00080 void Inverse(); 00081 void Normalize(); 00082 t_float DotProduct (const Quaternion &quat) const; 00083 t_float Length() const; 00084 00085 void GetAngleAxis (Vector3 &axis, t_float &angle_radian) const; // fetches the angle/axis given by the quat 00086 00087 // Fetches 4x4 homogeneous matrix given by the quat 00088 Matrix4 GetMatrix() const; 00089 00090 t_float x, y, z, w; 00091 00092 friend Quaternion operator * (t_float f, const Quaternion &quat); 00093 private: 00094 // set the quaternion by angle-axis (see AA constructor) 00095 void FromAngleAxis (t_float axis_x, t_float axis_y, t_float axis_z, t_float angle_radian); 00096 00097 // set the quaternion by euler axis angles (see euler constructor) 00098 void FromEulerZXY (t_float euler_x, t_float euler_y, t_float euler_z); 00099 }; 00100 00101 } 00102 00103 #endif // QUATERNION_H