32 #include "math_defs.h" 33 #include "math_funcs.h" 45 _FORCE_INLINE_ real_t length_squared()
const;
46 real_t length()
const;
48 Quat normalized()
const;
50 _FORCE_INLINE_ real_t dot(
const Quat& q)
const;
51 void set_euler(
const Vector3& p_euler);
52 Quat slerp(
const Quat& q,
const real_t& t)
const;
53 Quat slerpni(
const Quat& q,
const real_t& t)
const;
54 Quat cubic_slerp(
const Quat& q,
const Quat& prep,
const Quat& postq,
const real_t& t)
const;
56 _FORCE_INLINE_
void get_axis_and_angle(
Vector3& r_axis, real_t &r_angle)
const {
57 r_angle = 2 * Math::acos(w);
58 r_axis.x = -x / Math::sqrt(1-w*w);
59 r_axis.y = -y / Math::sqrt(1-w*w);
60 r_axis.z = -z / Math::sqrt(1-w*w);
63 void operator*=(
const Quat& q);
70 return Quat( w * v.x + y * v.z - z * v.y,
71 w * v.y + z * v.x - x * v.z,
72 w * v.z + x * v.y - y * v.x,
73 -x * v.x - y * v.y - z * v.z);
83 _FORCE_INLINE_
void operator+=(
const Quat& q);
84 _FORCE_INLINE_
void operator-=(
const Quat& q);
85 _FORCE_INLINE_
void operator*=(
const real_t& s);
86 _FORCE_INLINE_
void operator/=(
const real_t& s);
87 _FORCE_INLINE_
Quat operator+(
const Quat& q2)
const;
88 _FORCE_INLINE_
Quat operator-(
const Quat& q2)
const;
89 _FORCE_INLINE_
Quat operator-()
const;
90 _FORCE_INLINE_
Quat operator*(
const real_t& s)
const;
91 _FORCE_INLINE_
Quat operator/(
const real_t& s)
const;
94 _FORCE_INLINE_
bool operator==(
const Quat& p_quat)
const;
95 _FORCE_INLINE_
bool operator!=(
const Quat& p_quat)
const;
99 inline void set( real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
100 x=p_x; y=p_y; z=p_z; w=p_w;
102 inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
103 x=p_x; y=p_y; z=p_z; w=p_w;
110 real_t d = v0.dot(v1);
112 if (d < -1.0 + CMP_EPSILON) {
119 real_t s = Math::sqrt((1.0f + d) * 2.0f);
120 real_t rs = 1.0f / s;
129 inline Quat() {x=y=z=0; w=1; }
135 real_t Quat::dot(
const Quat& q)
const {
136 return x * q.x+y * q.y+z * q.z+w * q.w;
139 real_t Quat::length_squared()
const {
143 void Quat::operator+=(
const Quat& q) {
144 x += q.x; y += q.y; z += q.z; w += q.w;
147 void Quat::operator-=(
const Quat& q) {
148 x -= q.x; y -= q.y; z -= q.z; w -= q.w;
151 void Quat::operator*=(
const real_t& s) {
152 x *= s; y *= s; z *= s; w *= s;
156 void Quat::operator/=(
const real_t& s) {
161 Quat Quat::operator+(
const Quat& q2)
const {
162 const Quat& q1 = *
this;
163 return Quat( q1.x+q2.x, q1.y+q2.y, q1.z+q2.z, q1.w+q2.w );
166 Quat Quat::operator-(
const Quat& q2)
const {
167 const Quat& q1 = *
this;
168 return Quat( q1.x-q2.x, q1.y-q2.y, q1.z-q2.z, q1.w-q2.w);
171 Quat Quat::operator-()
const {
172 const Quat& q2 = *
this;
173 return Quat( -q2.x, -q2.y, -q2.z, -q2.w);
176 Quat Quat::operator*(
const real_t& s)
const {
177 return Quat(x * s, y * s, z * s, w * s);
180 Quat Quat::operator/(
const real_t& s)
const {
181 return *
this * (1.0 / s);
185 bool Quat::operator==(
const Quat& p_quat)
const {
187 return x==p_quat.x && y==p_quat.y && z==p_quat.z && w==p_quat.w;
190 bool Quat::operator!=(
const Quat& p_quat)
const {
192 return x!=p_quat.x || y!=p_quat.y || z!=p_quat.z || w!=p_quat.w;