22 #ifndef __ND_CUQUAT_H__
23 #define __ND_CUQUAT_H__
26 #include "cuMatrix3x3.h"
31 inline __device__ __host__
cuQuat()
36 inline __device__ __host__
cuQuat(
float x,
float y,
float z,
float w)
51 inline __device__ __host__
cuQuat(
const cuVector& unitAxis,
float angle)
56 const float sinAng = sin(angle);
57 x = unitAxis.x * sinAng;
58 y = unitAxis.y * sinAng;
59 z = unitAxis.z * sinAng;
67 inline cuMatrix3x3 __device__ __host__ GetMatrix3x3 ()
const
70 const cuQuat quat1 (Scale (2.0));
72 const float x2 = x * quat1.x;
73 const float y2 = y * quat1.y;
74 const float z2 = z * quat1.z;
76 const float xy = x * quat1.y;
77 const float xz = x * quat1.z;
78 const float xw = x * quat1.w;
79 const float yz = y * quat1.z;
80 const float yw = y * quat1.w;
81 const float zw = z * quat1.w;
83 const cuVector front(1.0f - y2 - z2, xy + zw, xz - yw, 0.0f);
84 const cuVector up (xy - zw, 1.0f - x2 - z2, yz + xw, 0.0f);
85 const cuVector right(xz + yw, yz - xw, 1.0f - x2 - y2, 0.0f);
89 inline cuQuat __device__ __host__ Normalize()
const
91 return cuVector::Normalize();
94 inline cuQuat __device__ __host__ operator* (
const cuQuat &q)
const
96 const cuVector x_( q.w, q.z, -q.y, -q.x);
97 const cuVector y_(-q.z, q.w, q.x, -q.y);
98 const cuVector z_( q.y, -q.x, q.w, -q.z);