1 //------------------------------------------------------------------------------
3 //------------------------------------------------------------------------------
4 // GLVU : Copyright 1997 - 2002
5 // The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its
8 // documentation for any purpose is hereby granted without fee, provided that
9 // the above copyright notice appear in all copies and that both that copyright
10 // notice and this permission notice appear in supporting documentation.
11 // Binaries may be compiled with this software without any royalties or
14 // The University of North Carolina at Chapel Hill makes no representations
15 // about the suitability of this software for any purpose. It is provided
16 // "as is" without express or implied warranty.
18 //----------------------------------------------------------------------------
20 // Quaternion coverage (and maybe functionality) test.
21 // The main objective is to just make sure every API gets called
22 // to flush out lurking template bugs that might not otherwise get tickled.
23 // A few checks to make sure things are functioning properly are also
26 // For the API coverage, if the thing simply compiles then it was a success.
27 //----------------------------------------------------------------------------
34 float x = 0.5f, y = 1.1f, z = -0.1f, s = 0.2f;
37 Quatf q2 = Quatf(x, y, z, s);
39 Quatf q4(Vec3f(1,2,3));
40 Quatf q5(Vec3f(2,3,4), 2.0);
41 Quatf q6(1.0, Vec3f(-1,-2,-3));
42 float floatarray[4] = { 1, 2, 3, 4 };
49 q3.Set(Vec3f(1.0,1.0,1.0));
50 q3.Set(Vec3f(1.0,1.0,1.0),-0.5);
53 // Quat &operator = ( const Quat &v ); /* assignment of a Quat */
55 // Quat &operator += ( const Quat &v ); /* incrementation by a Quat */
57 // Quat &operator -= ( const Quat &v ); /* decrementation by a Quat */
59 // Quat &operator *= ( const Type d ); /* multiplication by a scalar */
61 // Quat &operator *= ( const Quat &v ); /* quat product (this*v) */
63 // Quat &operator /= ( const Type d ); /* division by a scalar */
65 // Type &operator [] ( int i); /* indexing x=0, s=3 */
71 // TEST SPECIAL FUNCTIONS
73 // Type Length(void) const; /* length of a Quat */
74 float l = q4.Length();
75 // Type LengthSqr(void) const; /* squared length of a Quat */
77 // Type LengthSqr(void) const; /* squared length of a Quat */
79 // Quat &Normalize(void); /* normalize a Quat */
80 Quatf q9 = q4.Normalize();
81 // Quat &Invert(void); /* q = q^-1 */
83 // Quat &Conjugate(void); /* q = q* */
85 // qvec Xform( const qvec &v ); /* q*v*q-1 */
86 Vec3f v1 = q4.Xform(Vec3f(1.0,1.0,1.0));
87 // Quat &Log(void); /* log(q) */
89 // Quat &Exp(void); /* exp(q) */
91 // qvec GetAxis( void ) const; /* Get rot axis */
93 // Type GetAngle( void ) const; /* Get rot angle (radians) */
94 float a = q5.GetAngle();
95 // void SetAngle( Type rad_ang ); /* set rot angle (radians) */
97 // void ScaleAngle( Type f ); /* scale rot angle */
99 // void Print( ) const; /* print Quat */
102 /* TEST CONVERSIONS */
105 //Mat44& ToMat( Mat44 &dest ) const;
106 //Mat33& ToMat( Mat33 &dest ) const;
107 // Quat& FromMat( const Mat44<Type>& src ) const;
108 // Quat& FromMat( const Mat33<Type>& src ) const;
112 q5 = q3.FromMat(m44);
113 q5 = q3.FromMat(m33);
114 //void ToAngleAxis( Type &ang, qvec &ax ) const;
115 q3.ToAngleAxis( a, v1 );
116 //Quat& FromAngleAxis( Type ang, const qvec &ax );
117 q4 = q3.FromAngleAxis( a, v1 );
118 //Quat& FromTwoVecs(const qvec &a, const qvec& b);
120 q4 = q3.FromTwoVecs( v2, v1 );
121 //Quat& FromEuler( Type yaw, Type pitch, Type roll);
122 q4 = q3.FromEuler( 2.2f, 1.2f, -0.4f );
123 //void ToEuler(Type &yaw, Type &pitch, Type &roll) const;
124 float p=0.3f,r=-1.57f; y= 0.1f;
129 //friend Quat operator - (const Quat &v); /* -q1 */
131 //friend Quat operator + (const Quat &a, const Quat &b); /* q1 + q2 */
133 //friend Quat operator - (const Quat &a, const Quat &b); /* q1 - q2 */
135 //friend Quat operator * (const Quat &a, const Type d); /* q1 * 3.0 */
137 //friend Quat operator * (const Type d, const Quat &a); /* 3.0 * q1 */
139 //friend Quat operator * (const Quat &a, const Quat &b); /* q1 * q2 */
141 //friend Quat operator / (const Quat &a, const Type d); /* q1 / 3.0 */
143 //friend bool operator == (const Quat &a, const Quat &b); /* q1 == q2 ? */
144 bool eq = (q1 == q2);
145 //friend bool operator != (const Quat &a, const Quat &b); /* q1 != q2 ? */
146 bool neq = (q1 != q2);
149 // static Type DEG2RAD(Type d);
150 // static Type RAD2DEG(Type d);
151 a = Quatf::RAD2DEG(a);
152 a = Quatf::DEG2RAD(a);
158 a = Quatf::ATan2(a, p);
161 // static const Type FUDGE;
162 // static const Quat ZERO;
163 // static const Quat IDENTITY;
166 q4 = Quatf::IDENTITY();
168 q1 = QuatSlerp(q1, q3, q4, 0.5f );
169 q1 = QuatSlerp(q3, q4, 0.5f );
173 Quatf StatQuat(Quatf::IDENTITY());
174 Quatf StatQuat2 = Quatf::IDENTITY();
176 void functional_test()
178 printf("The ZERO quat: ");
179 Quatf::ZERO().Print();
180 printf("The IDENTITY quat: ");
181 Quatf::IDENTITY().Print();
182 printf("Statically constructed copy of IDENTITY quat: ");
184 printf("A different static copy of IDENTITY quat: ");
190 int main(int argc, char *argv[])