EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Ga::GaQuat Class Reference

#include "GaTypes.h"

Collaboration diagram for Ga::GaQuat:

Public Member Functions

GaExpInl GaQuat ()
 
GaExpInl GaQuat (GaFloat W, const GaVec3 &V)
 
GaExpInl GaQuat (GaFloat W, GaFloat X, GaFloat Y, GaFloat Z)
 
 GaQuat (const GaRadian &a, const GaVec3 &axis)
 
 GaQuat (const GaMat3x3 &rot)
 
GaExpInl GaVec3 operator* (const GaVec3 &vec) const
 
GaExpInl GaQuat operator* (const GaQuat &oth) const
 
GaExpInl GaQuatoperator= (const GaQuat &oth)
 
GaQuatoperator= (const Parameter &oth)
 
 GaQuat (const Parameter &oth)
 
GaQuat inverse () const
 

Public Attributes

GaFloat w
 
GaVec3 v
 

Static Public Attributes

static GaQuat IDENTITY = GaQuat(1,0,0,0)
 
static GaQuat ZERO = GaQuat(0,0,0,0)
 

Detailed Description

Definition at line 218 of file GaTypes.h.

Constructor & Destructor Documentation

GaExpInl Ga::GaQuat::GaQuat ( )
inline

Definition at line 224 of file GaTypes.h.

Referenced by inverse().

224 :w(0),v(0,0,0){}
GaVec3 v
Definition: GaTypes.h:267
GaFloat w
Definition: GaTypes.h:266

Here is the caller graph for this function:

GaExpInl Ga::GaQuat::GaQuat ( GaFloat  W,
const GaVec3 V 
)
inline

Definition at line 225 of file GaTypes.h.

225 :w(W),v(V){}
GaVec3 v
Definition: GaTypes.h:267
GaFloat w
Definition: GaTypes.h:266
GaExpInl Ga::GaQuat::GaQuat ( GaFloat  W,
GaFloat  X,
GaFloat  Y,
GaFloat  Z 
)
inline

Definition at line 226 of file GaTypes.h.

226 :w(W),v(X,Y,Z){}
GaVec3 v
Definition: GaTypes.h:267
GaFloat w
Definition: GaTypes.h:266
GaQuat::GaQuat ( const GaRadian a,
const GaVec3 axis 
)

Definition at line 27 of file GaTypes.cpp.

References Ga::Math::cosine(), Ga::GaRadian::r, Ga::Math::sine(), v, w, Ga::GaVec3::x, Ga::GaVec3::y, and Ga::GaVec3::z.

28 {
29  w = Math::cosine(a.r * 0.5);
30 
31  GaFloat sin_a = Math::sine(a.r * 0.5);
32  v.x = axis.x * sin_a;
33  v.y = axis.y * sin_a;
34  v.z = axis.z * sin_a;
35 
36  v.x *= 57.2957795131; // 180/pi (rad->deg)
37  v.y *= 57.2957795131; // 180/pi (rad->deg)
38  v.z *= 57.2957795131; // 180/pi (rad->deg)
39 
40  if (v.x < 0)
41  v.x += 360;
42  if (v.y < 0)
43  v.y += 360;
44  if (v.z < 0)
45  v.z += 360;
46 }
GaVec3 v
Definition: GaTypes.h:267
GaFloat x
Definition: GaTypes.h:207
GaFloat w
Definition: GaTypes.h:266
static GaFloat sine(const GaFloat &r)
Definition: GaMath.h:44
GaFloat y
Definition: GaTypes.h:207
GaFloat r
Definition: GaTypes.h:460
double GaFloat
Definition: GaPreReqs.h:69
GaFloat z
Definition: GaTypes.h:207
static GaFloat cosine(const GaFloat &r)
Definition: GaMath.h:43

Here is the call graph for this function:

GaQuat::GaQuat ( const GaMat3x3 rot)

Definition at line 298 of file GaTypes.cpp.

References Ga::Math::squareRoot(), v, w, Ga::GaVec3::x, Ga::GaVec3::y, and Ga::GaVec3::z.

299 {
300  // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
301  // article "Quaternion Calculus and Fast Animation".
302 
303  GaFloat fTrace = rot[0][0]+rot[1][1]+rot[2][2];
304  GaFloat fRoot;
305 
306  if ( fTrace > 0.0f )
307  {
308  // |w| > 1/2, may as well choose w > 1/2
309  fRoot = Math::squareRoot(fTrace + 1.0f); // 2w
310  w = 0.5f*fRoot;
311  fRoot = 0.5f/fRoot; // 1/(4w)
312  v.x = (rot[2][1]-rot[1][2])*fRoot;
313  v.y = (rot[0][2]-rot[2][0])*fRoot;
314  v.z = (rot[1][0]-rot[0][1])*fRoot;
315  }
316  else
317  {
318  // |w| <= 1/2
319  static GaUint s_iNext[3] = { 1, 2, 0 };
320  GaUint i = 0;
321  if ( rot[1][1] > rot[0][0] )
322  i = 1;
323  if ( rot[2][2] > rot[i][i] )
324  i = 2;
325  GaUint j = s_iNext[i];
326  GaUint k = s_iNext[j];
327 
328  fRoot = Math::squareRoot(rot[i][i]-rot[j][j]-rot[k][k] + 1.0f);
329  GaFloat* apkQuat[3] = { &v.x, &v.y, &v.z };
330  *apkQuat[i] = 0.5f*fRoot;
331  fRoot = 0.5f/fRoot;
332  w = (rot[k][j]-rot[j][k])*fRoot;
333  *apkQuat[j] = (rot[j][i]+rot[i][j])*fRoot;
334  *apkQuat[k] = (rot[k][i]+rot[i][k])*fRoot;
335  }
336 }
GaVec3 v
Definition: GaTypes.h:267
unsigned int GaUint
Definition: GaPreReqs.h:66
GaFloat x
Definition: GaTypes.h:207
static GaFloat squareRoot(GaFloat f)
Definition: GaMath.h:39
GaFloat w
Definition: GaTypes.h:266
GaFloat y
Definition: GaTypes.h:207
double GaFloat
Definition: GaPreReqs.h:69
GaFloat z
Definition: GaTypes.h:207

