]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/quattest.cpp
Tweak lib name.
[simgear.git] / simgear / scene / sky / clouds3d / quattest.cpp
1 //------------------------------------------------------------------------------
2 // File : quattest.cpp
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 
12 // restrictions. 
13 //
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.
17
18 //----------------------------------------------------------------------------
19 // Quattest.cpp
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 
24 //  included.
25 //
26 //  For the API coverage, if the thing simply compiles then it was a success.
27 //----------------------------------------------------------------------------
28
29
30 #include "quat.hpp"
31
32 void coverage_test()
33 {
34   float x = 0.5f, y = 1.1f, z = -0.1f, s = 0.2f;
35   // TEST CONSTRUCTORS
36   Quatf q1;
37   Quatf q2 = Quatf(x, y, z, s);
38   Quatf q3(x, y, z);
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 };
43   Quatf q7(floatarray);
44   Quatf q8(q7);
45
46   // TEST SETTERS
47   q1.Set(1,2,3);
48   q2.Set(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);
51
52   // TEST OPERATORS
53   // Quat &operator  = ( const Quat &v );      /* assignment of a Quat */
54   q4 = q6;
55   // Quat &operator += ( const Quat &v );      /* incrementation by a Quat */
56   q3 += q2;
57   // Quat &operator -= ( const Quat &v );      /* decrementation by a Quat */
58   q3 -= q2;
59   // Quat &operator *= ( const Type d );       /* multiplication by a scalar */
60   q4 *= 0.5f;
61   // Quat &operator *= ( const Quat &v );      /* quat product (this*v) */
62   q2 *= q1;
63   // Quat &operator /= ( const Type d );       /* division by a scalar */
64   q5 /= 2.0f;
65   // Type &operator [] ( int i);               /* indexing x=0, s=3 */
66   float c0 = q1[0];
67   float c1 = q1[1];
68   float c2 = q1[2];
69   float c3 = q1[3];
70   
71   // TEST SPECIAL FUNCTIONS
72   
73   // Type Length(void) const;                  /* length of a Quat */
74   float l = q4.Length();
75   // Type LengthSqr(void) const;               /* squared length of a Quat */
76   l = q4.LengthSqr();
77   // Type LengthSqr(void) const;               /* squared length of a Quat */
78   l = q4.Norm();
79   // Quat &Normalize(void);                    /* normalize a Quat */
80   Quatf q9 = q4.Normalize();
81   // Quat &Invert(void);                       /* q = q^-1 */
82   q9 = q4.Invert();
83   // Quat &Conjugate(void);                    /* q = q* */
84   q9 = q4.Conjugate();
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) */
88   q9 = q4.Log();
89   // Quat &Exp(void);                          /* exp(q) */
90   q9 = q4.Exp();
91   // qvec GetAxis( void ) const;               /* Get rot axis */
92   v1 = q5.GetAxis();
93   // Type GetAngle( void ) const;              /* Get rot angle (radians) */
94   float a = q5.GetAngle();
95   // void SetAngle( Type rad_ang );            /* set rot angle (radians) */
96   q2.SetAngle(a);
97   // void ScaleAngle( Type f );                /* scale rot angle */
98   q2.ScaleAngle(1.5);
99   // void Print( ) const;                      /* print Quat */
100   q3.Print();
101
102   /* TEST CONVERSIONS */
103   Mat44f m44;
104   Mat33f m33;
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;
109   q3.Normalize();
110   m44 = q3.ToMat(m44);
111   m33 = q3.ToMat(m33);
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); 
119   Vec3f v2(-1,-2,-3);
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;
125   q3.ToEuler( y,p,r );
126
127   /* TEST FRIENDS */
128
129   //friend Quat operator - (const Quat &v);                 /* -q1 */
130   q1 = -q2;
131   //friend Quat operator + (const Quat &a, const Quat &b);  /* q1 + q2 */
132   q1 = q2 + q3;
133   //friend Quat operator - (const Quat &a, const Quat &b);  /* q1 - q2 */
134   q1 = q2 - q3;
135   //friend Quat operator * (const Quat &a, const Type d);   /* q1 * 3.0 */
136   q1 = q2 * 0.2f;
137   //friend Quat operator * (const Type d, const Quat &a);   /* 3.0 * q1 */
138   q1 = 0.2f * q2;
139   //friend Quat operator * (const Quat &a, const Quat &b);  /* q1 * q2 */
140   q1 = q2 * q3;
141   //friend Quat operator / (const Quat &a, const Type d);   /* q1 / 3.0 */
142   q1 = q2 / 1.2f;
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);
147
148   // HELPERS
149   // static Type DEG2RAD(Type d);
150   // static Type RAD2DEG(Type d);
151   a = Quatf::RAD2DEG(a);
152   a = Quatf::DEG2RAD(a);
153   a = Quatf::Sin(a);
154   a = Quatf::Cos(a);
155   a = Quatf::ACos(a);
156   a = Quatf::ASin(a);
157   a = Quatf::ATan(a);
158   a = Quatf::ATan2(a, p);
159
160   // CONSTANTS
161   // static const Type FUDGE;
162   // static const Quat ZERO;
163   // static const Quat IDENTITY;
164   a = Quatf::FUDGE;
165   q3 = Quatf::ZERO();
166   q4 = Quatf::IDENTITY();
167
168   q1 = QuatSlerp(q1, q3, q4, 0.5f );
169   q1 = QuatSlerp(q3, q4, 0.5f );
170   
171 }
172
173 Quatf StatQuat(Quatf::IDENTITY());
174 Quatf StatQuat2 = Quatf::IDENTITY();
175
176 void functional_test()
177 {
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: ");
183   StatQuat.Print();
184   printf("A different static copy of IDENTITY quat: ");
185   StatQuat2.Print();
186
187
188 }
189
190 int main(int argc, char *argv[])
191 {
192   coverage_test();
193   functional_test();
194
195   return (0);
196 }