Neo  0.5.0
Developer Documentation
Quaternion.h
Go to the documentation of this file.
1 //========================================================================
2 // Copyright (c) 2003-2011 Anael Seghezzi <www.maratis3d.com>
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would
15 // be appreciated but is not required.
16 //
17 // 2. Altered source versions must be plainly marked as such, and must not
18 // be misrepresented as being the original software.
19 //
20 // 3. This notice may not be removed or altered from any source
21 // distribution.
22 //
23 //========================================================================
24 
25 
26 #ifndef __QUATERNION_H
27 #define __QUATERNION_H
28 
29 namespace Neo
30 {
31 class NEO_CORE_EXPORT Quaternion
32 {
33 public:
34 
35  float values[4];
36 
37 public:
38 
39  Quaternion(void)
40  {
41  loadIdentity();
42  }
43 
44  Quaternion(float val0, float val1, float val2, float val3)
45  {
46  values[0] = val0;
47  values[1] = val1;
48  values[2] = val2;
49  values[3] = val3;
50  }
51 
52  Quaternion(float angle, const Vector3 & axis)
53  {
54  setFromAngleAxis(angle, axis);
55  }
56 
57  Quaternion(float xAngle, float yAngle, float zAngle)
58  {
59  setFromAngles(xAngle, yAngle, zAngle);
60  }
61 
62  Quaternion(const Quaternion & q1, Quaternion q2, float interpolation)
63  {
64  slerp(q1, q2, interpolation);
65  }
66 
67 public:
68 
69  Quaternion operator * (const Quaternion & quat) const;
70 
71  void operator *= (const Quaternion & quat);
72 
73  Quaternion operator - (void) const
74  {
75  return Quaternion(-values[0], -values[1], -values[2], -values[3]);
76  }
77 
78  inline bool operator == (const Quaternion & quat) const
79  {
80  if(values[0] == quat.values[0] &&
81  values[1] == quat.values[1] &&
82  values[2] == quat.values[2] &&
83  values[3] == quat.values[3])
84  return true;
85 
86  return false;
87  }
88 
89  inline bool operator != (const Quaternion & quat) const
90  {
91  return !((*this) == quat);
92  }
93 
94 public:
95 
96  void normalize(void);
97  void loadIdentity(void);
98  void setFromAngles(float xAngle, float yAngle, float zAngle);
99  void slerp(const Quaternion & q1, const Quaternion & q2, float interpolation);
100  void invert(void);
101  void setFromAngleAxis(float angle, const Vector3 & axis);
102  void setFromVectors(const Vector3 & source, const Vector3 & destination);
103 
104  Vector3 getEulerAngles(void) const;
105 
106  float getAngle(void) const;
107  Vector3 getAxis(void) const;
108 };
109 }
110 #endif
Quaternion(float val0, float val1, float val2, float val3)
Definition: Quaternion.h:44
Quaternion(void)
Definition: Quaternion.h:39
Definition: Vector3.h:31
Quaternion(float xAngle, float yAngle, float zAngle)
Definition: Quaternion.h:57
float values[4]
Definition: Quaternion.h:35
Quaternion(float angle, const Vector3 &axis)
Definition: Quaternion.h:52
Quaternion(const Quaternion &q1, Quaternion q2, float interpolation)
Definition: Quaternion.h:62
Definition: Color.h:29
Definition: Quaternion.h:31