Here is the call graph for this function:

Ga::GaQuat::GaQuat ( const Parameter &  oth)

Member Function Documentation

GaQuat GaQuat::inverse ( ) const

Definition at line 338 of file GaTypes.cpp.

References GaQuat(), v, w, Ga::GaVec3::x, Ga::GaVec3::y, and Ga::GaVec3::z.

339 {
340  GaFloat nrm = w*w + v.x*v.x + v.y*v.y + v.z*v.z;
341  if(nrm > 0.0)
342  {
343  GaFloat inv = 1.0f/nrm;
344  return GaQuat(w*inv,-v.x*inv,-v.y*inv,-v.z*inv);
345  }
346  else
347  {
348  return GaQuat(0,0,0,0);
349  }
350 }
GaVec3 v
Definition: GaTypes.h:267
GaFloat x
Definition: GaTypes.h:207
GaExpInl GaQuat()
Definition: GaTypes.h:224
GaFloat w
Definition: GaTypes.h:266
GaFloat y
Definition: GaTypes.h:207
double GaFloat
Definition: GaPreReqs.h:69
GaFloat z
Definition: GaTypes.h:207

Here is the call graph for this function:

GaExpInl GaVec3 Ga::GaQuat::operator* ( const GaVec3 vec) const
inline

Definition at line 231 of file GaTypes.h.

References Ga::GaVec3::crossProduct(), Ga::GaVec3::x, Ga::GaVec3::y, and Ga::GaVec3::z.

232  {
233  GaVec3 uv = v.crossProduct(vec);
234  GaVec3 uuv = v.crossProduct(uv);
235 
236  uv *= (2.0f * w);
237  uuv *= 2.0f;
238 
239  return GaVec3(vec.x + uv.x + uuv.x,vec.y + uv.y + uuv.y,vec.z + uv.z + uuv.z);
240  }
GaVec3 v
Definition: GaTypes.h:267
GaExpInl GaVec3 crossProduct(const GaVec3 &oth) const
Definition: GaTypes.h:140
GaFloat w
Definition: GaTypes.h:266

Here is the call graph for this function:

GaExpInl GaQuat Ga::GaQuat::operator* ( const GaQuat oth) const
inline

Definition at line 242 of file GaTypes.h.

References v, w, Ga::GaVec3::x, Ga::GaVec3::y, and Ga::GaVec3::z.

243  {
244  return GaQuat
245  (
246  w * oth.w - v.x * oth.v.x - v.y * oth.v.y - v.z * oth.v.z,
247  w * oth.v.x + v.x * oth.w + v.y * oth.v.z - v.z * oth.v.y,
248  w * oth.v.y + v.y * oth.w + v.z * oth.v.x - v.x * oth.v.z,
249  w * oth.v.z + v.z * oth.w + v.x * oth.v.y - v.y * oth.v.x
250  );
251  }
GaVec3 v
Definition: GaTypes.h:267
GaFloat x
Definition: GaTypes.h:207
GaExpInl GaQuat()
Definition: GaTypes.h:224
GaFloat w
Definition: GaTypes.h:266
GaFloat y
Definition: GaTypes.h:207
GaFloat z
Definition: GaTypes.h:207
GaExpInl GaQuat& Ga::GaQuat::operator= ( const GaQuat oth)
inline

Definition at line 253 of file GaTypes.h.

References v, and w.

254  {
255  w = oth.w;
256  v = oth.v;
257 
258  return *this;
259  }
GaVec3 v
Definition: GaTypes.h:267
GaFloat w
Definition: GaTypes.h:266
GaQuat& Ga::GaQuat::operator= ( const Parameter &  oth)

Member Data Documentation

GaQuat GaQuat::IDENTITY = GaQuat(1,0,0,0)
static

Definition at line 221 of file GaTypes.h.

GaVec3 Ga::GaQuat::v
GaFloat Ga::GaQuat::w

Definition at line 266 of file GaTypes.h.

Referenced by Ga::GaMat3x3::GaMat3x3(), GaQuat(), inverse(), operator*(), and operator=().

GaQuat GaQuat::ZERO = GaQuat(0,0,0,0)
static

Definition at line 222 of file GaTypes.h.


The documentation for this class was generated from the following files: