17 #ifndef _VECTORMATH_QUAT_AOS_CPP_H
18 #define _VECTORMATH_QUAT_AOS_CPP_H
23 #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
24 #define _VECTORMATH_INTERNAL_FUNCTIONS
28 namespace Vectormath {
36 inline Quat::Quat(
float _x,
float _y,
float _z,
float _w )
57 mXYZW[0] = vec.
getX();
58 mXYZW[1] = vec.
getY();
59 mXYZW[2] = vec.
getZ();
60 mXYZW[3] = vec.
getW();
65 vXYZW = vdupq_n_f32(scalar);
70 return Quat( 0.0f, 0.0f, 0.0f, 1.0f );
75 return ( quat0 + ( ( quat1 - quat0 ) * t ) );
81 float recipSinAngle, scale0, scale1, cosAngle, angle;
82 cosAngle =
dot( unitQuat0, unitQuat1 );
83 if ( cosAngle < 0.0f ) {
85 start = ( -unitQuat0 );
90 angle = acosf( cosAngle );
91 recipSinAngle = ( 1.0f / sinf( angle ) );
92 scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle );
93 scale1 = ( sinf( ( t * angle ) ) * recipSinAngle );
95 scale0 = ( 1.0f - t );
98 return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) );
104 tmp0 =
slerp( t, unitQuat0, unitQuat3 );
105 tmp1 =
slerp( t, unitQuat1, unitQuat2 );
106 return slerp( ( ( 2.0f * t ) * ( 1.0f - t ) ), tmp0, tmp1 );
111 quat =
Quat( fptr[0], fptr[1], fptr[2], fptr[3] );
116 vst1q_f32(fptr, quat.getvXYZW());
121 vXYZW = quat.getvXYZW();
127 mXYZW[0] = vec.
getX();
128 mXYZW[1] = vec.
getY();
129 mXYZW[2] = vec.
getZ();
135 return Vector3( mXYZW[0], mXYZW[1], mXYZW[2] );
138 inline float32x4_t Quat::getvXYZW( )
const
189 *(&mXYZW[0] + idx) = value;
195 return *(&mXYZW[0] + idx);
200 return *(&mXYZW[0] + idx);
205 return *(&mXYZW[0] + idx);
210 return Quat( vaddq_f32(vXYZW, quat.vXYZW) );
215 return Quat( vsubq_f32(vXYZW, quat.vXYZW) );
220 float32x4_t v_scalar = vdupq_n_f32(scalar);
221 return Quat( vmulq_f32(vXYZW, v_scalar) );
226 *
this = *
this + quat;
232 *
this = *
this - quat;
238 *
this = *
this * scalar;
245 ( mXYZW[0] / scalar ),
246 ( mXYZW[1] / scalar ),
247 ( mXYZW[2] / scalar ),
248 ( mXYZW[3] / scalar )
254 *
this = *
this / scalar;
260 return Quat( vnegq_f32(vXYZW) );
265 return quat * scalar;
271 result = ( quat0.
getX() * quat1.
getX() );
272 result = ( result + ( quat0.
getY() * quat1.
getY() ) );
273 result = ( result + ( quat0.
getZ() * quat1.
getZ() ) );
274 result = ( result + ( quat0.
getW() * quat1.
getW() ) );
281 result = ( quat.
getX() * quat.
getX() );
282 result = ( result + ( quat.
getY() * quat.
getY() ) );
283 result = ( result + ( quat.
getZ() * quat.
getZ() ) );
284 result = ( result + ( quat.
getW() * quat.
getW() ) );
290 return ::sqrtf(
norm( quat ) );
295 float lenSqr, lenInv;
296 lenSqr =
norm( quat );
297 lenInv = ( 1.0f / sqrtf( lenSqr ) );
299 ( quat.
getX() * lenInv ),
300 ( quat.
getY() * lenInv ),
301 ( quat.
getZ() * lenInv ),
302 ( quat.
getW() * lenInv )
308 float cosHalfAngleX2, recipCosHalfAngleX2;
309 cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f +
dot( unitVec0, unitVec1 ) ) ) );
310 recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 );
311 return Quat( (
cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), ( cosHalfAngleX2 * 0.5f ) );
317 angle = ( radians * 0.5f );
320 return Quat( ( unitVec * s ), c );
326 angle = ( radians * 0.5f );
329 return Quat( s, 0.0f, 0.0f, c );
335 angle = ( radians * 0.5f );
338 return Quat( 0.0f, s, 0.0f, c );
344 angle = ( radians * 0.5f );
347 return Quat( 0.0f, 0.0f, s, c );
353 ( ( ( ( mXYZW[3] * quat.mXYZW[0] ) + ( mXYZW[0] * quat.mXYZW[3] ) ) + ( mXYZW[1] * quat.mXYZW[2] ) ) - ( mXYZW[2] * quat.mXYZW[1] ) ),
354 ( ( ( ( mXYZW[3] * quat.mXYZW[1] ) + ( mXYZW[1] * quat.mXYZW[3] ) ) + ( mXYZW[2] * quat.mXYZW[0] ) ) - ( mXYZW[0] * quat.mXYZW[2] ) ),
355 ( ( ( ( mXYZW[3] * quat.mXYZW[2] ) + ( mXYZW[2] * quat.mXYZW[3] ) ) + ( mXYZW[0] * quat.mXYZW[1] ) ) - ( mXYZW[1] * quat.mXYZW[0] ) ),
356 ( ( ( ( mXYZW[3] * quat.mXYZW[3] ) - ( mXYZW[0] * quat.mXYZW[0] ) ) - ( mXYZW[1] * quat.mXYZW[1] ) ) - ( mXYZW[2] * quat.mXYZW[2] ) )
362 *
this = *
this * quat;
368 float tmpX, tmpY, tmpZ, tmpW;
374 ( ( ( ( tmpW * quat.
getX() ) + ( tmpX * quat.
getW() ) ) - ( tmpY * quat.
getZ() ) ) + ( tmpZ * quat.
getY() ) ),
375 ( ( ( ( tmpW * quat.
getY() ) + ( tmpY * quat.
getW() ) ) - ( tmpZ * quat.
getX() ) ) + ( tmpX * quat.
getZ() ) ),
376 ( ( ( ( tmpW * quat.
getZ() ) + ( tmpZ * quat.
getW() ) ) - ( tmpX * quat.
getY() ) ) + ( tmpY * quat.
getX() ) )
388 ( select1 )? quat1.
getX() : quat0.
getX(),
389 ( select1 )? quat1.
getY() : quat0.
getY(),
390 ( select1 )? quat1.
getZ() : quat0.
getZ(),
391 ( select1 )? quat1.
getW() : quat0.
getW()
395 #ifdef _VECTORMATH_DEBUG
397 inline void print(
const Quat & quat )
399 printf(
"( %f %f %f %f )\n", quat.getX(), quat.getY(), quat.getZ(), quat.getW() );
402 inline void print(
const Quat & quat,
const char * name )
404 printf(
"%s: ( %f %f %f %f )\n", name, quat.getX(), quat.getY(), quat.getZ(), quat.getW() );
const Quat normalize(const Quat &quat)
static const Quat rotationY(float radians)
Quat & operator*=(const Quat &quat)
Quat & operator-=(const Quat &quat)
const Quat operator+(const Quat &quat) const
Quat & operator=(const Quat &quat)
#define _VECTORMATH_SLERP_TOL
const Vector3 rotate(const Quat &quat, const Vector3 &vec)
float & operator[](int idx)
static const Quat identity()
static const Quat rotationZ(float radians)
static const Quat rotation(const Vector3 &unitVec0, const Vector3 &unitVec1)
static const Quat rotationX(float radians)
const Quat operator*(const Quat &quat) const
float norm(const Quat &quat)
const Quat operator/(float scalar) const
const Quat operator-() const
const Vector3 getXYZ() const
void loadXYZW(Quat &quat, const float *fptr)
const Quat conj(const Quat &quat)
Quat & operator/=(float scalar)
void storeXYZW(const Quat &quat, float *fptr)
const Quat lerp(float t, const Quat &quat0, const Quat &quat1)
const Matrix3 select(const Matrix3 &mat0, const Matrix3 &mat1, bool select1)
Quat & setElem(int idx, float value)
float getElem(int idx) const
const Quat squad(float t, const Quat &unitQuat0, const Quat &unitQuat1, const Quat &unitQuat2, const Quat &unitQuat3)
float dot(const Quat &quat0, const Quat &quat1)
const Vector3 cross(const Vector3 &vec0, const Vector3 &vec1)
Quat & setXYZ(const Vector3 &vec)
float length(const Quat &quat)
const Matrix3 operator*(float scalar, const Matrix3 &mat)
Quat & operator+=(const Quat &quat)
const Quat slerp(float t, const Quat &unitQuat0, const Quat &unitQuat1)