Added vectormath library, the open source version. Currently, PowerPC PPU, Cell SPU and a scalar version is available.
An SSE port of vectormath might become available too.
This commit is contained in:
1452
Extras/vectormathlibrary/include/vectormath/scalar/c/mat_aos.h
Normal file
1452
Extras/vectormathlibrary/include/vectormath/scalar/c/mat_aos.h
Normal file
File diff suppressed because it is too large
Load Diff
1006
Extras/vectormathlibrary/include/vectormath/scalar/c/mat_aos_v.h
Normal file
1006
Extras/vectormathlibrary/include/vectormath/scalar/c/mat_aos_v.h
Normal file
File diff suppressed because it is too large
Load Diff
368
Extras/vectormathlibrary/include/vectormath/scalar/c/quat_aos.h
Normal file
368
Extras/vectormathlibrary/include/vectormath/scalar/c/quat_aos.h
Normal file
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Sony Computer Entertainment Inc nor the names
|
||||
of its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VECTORMATH_QUAT_AOS_C_H
|
||||
#define _VECTORMATH_QUAT_AOS_C_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Definitions
|
||||
*/
|
||||
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
#define _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
|
||||
#endif
|
||||
|
||||
static inline void vmathQCopy( VmathQuat *result, const VmathQuat *quat )
|
||||
{
|
||||
result->x = quat->x;
|
||||
result->y = quat->y;
|
||||
result->z = quat->z;
|
||||
result->w = quat->w;
|
||||
}
|
||||
|
||||
static inline void vmathQMakeFromElems( VmathQuat *result, float _x, float _y, float _z, float _w )
|
||||
{
|
||||
result->x = _x;
|
||||
result->y = _y;
|
||||
result->z = _z;
|
||||
result->w = _w;
|
||||
}
|
||||
|
||||
static inline void vmathQMakeFromV3Scalar( VmathQuat *result, const VmathVector3 *xyz, float _w )
|
||||
{
|
||||
vmathQSetXYZ( result, xyz );
|
||||
vmathQSetW( result, _w );
|
||||
}
|
||||
|
||||
static inline void vmathQMakeFromV4( VmathQuat *result, const VmathVector4 *vec )
|
||||
{
|
||||
result->x = vec->x;
|
||||
result->y = vec->y;
|
||||
result->z = vec->z;
|
||||
result->w = vec->w;
|
||||
}
|
||||
|
||||
static inline void vmathQMakeFromScalar( VmathQuat *result, float scalar )
|
||||
{
|
||||
result->x = scalar;
|
||||
result->y = scalar;
|
||||
result->z = scalar;
|
||||
result->w = scalar;
|
||||
}
|
||||
|
||||
static inline void vmathQMakeIdentity( VmathQuat *result )
|
||||
{
|
||||
vmathQMakeFromElems( result, 0.0f, 0.0f, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
static inline void vmathQLerp( VmathQuat *result, float t, const VmathQuat *quat0, const VmathQuat *quat1 )
|
||||
{
|
||||
VmathQuat tmpQ_0, tmpQ_1;
|
||||
vmathQSub( &tmpQ_0, quat1, quat0 );
|
||||
vmathQScalarMul( &tmpQ_1, &tmpQ_0, t );
|
||||
vmathQAdd( result, quat0, &tmpQ_1 );
|
||||
}
|
||||
|
||||
static inline void vmathQSlerp( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1 )
|
||||
{
|
||||
VmathQuat start, tmpQ_0, tmpQ_1;
|
||||
float recipSinAngle, scale0, scale1, cosAngle, angle;
|
||||
cosAngle = vmathQDot( unitQuat0, unitQuat1 );
|
||||
if ( cosAngle < 0.0f ) {
|
||||
cosAngle = -cosAngle;
|
||||
vmathQNeg( &start, unitQuat0 );
|
||||
} else {
|
||||
vmathQCopy( &start, unitQuat0 );
|
||||
}
|
||||
if ( cosAngle < _VECTORMATH_SLERP_TOL ) {
|
||||
angle = acosf( cosAngle );
|
||||
recipSinAngle = ( 1.0f / sinf( angle ) );
|
||||
scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle );
|
||||
scale1 = ( sinf( ( t * angle ) ) * recipSinAngle );
|
||||
} else {
|
||||
scale0 = ( 1.0f - t );
|
||||
scale1 = t;
|
||||
}
|
||||
vmathQScalarMul( &tmpQ_0, &start, scale0 );
|
||||
vmathQScalarMul( &tmpQ_1, unitQuat1, scale1 );
|
||||
vmathQAdd( result, &tmpQ_0, &tmpQ_1 );
|
||||
}
|
||||
|
||||
static inline void vmathQSquad( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1, const VmathQuat *unitQuat2, const VmathQuat *unitQuat3 )
|
||||
{
|
||||
VmathQuat tmp0, tmp1;
|
||||
vmathQSlerp( &tmp0, t, unitQuat0, unitQuat3 );
|
||||
vmathQSlerp( &tmp1, t, unitQuat1, unitQuat2 );
|
||||
vmathQSlerp( result, ( ( 2.0f * t ) * ( 1.0f - t ) ), &tmp0, &tmp1 );
|
||||
}
|
||||
|
||||
static inline void vmathQSetXYZ( VmathQuat *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = vec->x;
|
||||
result->y = vec->y;
|
||||
result->z = vec->z;
|
||||
}
|
||||
|
||||
static inline void vmathQGetXYZ( VmathVector3 *result, const VmathQuat *quat )
|
||||
{
|
||||
vmathV3MakeFromElems( result, quat->x, quat->y, quat->z );
|
||||
}
|
||||
|
||||
static inline void vmathQSetX( VmathQuat *result, float _x )
|
||||
{
|
||||
result->x = _x;
|
||||
}
|
||||
|
||||
static inline float vmathQGetX( const VmathQuat *quat )
|
||||
{
|
||||
return quat->x;
|
||||
}
|
||||
|
||||
static inline void vmathQSetY( VmathQuat *result, float _y )
|
||||
{
|
||||
result->y = _y;
|
||||
}
|
||||
|
||||
static inline float vmathQGetY( const VmathQuat *quat )
|
||||
{
|
||||
return quat->y;
|
||||
}
|
||||
|
||||
static inline void vmathQSetZ( VmathQuat *result, float _z )
|
||||
{
|
||||
result->z = _z;
|
||||
}
|
||||
|
||||
static inline float vmathQGetZ( const VmathQuat *quat )
|
||||
{
|
||||
return quat->z;
|
||||
}
|
||||
|
||||
static inline void vmathQSetW( VmathQuat *result, float _w )
|
||||
{
|
||||
result->w = _w;
|
||||
}
|
||||
|
||||
static inline float vmathQGetW( const VmathQuat *quat )
|
||||
{
|
||||
return quat->w;
|
||||
}
|
||||
|
||||
static inline void vmathQSetElem( VmathQuat *result, int idx, float value )
|
||||
{
|
||||
*(&result->x + idx) = value;
|
||||
}
|
||||
|
||||
static inline float vmathQGetElem( const VmathQuat *quat, int idx )
|
||||
{
|
||||
return *(&quat->x + idx);
|
||||
}
|
||||
|
||||
static inline void vmathQAdd( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
|
||||
{
|
||||
result->x = ( quat0->x + quat1->x );
|
||||
result->y = ( quat0->y + quat1->y );
|
||||
result->z = ( quat0->z + quat1->z );
|
||||
result->w = ( quat0->w + quat1->w );
|
||||
}
|
||||
|
||||
static inline void vmathQSub( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
|
||||
{
|
||||
result->x = ( quat0->x - quat1->x );
|
||||
result->y = ( quat0->y - quat1->y );
|
||||
result->z = ( quat0->z - quat1->z );
|
||||
result->w = ( quat0->w - quat1->w );
|
||||
}
|
||||
|
||||
static inline void vmathQScalarMul( VmathQuat *result, const VmathQuat *quat, float scalar )
|
||||
{
|
||||
result->x = ( quat->x * scalar );
|
||||
result->y = ( quat->y * scalar );
|
||||
result->z = ( quat->z * scalar );
|
||||
result->w = ( quat->w * scalar );
|
||||
}
|
||||
|
||||
static inline void vmathQScalarDiv( VmathQuat *result, const VmathQuat *quat, float scalar )
|
||||
{
|
||||
result->x = ( quat->x / scalar );
|
||||
result->y = ( quat->y / scalar );
|
||||
result->z = ( quat->z / scalar );
|
||||
result->w = ( quat->w / scalar );
|
||||
}
|
||||
|
||||
static inline void vmathQNeg( VmathQuat *result, const VmathQuat *quat )
|
||||
{
|
||||
result->x = -quat->x;
|
||||
result->y = -quat->y;
|
||||
result->z = -quat->z;
|
||||
result->w = -quat->w;
|
||||
}
|
||||
|
||||
static inline float vmathQDot( const VmathQuat *quat0, const VmathQuat *quat1 )
|
||||
{
|
||||
float result;
|
||||
result = ( quat0->x * quat1->x );
|
||||
result = ( result + ( quat0->y * quat1->y ) );
|
||||
result = ( result + ( quat0->z * quat1->z ) );
|
||||
result = ( result + ( quat0->w * quat1->w ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathQNorm( const VmathQuat *quat )
|
||||
{
|
||||
float result;
|
||||
result = ( quat->x * quat->x );
|
||||
result = ( result + ( quat->y * quat->y ) );
|
||||
result = ( result + ( quat->z * quat->z ) );
|
||||
result = ( result + ( quat->w * quat->w ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathQLength( const VmathQuat *quat )
|
||||
{
|
||||
return sqrtf( vmathQNorm( quat ) );
|
||||
}
|
||||
|
||||
static inline void vmathQNormalize( VmathQuat *result, const VmathQuat *quat )
|
||||
{
|
||||
float lenSqr, lenInv;
|
||||
lenSqr = vmathQNorm( quat );
|
||||
lenInv = ( 1.0f / sqrtf( lenSqr ) );
|
||||
result->x = ( quat->x * lenInv );
|
||||
result->y = ( quat->y * lenInv );
|
||||
result->z = ( quat->z * lenInv );
|
||||
result->w = ( quat->w * lenInv );
|
||||
}
|
||||
|
||||
static inline void vmathQMakeRotationArc( VmathQuat *result, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 )
|
||||
{
|
||||
VmathVector3 tmpV3_0, tmpV3_1;
|
||||
float cosHalfAngleX2, recipCosHalfAngleX2;
|
||||
cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f + vmathV3Dot( unitVec0, unitVec1 ) ) ) );
|
||||
recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 );
|
||||
vmathV3Cross( &tmpV3_0, unitVec0, unitVec1 );
|
||||
vmathV3ScalarMul( &tmpV3_1, &tmpV3_0, recipCosHalfAngleX2 );
|
||||
vmathQMakeFromV3Scalar( result, &tmpV3_1, ( cosHalfAngleX2 * 0.5f ) );
|
||||
}
|
||||
|
||||
static inline void vmathQMakeRotationAxis( VmathQuat *result, float radians, const VmathVector3 *unitVec )
|
||||
{
|
||||
VmathVector3 tmpV3_0;
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
vmathV3ScalarMul( &tmpV3_0, unitVec, s );
|
||||
vmathQMakeFromV3Scalar( result, &tmpV3_0, c );
|
||||
}
|
||||
|
||||
static inline void vmathQMakeRotationX( VmathQuat *result, float radians )
|
||||
{
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
vmathQMakeFromElems( result, s, 0.0f, 0.0f, c );
|
||||
}
|
||||
|
||||
static inline void vmathQMakeRotationY( VmathQuat *result, float radians )
|
||||
{
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
vmathQMakeFromElems( result, 0.0f, s, 0.0f, c );
|
||||
}
|
||||
|
||||
static inline void vmathQMakeRotationZ( VmathQuat *result, float radians )
|
||||
{
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
vmathQMakeFromElems( result, 0.0f, 0.0f, s, c );
|
||||
}
|
||||
|
||||
static inline void vmathQMul( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
|
||||
{
|
||||
float tmpX, tmpY, tmpZ, tmpW;
|
||||
tmpX = ( ( ( ( quat0->w * quat1->x ) + ( quat0->x * quat1->w ) ) + ( quat0->y * quat1->z ) ) - ( quat0->z * quat1->y ) );
|
||||
tmpY = ( ( ( ( quat0->w * quat1->y ) + ( quat0->y * quat1->w ) ) + ( quat0->z * quat1->x ) ) - ( quat0->x * quat1->z ) );
|
||||
tmpZ = ( ( ( ( quat0->w * quat1->z ) + ( quat0->z * quat1->w ) ) + ( quat0->x * quat1->y ) ) - ( quat0->y * quat1->x ) );
|
||||
tmpW = ( ( ( ( quat0->w * quat1->w ) - ( quat0->x * quat1->x ) ) - ( quat0->y * quat1->y ) ) - ( quat0->z * quat1->z ) );
|
||||
vmathQMakeFromElems( result, tmpX, tmpY, tmpZ, tmpW );
|
||||
}
|
||||
|
||||
static inline void vmathQRotate( VmathVector3 *result, const VmathQuat *quat, const VmathVector3 *vec )
|
||||
{
|
||||
float tmpX, tmpY, tmpZ, tmpW;
|
||||
tmpX = ( ( ( quat->w * vec->x ) + ( quat->y * vec->z ) ) - ( quat->z * vec->y ) );
|
||||
tmpY = ( ( ( quat->w * vec->y ) + ( quat->z * vec->x ) ) - ( quat->x * vec->z ) );
|
||||
tmpZ = ( ( ( quat->w * vec->z ) + ( quat->x * vec->y ) ) - ( quat->y * vec->x ) );
|
||||
tmpW = ( ( ( quat->x * vec->x ) + ( quat->y * vec->y ) ) + ( quat->z * vec->z ) );
|
||||
result->x = ( ( ( ( tmpW * quat->x ) + ( tmpX * quat->w ) ) - ( tmpY * quat->z ) ) + ( tmpZ * quat->y ) );
|
||||
result->y = ( ( ( ( tmpW * quat->y ) + ( tmpY * quat->w ) ) - ( tmpZ * quat->x ) ) + ( tmpX * quat->z ) );
|
||||
result->z = ( ( ( ( tmpW * quat->z ) + ( tmpZ * quat->w ) ) - ( tmpX * quat->y ) ) + ( tmpY * quat->x ) );
|
||||
}
|
||||
|
||||
static inline void vmathQConj( VmathQuat *result, const VmathQuat *quat )
|
||||
{
|
||||
vmathQMakeFromElems( result, -quat->x, -quat->y, -quat->z, quat->w );
|
||||
}
|
||||
|
||||
static inline void vmathQSelect( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, unsigned int select1 )
|
||||
{
|
||||
result->x = ( select1 )? quat1->x : quat0->x;
|
||||
result->y = ( select1 )? quat1->y : quat0->y;
|
||||
result->z = ( select1 )? quat1->z : quat0->z;
|
||||
result->w = ( select1 )? quat1->w : quat0->w;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathQPrint( const VmathQuat *quat )
|
||||
{
|
||||
printf( "( %f %f %f %f )\n", quat->x, quat->y, quat->z, quat->w );
|
||||
}
|
||||
|
||||
static inline void vmathQPrints( const VmathQuat *quat, const char *name )
|
||||
{
|
||||
printf( "%s: ( %f %f %f %f )\n", name, quat->x, quat->y, quat->z, quat->w );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Sony Computer Entertainment Inc nor the names
|
||||
of its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VECTORMATH_QUAT_AOS_V_C_H
|
||||
#define _VECTORMATH_QUAT_AOS_V_C_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Definitions
|
||||
*/
|
||||
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
#define _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
|
||||
#endif
|
||||
|
||||
static inline VmathQuat vmathQMakeFromElems_V( float _x, float _y, float _z, float _w )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeFromElems(&result, _x, _y, _z, _w);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeFromV3Scalar_V( VmathVector3 xyz, float _w )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeFromV3Scalar(&result, &xyz, _w);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeFromV4_V( VmathVector4 vec )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeFromV4(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeFromScalar_V( float scalar )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeFromScalar(&result, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeIdentity_V( )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeIdentity(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQLerp_V( float t, VmathQuat quat0, VmathQuat quat1 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQLerp(&result, t, &quat0, &quat1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQSlerp_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQSlerp(&result, t, &unitQuat0, &unitQuat1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQSquad_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1, VmathQuat unitQuat2, VmathQuat unitQuat3 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathQSetXYZ_V( VmathQuat *result, VmathVector3 vec )
|
||||
{
|
||||
vmathQSetXYZ(result, &vec);
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathQGetXYZ_V( VmathQuat quat )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathQGetXYZ(&result, &quat);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathQSetX_V( VmathQuat *result, float _x )
|
||||
{
|
||||
vmathQSetX(result, _x);
|
||||
}
|
||||
|
||||
static inline float vmathQGetX_V( VmathQuat quat )
|
||||
{
|
||||
return vmathQGetX(&quat);
|
||||
}
|
||||
|
||||
static inline void vmathQSetY_V( VmathQuat *result, float _y )
|
||||
{
|
||||
vmathQSetY(result, _y);
|
||||
}
|
||||
|
||||
static inline float vmathQGetY_V( VmathQuat quat )
|
||||
{
|
||||
return vmathQGetY(&quat);
|
||||
}
|
||||
|
||||
static inline void vmathQSetZ_V( VmathQuat *result, float _z )
|
||||
{
|
||||
vmathQSetZ(result, _z);
|
||||
}
|
||||
|
||||
static inline float vmathQGetZ_V( VmathQuat quat )
|
||||
{
|
||||
return vmathQGetZ(&quat);
|
||||
}
|
||||
|
||||
static inline void vmathQSetW_V( VmathQuat *result, float _w )
|
||||
{
|
||||
vmathQSetW(result, _w);
|
||||
}
|
||||
|
||||
static inline float vmathQGetW_V( VmathQuat quat )
|
||||
{
|
||||
return vmathQGetW(&quat);
|
||||
}
|
||||
|
||||
static inline void vmathQSetElem_V( VmathQuat *result, int idx, float value )
|
||||
{
|
||||
vmathQSetElem(result, idx, value);
|
||||
}
|
||||
|
||||
static inline float vmathQGetElem_V( VmathQuat quat, int idx )
|
||||
{
|
||||
return vmathQGetElem(&quat, idx);
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQAdd_V( VmathQuat quat0, VmathQuat quat1 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQAdd(&result, &quat0, &quat1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQSub_V( VmathQuat quat0, VmathQuat quat1 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQSub(&result, &quat0, &quat1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQScalarMul_V( VmathQuat quat, float scalar )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQScalarMul(&result, &quat, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQScalarDiv_V( VmathQuat quat, float scalar )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQScalarDiv(&result, &quat, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQNeg_V( VmathQuat quat )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQNeg(&result, &quat);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathQDot_V( VmathQuat quat0, VmathQuat quat1 )
|
||||
{
|
||||
return vmathQDot(&quat0, &quat1);
|
||||
}
|
||||
|
||||
static inline float vmathQNorm_V( VmathQuat quat )
|
||||
{
|
||||
return vmathQNorm(&quat);
|
||||
}
|
||||
|
||||
static inline float vmathQLength_V( VmathQuat quat )
|
||||
{
|
||||
return vmathQLength(&quat);
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQNormalize_V( VmathQuat quat )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQNormalize(&result, &quat);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeRotationArc_V( VmathVector3 unitVec0, VmathVector3 unitVec1 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeRotationArc(&result, &unitVec0, &unitVec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeRotationAxis_V( float radians, VmathVector3 unitVec )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeRotationAxis(&result, radians, &unitVec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeRotationX_V( float radians )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeRotationX(&result, radians);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeRotationY_V( float radians )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeRotationY(&result, radians);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMakeRotationZ_V( float radians )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMakeRotationZ(&result, radians);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQMul_V( VmathQuat quat0, VmathQuat quat1 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQMul(&result, &quat0, &quat1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathQRotate_V( VmathQuat quat, VmathVector3 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathQRotate(&result, &quat, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQConj_V( VmathQuat quat )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQConj(&result, &quat);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathQuat vmathQSelect_V( VmathQuat quat0, VmathQuat quat1, unsigned int select1 )
|
||||
{
|
||||
VmathQuat result;
|
||||
vmathQSelect(&result, &quat0, &quat1, select1);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathQPrint_V( VmathQuat quat )
|
||||
{
|
||||
vmathQPrint(&quat);
|
||||
}
|
||||
|
||||
static inline void vmathQPrints_V( VmathQuat quat, const char *name )
|
||||
{
|
||||
vmathQPrints(&quat, name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
971
Extras/vectormathlibrary/include/vectormath/scalar/c/vec_aos.h
Normal file
971
Extras/vectormathlibrary/include/vectormath/scalar/c/vec_aos.h
Normal file
@@ -0,0 +1,971 @@
|
||||
/*
|
||||
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Sony Computer Entertainment Inc nor the names
|
||||
of its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VECTORMATH_VEC_AOS_C_H
|
||||
#define _VECTORMATH_VEC_AOS_C_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Constants
|
||||
*/
|
||||
#define _VECTORMATH_SLERP_TOL 0.999f
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Definitions
|
||||
*/
|
||||
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
#define _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
|
||||
#endif
|
||||
|
||||
static inline void vmathV3Copy( VmathVector3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = vec->x;
|
||||
result->y = vec->y;
|
||||
result->z = vec->z;
|
||||
}
|
||||
|
||||
static inline void vmathV3MakeFromElems( VmathVector3 *result, float _x, float _y, float _z )
|
||||
{
|
||||
result->x = _x;
|
||||
result->y = _y;
|
||||
result->z = _z;
|
||||
}
|
||||
|
||||
static inline void vmathV3MakeFromP3( VmathVector3 *result, const VmathPoint3 *pnt )
|
||||
{
|
||||
result->x = pnt->x;
|
||||
result->y = pnt->y;
|
||||
result->z = pnt->z;
|
||||
}
|
||||
|
||||
static inline void vmathV3MakeFromScalar( VmathVector3 *result, float scalar )
|
||||
{
|
||||
result->x = scalar;
|
||||
result->y = scalar;
|
||||
result->z = scalar;
|
||||
}
|
||||
|
||||
static inline void vmathV3MakeXAxis( VmathVector3 *result )
|
||||
{
|
||||
vmathV3MakeFromElems( result, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
static inline void vmathV3MakeYAxis( VmathVector3 *result )
|
||||
{
|
||||
vmathV3MakeFromElems( result, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
static inline void vmathV3MakeZAxis( VmathVector3 *result )
|
||||
{
|
||||
vmathV3MakeFromElems( result, 0.0f, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
static inline void vmathV3Lerp( VmathVector3 *result, float t, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
VmathVector3 tmpV3_0, tmpV3_1;
|
||||
vmathV3Sub( &tmpV3_0, vec1, vec0 );
|
||||
vmathV3ScalarMul( &tmpV3_1, &tmpV3_0, t );
|
||||
vmathV3Add( result, vec0, &tmpV3_1 );
|
||||
}
|
||||
|
||||
static inline void vmathV3Slerp( VmathVector3 *result, float t, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 )
|
||||
{
|
||||
VmathVector3 tmpV3_0, tmpV3_1;
|
||||
float recipSinAngle, scale0, scale1, cosAngle, angle;
|
||||
cosAngle = vmathV3Dot( unitVec0, unitVec1 );
|
||||
if ( cosAngle < _VECTORMATH_SLERP_TOL ) {
|
||||
angle = acosf( cosAngle );
|
||||
recipSinAngle = ( 1.0f / sinf( angle ) );
|
||||
scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle );
|
||||
scale1 = ( sinf( ( t * angle ) ) * recipSinAngle );
|
||||
} else {
|
||||
scale0 = ( 1.0f - t );
|
||||
scale1 = t;
|
||||
}
|
||||
vmathV3ScalarMul( &tmpV3_0, unitVec0, scale0 );
|
||||
vmathV3ScalarMul( &tmpV3_1, unitVec1, scale1 );
|
||||
vmathV3Add( result, &tmpV3_0, &tmpV3_1 );
|
||||
}
|
||||
|
||||
static inline void vmathV3SetX( VmathVector3 *result, float _x )
|
||||
{
|
||||
result->x = _x;
|
||||
}
|
||||
|
||||
static inline float vmathV3GetX( const VmathVector3 *vec )
|
||||
{
|
||||
return vec->x;
|
||||
}
|
||||
|
||||
static inline void vmathV3SetY( VmathVector3 *result, float _y )
|
||||
{
|
||||
result->y = _y;
|
||||
}
|
||||
|
||||
static inline float vmathV3GetY( const VmathVector3 *vec )
|
||||
{
|
||||
return vec->y;
|
||||
}
|
||||
|
||||
static inline void vmathV3SetZ( VmathVector3 *result, float _z )
|
||||
{
|
||||
result->z = _z;
|
||||
}
|
||||
|
||||
static inline float vmathV3GetZ( const VmathVector3 *vec )
|
||||
{
|
||||
return vec->z;
|
||||
}
|
||||
|
||||
static inline void vmathV3SetElem( VmathVector3 *result, int idx, float value )
|
||||
{
|
||||
*(&result->x + idx) = value;
|
||||
}
|
||||
|
||||
static inline float vmathV3GetElem( const VmathVector3 *vec, int idx )
|
||||
{
|
||||
return *(&vec->x + idx);
|
||||
}
|
||||
|
||||
static inline void vmathV3Add( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x + vec1->x );
|
||||
result->y = ( vec0->y + vec1->y );
|
||||
result->z = ( vec0->z + vec1->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3Sub( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x - vec1->x );
|
||||
result->y = ( vec0->y - vec1->y );
|
||||
result->z = ( vec0->z - vec1->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3AddP3( VmathPoint3 *result, const VmathVector3 *vec, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
result->x = ( vec->x + pnt1->x );
|
||||
result->y = ( vec->y + pnt1->y );
|
||||
result->z = ( vec->z + pnt1->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3ScalarMul( VmathVector3 *result, const VmathVector3 *vec, float scalar )
|
||||
{
|
||||
result->x = ( vec->x * scalar );
|
||||
result->y = ( vec->y * scalar );
|
||||
result->z = ( vec->z * scalar );
|
||||
}
|
||||
|
||||
static inline void vmathV3ScalarDiv( VmathVector3 *result, const VmathVector3 *vec, float scalar )
|
||||
{
|
||||
result->x = ( vec->x / scalar );
|
||||
result->y = ( vec->y / scalar );
|
||||
result->z = ( vec->z / scalar );
|
||||
}
|
||||
|
||||
static inline void vmathV3Neg( VmathVector3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = -vec->x;
|
||||
result->y = -vec->y;
|
||||
result->z = -vec->z;
|
||||
}
|
||||
|
||||
static inline void vmathV3MulPerElem( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x * vec1->x );
|
||||
result->y = ( vec0->y * vec1->y );
|
||||
result->z = ( vec0->z * vec1->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3DivPerElem( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x / vec1->x );
|
||||
result->y = ( vec0->y / vec1->y );
|
||||
result->z = ( vec0->z / vec1->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3RecipPerElem( VmathVector3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = ( 1.0f / vec->x );
|
||||
result->y = ( 1.0f / vec->y );
|
||||
result->z = ( 1.0f / vec->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3SqrtPerElem( VmathVector3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = sqrtf( vec->x );
|
||||
result->y = sqrtf( vec->y );
|
||||
result->z = sqrtf( vec->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3RsqrtPerElem( VmathVector3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = ( 1.0f / sqrtf( vec->x ) );
|
||||
result->y = ( 1.0f / sqrtf( vec->y ) );
|
||||
result->z = ( 1.0f / sqrtf( vec->z ) );
|
||||
}
|
||||
|
||||
static inline void vmathV3AbsPerElem( VmathVector3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = fabsf( vec->x );
|
||||
result->y = fabsf( vec->y );
|
||||
result->z = fabsf( vec->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3CopySignPerElem( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = ( vec1->x < 0.0f )? -fabsf( vec0->x ) : fabsf( vec0->x );
|
||||
result->y = ( vec1->y < 0.0f )? -fabsf( vec0->y ) : fabsf( vec0->y );
|
||||
result->z = ( vec1->z < 0.0f )? -fabsf( vec0->z ) : fabsf( vec0->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3MaxPerElem( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = (vec0->x > vec1->x)? vec0->x : vec1->x;
|
||||
result->y = (vec0->y > vec1->y)? vec0->y : vec1->y;
|
||||
result->z = (vec0->z > vec1->z)? vec0->z : vec1->z;
|
||||
}
|
||||
|
||||
static inline float vmathV3MaxElem( const VmathVector3 *vec )
|
||||
{
|
||||
float result;
|
||||
result = (vec->x > vec->y)? vec->x : vec->y;
|
||||
result = (vec->z > result)? vec->z : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathV3MinPerElem( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = (vec0->x < vec1->x)? vec0->x : vec1->x;
|
||||
result->y = (vec0->y < vec1->y)? vec0->y : vec1->y;
|
||||
result->z = (vec0->z < vec1->z)? vec0->z : vec1->z;
|
||||
}
|
||||
|
||||
static inline float vmathV3MinElem( const VmathVector3 *vec )
|
||||
{
|
||||
float result;
|
||||
result = (vec->x < vec->y)? vec->x : vec->y;
|
||||
result = (vec->z < result)? vec->z : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV3Sum( const VmathVector3 *vec )
|
||||
{
|
||||
float result;
|
||||
result = ( vec->x + vec->y );
|
||||
result = ( result + vec->z );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV3Dot( const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
float result;
|
||||
result = ( vec0->x * vec1->x );
|
||||
result = ( result + ( vec0->y * vec1->y ) );
|
||||
result = ( result + ( vec0->z * vec1->z ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV3LengthSqr( const VmathVector3 *vec )
|
||||
{
|
||||
float result;
|
||||
result = ( vec->x * vec->x );
|
||||
result = ( result + ( vec->y * vec->y ) );
|
||||
result = ( result + ( vec->z * vec->z ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV3Length( const VmathVector3 *vec )
|
||||
{
|
||||
return sqrtf( vmathV3LengthSqr( vec ) );
|
||||
}
|
||||
|
||||
static inline void vmathV3Normalize( VmathVector3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
float lenSqr, lenInv;
|
||||
lenSqr = vmathV3LengthSqr( vec );
|
||||
lenInv = ( 1.0f / sqrtf( lenSqr ) );
|
||||
result->x = ( vec->x * lenInv );
|
||||
result->y = ( vec->y * lenInv );
|
||||
result->z = ( vec->z * lenInv );
|
||||
}
|
||||
|
||||
static inline void vmathV3Cross( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1 )
|
||||
{
|
||||
float tmpX, tmpY, tmpZ;
|
||||
tmpX = ( ( vec0->y * vec1->z ) - ( vec0->z * vec1->y ) );
|
||||
tmpY = ( ( vec0->z * vec1->x ) - ( vec0->x * vec1->z ) );
|
||||
tmpZ = ( ( vec0->x * vec1->y ) - ( vec0->y * vec1->x ) );
|
||||
vmathV3MakeFromElems( result, tmpX, tmpY, tmpZ );
|
||||
}
|
||||
|
||||
static inline void vmathV3Select( VmathVector3 *result, const VmathVector3 *vec0, const VmathVector3 *vec1, unsigned int select1 )
|
||||
{
|
||||
result->x = ( select1 )? vec1->x : vec0->x;
|
||||
result->y = ( select1 )? vec1->y : vec0->y;
|
||||
result->z = ( select1 )? vec1->z : vec0->z;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathV3Print( const VmathVector3 *vec )
|
||||
{
|
||||
printf( "( %f %f %f )\n", vec->x, vec->y, vec->z );
|
||||
}
|
||||
|
||||
static inline void vmathV3Prints( const VmathVector3 *vec, const char *name )
|
||||
{
|
||||
printf( "%s: ( %f %f %f )\n", name, vec->x, vec->y, vec->z );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline void vmathV4Copy( VmathVector4 *result, const VmathVector4 *vec )
|
||||
{
|
||||
result->x = vec->x;
|
||||
result->y = vec->y;
|
||||
result->z = vec->z;
|
||||
result->w = vec->w;
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeFromElems( VmathVector4 *result, float _x, float _y, float _z, float _w )
|
||||
{
|
||||
result->x = _x;
|
||||
result->y = _y;
|
||||
result->z = _z;
|
||||
result->w = _w;
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeFromV3Scalar( VmathVector4 *result, const VmathVector3 *xyz, float _w )
|
||||
{
|
||||
vmathV4SetXYZ( result, xyz );
|
||||
vmathV4SetW( result, _w );
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeFromV3( VmathVector4 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = vec->x;
|
||||
result->y = vec->y;
|
||||
result->z = vec->z;
|
||||
result->w = 0.0f;
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeFromP3( VmathVector4 *result, const VmathPoint3 *pnt )
|
||||
{
|
||||
result->x = pnt->x;
|
||||
result->y = pnt->y;
|
||||
result->z = pnt->z;
|
||||
result->w = 1.0f;
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeFromQ( VmathVector4 *result, const VmathQuat *quat )
|
||||
{
|
||||
result->x = quat->x;
|
||||
result->y = quat->y;
|
||||
result->z = quat->z;
|
||||
result->w = quat->w;
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeFromScalar( VmathVector4 *result, float scalar )
|
||||
{
|
||||
result->x = scalar;
|
||||
result->y = scalar;
|
||||
result->z = scalar;
|
||||
result->w = scalar;
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeXAxis( VmathVector4 *result )
|
||||
{
|
||||
vmathV4MakeFromElems( result, 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeYAxis( VmathVector4 *result )
|
||||
{
|
||||
vmathV4MakeFromElems( result, 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeZAxis( VmathVector4 *result )
|
||||
{
|
||||
vmathV4MakeFromElems( result, 0.0f, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
static inline void vmathV4MakeWAxis( VmathVector4 *result )
|
||||
{
|
||||
vmathV4MakeFromElems( result, 0.0f, 0.0f, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
static inline void vmathV4Lerp( VmathVector4 *result, float t, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
VmathVector4 tmpV4_0, tmpV4_1;
|
||||
vmathV4Sub( &tmpV4_0, vec1, vec0 );
|
||||
vmathV4ScalarMul( &tmpV4_1, &tmpV4_0, t );
|
||||
vmathV4Add( result, vec0, &tmpV4_1 );
|
||||
}
|
||||
|
||||
static inline void vmathV4Slerp( VmathVector4 *result, float t, const VmathVector4 *unitVec0, const VmathVector4 *unitVec1 )
|
||||
{
|
||||
VmathVector4 tmpV4_0, tmpV4_1;
|
||||
float recipSinAngle, scale0, scale1, cosAngle, angle;
|
||||
cosAngle = vmathV4Dot( unitVec0, unitVec1 );
|
||||
if ( cosAngle < _VECTORMATH_SLERP_TOL ) {
|
||||
angle = acosf( cosAngle );
|
||||
recipSinAngle = ( 1.0f / sinf( angle ) );
|
||||
scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle );
|
||||
scale1 = ( sinf( ( t * angle ) ) * recipSinAngle );
|
||||
} else {
|
||||
scale0 = ( 1.0f - t );
|
||||
scale1 = t;
|
||||
}
|
||||
vmathV4ScalarMul( &tmpV4_0, unitVec0, scale0 );
|
||||
vmathV4ScalarMul( &tmpV4_1, unitVec1, scale1 );
|
||||
vmathV4Add( result, &tmpV4_0, &tmpV4_1 );
|
||||
}
|
||||
|
||||
static inline void vmathV4SetXYZ( VmathVector4 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = vec->x;
|
||||
result->y = vec->y;
|
||||
result->z = vec->z;
|
||||
}
|
||||
|
||||
static inline void vmathV4GetXYZ( VmathVector3 *result, const VmathVector4 *vec )
|
||||
{
|
||||
vmathV3MakeFromElems( result, vec->x, vec->y, vec->z );
|
||||
}
|
||||
|
||||
static inline void vmathV4SetX( VmathVector4 *result, float _x )
|
||||
{
|
||||
result->x = _x;
|
||||
}
|
||||
|
||||
static inline float vmathV4GetX( const VmathVector4 *vec )
|
||||
{
|
||||
return vec->x;
|
||||
}
|
||||
|
||||
static inline void vmathV4SetY( VmathVector4 *result, float _y )
|
||||
{
|
||||
result->y = _y;
|
||||
}
|
||||
|
||||
static inline float vmathV4GetY( const VmathVector4 *vec )
|
||||
{
|
||||
return vec->y;
|
||||
}
|
||||
|
||||
static inline void vmathV4SetZ( VmathVector4 *result, float _z )
|
||||
{
|
||||
result->z = _z;
|
||||
}
|
||||
|
||||
static inline float vmathV4GetZ( const VmathVector4 *vec )
|
||||
{
|
||||
return vec->z;
|
||||
}
|
||||
|
||||
static inline void vmathV4SetW( VmathVector4 *result, float _w )
|
||||
{
|
||||
result->w = _w;
|
||||
}
|
||||
|
||||
static inline float vmathV4GetW( const VmathVector4 *vec )
|
||||
{
|
||||
return vec->w;
|
||||
}
|
||||
|
||||
static inline void vmathV4SetElem( VmathVector4 *result, int idx, float value )
|
||||
{
|
||||
*(&result->x + idx) = value;
|
||||
}
|
||||
|
||||
static inline float vmathV4GetElem( const VmathVector4 *vec, int idx )
|
||||
{
|
||||
return *(&vec->x + idx);
|
||||
}
|
||||
|
||||
static inline void vmathV4Add( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x + vec1->x );
|
||||
result->y = ( vec0->y + vec1->y );
|
||||
result->z = ( vec0->z + vec1->z );
|
||||
result->w = ( vec0->w + vec1->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4Sub( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x - vec1->x );
|
||||
result->y = ( vec0->y - vec1->y );
|
||||
result->z = ( vec0->z - vec1->z );
|
||||
result->w = ( vec0->w - vec1->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4ScalarMul( VmathVector4 *result, const VmathVector4 *vec, float scalar )
|
||||
{
|
||||
result->x = ( vec->x * scalar );
|
||||
result->y = ( vec->y * scalar );
|
||||
result->z = ( vec->z * scalar );
|
||||
result->w = ( vec->w * scalar );
|
||||
}
|
||||
|
||||
static inline void vmathV4ScalarDiv( VmathVector4 *result, const VmathVector4 *vec, float scalar )
|
||||
{
|
||||
result->x = ( vec->x / scalar );
|
||||
result->y = ( vec->y / scalar );
|
||||
result->z = ( vec->z / scalar );
|
||||
result->w = ( vec->w / scalar );
|
||||
}
|
||||
|
||||
static inline void vmathV4Neg( VmathVector4 *result, const VmathVector4 *vec )
|
||||
{
|
||||
result->x = -vec->x;
|
||||
result->y = -vec->y;
|
||||
result->z = -vec->z;
|
||||
result->w = -vec->w;
|
||||
}
|
||||
|
||||
static inline void vmathV4MulPerElem( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x * vec1->x );
|
||||
result->y = ( vec0->y * vec1->y );
|
||||
result->z = ( vec0->z * vec1->z );
|
||||
result->w = ( vec0->w * vec1->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4DivPerElem( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
result->x = ( vec0->x / vec1->x );
|
||||
result->y = ( vec0->y / vec1->y );
|
||||
result->z = ( vec0->z / vec1->z );
|
||||
result->w = ( vec0->w / vec1->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4RecipPerElem( VmathVector4 *result, const VmathVector4 *vec )
|
||||
{
|
||||
result->x = ( 1.0f / vec->x );
|
||||
result->y = ( 1.0f / vec->y );
|
||||
result->z = ( 1.0f / vec->z );
|
||||
result->w = ( 1.0f / vec->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4SqrtPerElem( VmathVector4 *result, const VmathVector4 *vec )
|
||||
{
|
||||
result->x = sqrtf( vec->x );
|
||||
result->y = sqrtf( vec->y );
|
||||
result->z = sqrtf( vec->z );
|
||||
result->w = sqrtf( vec->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4RsqrtPerElem( VmathVector4 *result, const VmathVector4 *vec )
|
||||
{
|
||||
result->x = ( 1.0f / sqrtf( vec->x ) );
|
||||
result->y = ( 1.0f / sqrtf( vec->y ) );
|
||||
result->z = ( 1.0f / sqrtf( vec->z ) );
|
||||
result->w = ( 1.0f / sqrtf( vec->w ) );
|
||||
}
|
||||
|
||||
static inline void vmathV4AbsPerElem( VmathVector4 *result, const VmathVector4 *vec )
|
||||
{
|
||||
result->x = fabsf( vec->x );
|
||||
result->y = fabsf( vec->y );
|
||||
result->z = fabsf( vec->z );
|
||||
result->w = fabsf( vec->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4CopySignPerElem( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
result->x = ( vec1->x < 0.0f )? -fabsf( vec0->x ) : fabsf( vec0->x );
|
||||
result->y = ( vec1->y < 0.0f )? -fabsf( vec0->y ) : fabsf( vec0->y );
|
||||
result->z = ( vec1->z < 0.0f )? -fabsf( vec0->z ) : fabsf( vec0->z );
|
||||
result->w = ( vec1->w < 0.0f )? -fabsf( vec0->w ) : fabsf( vec0->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4MaxPerElem( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
result->x = (vec0->x > vec1->x)? vec0->x : vec1->x;
|
||||
result->y = (vec0->y > vec1->y)? vec0->y : vec1->y;
|
||||
result->z = (vec0->z > vec1->z)? vec0->z : vec1->z;
|
||||
result->w = (vec0->w > vec1->w)? vec0->w : vec1->w;
|
||||
}
|
||||
|
||||
static inline float vmathV4MaxElem( const VmathVector4 *vec )
|
||||
{
|
||||
float result;
|
||||
result = (vec->x > vec->y)? vec->x : vec->y;
|
||||
result = (vec->z > result)? vec->z : result;
|
||||
result = (vec->w > result)? vec->w : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathV4MinPerElem( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
result->x = (vec0->x < vec1->x)? vec0->x : vec1->x;
|
||||
result->y = (vec0->y < vec1->y)? vec0->y : vec1->y;
|
||||
result->z = (vec0->z < vec1->z)? vec0->z : vec1->z;
|
||||
result->w = (vec0->w < vec1->w)? vec0->w : vec1->w;
|
||||
}
|
||||
|
||||
static inline float vmathV4MinElem( const VmathVector4 *vec )
|
||||
{
|
||||
float result;
|
||||
result = (vec->x < vec->y)? vec->x : vec->y;
|
||||
result = (vec->z < result)? vec->z : result;
|
||||
result = (vec->w < result)? vec->w : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV4Sum( const VmathVector4 *vec )
|
||||
{
|
||||
float result;
|
||||
result = ( vec->x + vec->y );
|
||||
result = ( result + vec->z );
|
||||
result = ( result + vec->w );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV4Dot( const VmathVector4 *vec0, const VmathVector4 *vec1 )
|
||||
{
|
||||
float result;
|
||||
result = ( vec0->x * vec1->x );
|
||||
result = ( result + ( vec0->y * vec1->y ) );
|
||||
result = ( result + ( vec0->z * vec1->z ) );
|
||||
result = ( result + ( vec0->w * vec1->w ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV4LengthSqr( const VmathVector4 *vec )
|
||||
{
|
||||
float result;
|
||||
result = ( vec->x * vec->x );
|
||||
result = ( result + ( vec->y * vec->y ) );
|
||||
result = ( result + ( vec->z * vec->z ) );
|
||||
result = ( result + ( vec->w * vec->w ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV4Length( const VmathVector4 *vec )
|
||||
{
|
||||
return sqrtf( vmathV4LengthSqr( vec ) );
|
||||
}
|
||||
|
||||
static inline void vmathV4Normalize( VmathVector4 *result, const VmathVector4 *vec )
|
||||
{
|
||||
float lenSqr, lenInv;
|
||||
lenSqr = vmathV4LengthSqr( vec );
|
||||
lenInv = ( 1.0f / sqrtf( lenSqr ) );
|
||||
result->x = ( vec->x * lenInv );
|
||||
result->y = ( vec->y * lenInv );
|
||||
result->z = ( vec->z * lenInv );
|
||||
result->w = ( vec->w * lenInv );
|
||||
}
|
||||
|
||||
static inline void vmathV4Select( VmathVector4 *result, const VmathVector4 *vec0, const VmathVector4 *vec1, unsigned int select1 )
|
||||
{
|
||||
result->x = ( select1 )? vec1->x : vec0->x;
|
||||
result->y = ( select1 )? vec1->y : vec0->y;
|
||||
result->z = ( select1 )? vec1->z : vec0->z;
|
||||
result->w = ( select1 )? vec1->w : vec0->w;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathV4Print( const VmathVector4 *vec )
|
||||
{
|
||||
printf( "( %f %f %f %f )\n", vec->x, vec->y, vec->z, vec->w );
|
||||
}
|
||||
|
||||
static inline void vmathV4Prints( const VmathVector4 *vec, const char *name )
|
||||
{
|
||||
printf( "%s: ( %f %f %f %f )\n", name, vec->x, vec->y, vec->z, vec->w );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline void vmathP3Copy( VmathPoint3 *result, const VmathPoint3 *pnt )
|
||||
{
|
||||
result->x = pnt->x;
|
||||
result->y = pnt->y;
|
||||
result->z = pnt->z;
|
||||
}
|
||||
|
||||
static inline void vmathP3MakeFromElems( VmathPoint3 *result, float _x, float _y, float _z )
|
||||
{
|
||||
result->x = _x;
|
||||
result->y = _y;
|
||||
result->z = _z;
|
||||
}
|
||||
|
||||
static inline void vmathP3MakeFromV3( VmathPoint3 *result, const VmathVector3 *vec )
|
||||
{
|
||||
result->x = vec->x;
|
||||
result->y = vec->y;
|
||||
result->z = vec->z;
|
||||
}
|
||||
|
||||
static inline void vmathP3MakeFromScalar( VmathPoint3 *result, float scalar )
|
||||
{
|
||||
result->x = scalar;
|
||||
result->y = scalar;
|
||||
result->z = scalar;
|
||||
}
|
||||
|
||||
static inline void vmathP3Lerp( VmathPoint3 *result, float t, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
VmathVector3 tmpV3_0, tmpV3_1;
|
||||
vmathP3Sub( &tmpV3_0, pnt1, pnt0 );
|
||||
vmathV3ScalarMul( &tmpV3_1, &tmpV3_0, t );
|
||||
vmathP3AddV3( result, pnt0, &tmpV3_1 );
|
||||
}
|
||||
|
||||
static inline void vmathP3SetX( VmathPoint3 *result, float _x )
|
||||
{
|
||||
result->x = _x;
|
||||
}
|
||||
|
||||
static inline float vmathP3GetX( const VmathPoint3 *pnt )
|
||||
{
|
||||
return pnt->x;
|
||||
}
|
||||
|
||||
static inline void vmathP3SetY( VmathPoint3 *result, float _y )
|
||||
{
|
||||
result->y = _y;
|
||||
}
|
||||
|
||||
static inline float vmathP3GetY( const VmathPoint3 *pnt )
|
||||
{
|
||||
return pnt->y;
|
||||
}
|
||||
|
||||
static inline void vmathP3SetZ( VmathPoint3 *result, float _z )
|
||||
{
|
||||
result->z = _z;
|
||||
}
|
||||
|
||||
static inline float vmathP3GetZ( const VmathPoint3 *pnt )
|
||||
{
|
||||
return pnt->z;
|
||||
}
|
||||
|
||||
static inline void vmathP3SetElem( VmathPoint3 *result, int idx, float value )
|
||||
{
|
||||
*(&result->x + idx) = value;
|
||||
}
|
||||
|
||||
static inline float vmathP3GetElem( const VmathPoint3 *pnt, int idx )
|
||||
{
|
||||
return *(&pnt->x + idx);
|
||||
}
|
||||
|
||||
static inline void vmathP3Sub( VmathVector3 *result, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
result->x = ( pnt0->x - pnt1->x );
|
||||
result->y = ( pnt0->y - pnt1->y );
|
||||
result->z = ( pnt0->z - pnt1->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3AddV3( VmathPoint3 *result, const VmathPoint3 *pnt, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = ( pnt->x + vec1->x );
|
||||
result->y = ( pnt->y + vec1->y );
|
||||
result->z = ( pnt->z + vec1->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3SubV3( VmathPoint3 *result, const VmathPoint3 *pnt, const VmathVector3 *vec1 )
|
||||
{
|
||||
result->x = ( pnt->x - vec1->x );
|
||||
result->y = ( pnt->y - vec1->y );
|
||||
result->z = ( pnt->z - vec1->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3MulPerElem( VmathPoint3 *result, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
result->x = ( pnt0->x * pnt1->x );
|
||||
result->y = ( pnt0->y * pnt1->y );
|
||||
result->z = ( pnt0->z * pnt1->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3DivPerElem( VmathPoint3 *result, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
result->x = ( pnt0->x / pnt1->x );
|
||||
result->y = ( pnt0->y / pnt1->y );
|
||||
result->z = ( pnt0->z / pnt1->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3RecipPerElem( VmathPoint3 *result, const VmathPoint3 *pnt )
|
||||
{
|
||||
result->x = ( 1.0f / pnt->x );
|
||||
result->y = ( 1.0f / pnt->y );
|
||||
result->z = ( 1.0f / pnt->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3SqrtPerElem( VmathPoint3 *result, const VmathPoint3 *pnt )
|
||||
{
|
||||
result->x = sqrtf( pnt->x );
|
||||
result->y = sqrtf( pnt->y );
|
||||
result->z = sqrtf( pnt->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3RsqrtPerElem( VmathPoint3 *result, const VmathPoint3 *pnt )
|
||||
{
|
||||
result->x = ( 1.0f / sqrtf( pnt->x ) );
|
||||
result->y = ( 1.0f / sqrtf( pnt->y ) );
|
||||
result->z = ( 1.0f / sqrtf( pnt->z ) );
|
||||
}
|
||||
|
||||
static inline void vmathP3AbsPerElem( VmathPoint3 *result, const VmathPoint3 *pnt )
|
||||
{
|
||||
result->x = fabsf( pnt->x );
|
||||
result->y = fabsf( pnt->y );
|
||||
result->z = fabsf( pnt->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3CopySignPerElem( VmathPoint3 *result, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
result->x = ( pnt1->x < 0.0f )? -fabsf( pnt0->x ) : fabsf( pnt0->x );
|
||||
result->y = ( pnt1->y < 0.0f )? -fabsf( pnt0->y ) : fabsf( pnt0->y );
|
||||
result->z = ( pnt1->z < 0.0f )? -fabsf( pnt0->z ) : fabsf( pnt0->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3MaxPerElem( VmathPoint3 *result, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
result->x = (pnt0->x > pnt1->x)? pnt0->x : pnt1->x;
|
||||
result->y = (pnt0->y > pnt1->y)? pnt0->y : pnt1->y;
|
||||
result->z = (pnt0->z > pnt1->z)? pnt0->z : pnt1->z;
|
||||
}
|
||||
|
||||
static inline float vmathP3MaxElem( const VmathPoint3 *pnt )
|
||||
{
|
||||
float result;
|
||||
result = (pnt->x > pnt->y)? pnt->x : pnt->y;
|
||||
result = (pnt->z > result)? pnt->z : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathP3MinPerElem( VmathPoint3 *result, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
result->x = (pnt0->x < pnt1->x)? pnt0->x : pnt1->x;
|
||||
result->y = (pnt0->y < pnt1->y)? pnt0->y : pnt1->y;
|
||||
result->z = (pnt0->z < pnt1->z)? pnt0->z : pnt1->z;
|
||||
}
|
||||
|
||||
static inline float vmathP3MinElem( const VmathPoint3 *pnt )
|
||||
{
|
||||
float result;
|
||||
result = (pnt->x < pnt->y)? pnt->x : pnt->y;
|
||||
result = (pnt->z < result)? pnt->z : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathP3Sum( const VmathPoint3 *pnt )
|
||||
{
|
||||
float result;
|
||||
result = ( pnt->x + pnt->y );
|
||||
result = ( result + pnt->z );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathP3Scale( VmathPoint3 *result, const VmathPoint3 *pnt, float scaleVal )
|
||||
{
|
||||
VmathPoint3 tmpP3_0;
|
||||
vmathP3MakeFromScalar( &tmpP3_0, scaleVal );
|
||||
vmathP3MulPerElem( result, pnt, &tmpP3_0 );
|
||||
}
|
||||
|
||||
static inline void vmathP3NonUniformScale( VmathPoint3 *result, const VmathPoint3 *pnt, const VmathVector3 *scaleVec )
|
||||
{
|
||||
VmathPoint3 tmpP3_0;
|
||||
vmathP3MakeFromV3( &tmpP3_0, scaleVec );
|
||||
vmathP3MulPerElem( result, pnt, &tmpP3_0 );
|
||||
}
|
||||
|
||||
static inline float vmathP3Projection( const VmathPoint3 *pnt, const VmathVector3 *unitVec )
|
||||
{
|
||||
float result;
|
||||
result = ( pnt->x * unitVec->x );
|
||||
result = ( result + ( pnt->y * unitVec->y ) );
|
||||
result = ( result + ( pnt->z * unitVec->z ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathP3DistSqrFromOrigin( const VmathPoint3 *pnt )
|
||||
{
|
||||
VmathVector3 tmpV3_0;
|
||||
vmathV3MakeFromP3( &tmpV3_0, pnt );
|
||||
return vmathV3LengthSqr( &tmpV3_0 );
|
||||
}
|
||||
|
||||
static inline float vmathP3DistFromOrigin( const VmathPoint3 *pnt )
|
||||
{
|
||||
VmathVector3 tmpV3_0;
|
||||
vmathV3MakeFromP3( &tmpV3_0, pnt );
|
||||
return vmathV3Length( &tmpV3_0 );
|
||||
}
|
||||
|
||||
static inline float vmathP3DistSqr( const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
VmathVector3 tmpV3_0;
|
||||
vmathP3Sub( &tmpV3_0, pnt1, pnt0 );
|
||||
return vmathV3LengthSqr( &tmpV3_0 );
|
||||
}
|
||||
|
||||
static inline float vmathP3Dist( const VmathPoint3 *pnt0, const VmathPoint3 *pnt1 )
|
||||
{
|
||||
VmathVector3 tmpV3_0;
|
||||
vmathP3Sub( &tmpV3_0, pnt1, pnt0 );
|
||||
return vmathV3Length( &tmpV3_0 );
|
||||
}
|
||||
|
||||
static inline void vmathP3Select( VmathPoint3 *result, const VmathPoint3 *pnt0, const VmathPoint3 *pnt1, unsigned int select1 )
|
||||
{
|
||||
result->x = ( select1 )? pnt1->x : pnt0->x;
|
||||
result->y = ( select1 )? pnt1->y : pnt0->y;
|
||||
result->z = ( select1 )? pnt1->z : pnt0->z;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathP3Print( const VmathPoint3 *pnt )
|
||||
{
|
||||
printf( "( %f %f %f )\n", pnt->x, pnt->y, pnt->z );
|
||||
}
|
||||
|
||||
static inline void vmathP3Prints( const VmathPoint3 *pnt, const char *name )
|
||||
{
|
||||
printf( "%s: ( %f %f %f )\n", name, pnt->x, pnt->y, pnt->z );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
848
Extras/vectormathlibrary/include/vectormath/scalar/c/vec_aos_v.h
Normal file
848
Extras/vectormathlibrary/include/vectormath/scalar/c/vec_aos_v.h
Normal file
@@ -0,0 +1,848 @@
|
||||
/*
|
||||
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Sony Computer Entertainment Inc nor the names
|
||||
of its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VECTORMATH_VEC_AOS_V_C_H
|
||||
#define _VECTORMATH_VEC_AOS_V_C_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Constants
|
||||
*/
|
||||
#define _VECTORMATH_SLERP_TOL 0.999f
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Definitions
|
||||
*/
|
||||
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
#define _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
|
||||
#endif
|
||||
|
||||
static inline VmathVector3 vmathV3MakeFromElems_V( float _x, float _y, float _z )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MakeFromElems(&result, _x, _y, _z);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MakeFromP3_V( VmathPoint3 pnt )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MakeFromP3(&result, &pnt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MakeFromScalar_V( float scalar )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MakeFromScalar(&result, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MakeXAxis_V( )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MakeXAxis(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MakeYAxis_V( )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MakeYAxis(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MakeZAxis_V( )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MakeZAxis(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Lerp_V( float t, VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Lerp(&result, t, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Slerp_V( float t, VmathVector3 unitVec0, VmathVector3 unitVec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Slerp(&result, t, &unitVec0, &unitVec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathV3SetX_V( VmathVector3 *result, float _x )
|
||||
{
|
||||
vmathV3SetX(result, _x);
|
||||
}
|
||||
|
||||
static inline float vmathV3GetX_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3GetX(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV3SetY_V( VmathVector3 *result, float _y )
|
||||
{
|
||||
vmathV3SetY(result, _y);
|
||||
}
|
||||
|
||||
static inline float vmathV3GetY_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3GetY(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV3SetZ_V( VmathVector3 *result, float _z )
|
||||
{
|
||||
vmathV3SetZ(result, _z);
|
||||
}
|
||||
|
||||
static inline float vmathV3GetZ_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3GetZ(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV3SetElem_V( VmathVector3 *result, int idx, float value )
|
||||
{
|
||||
vmathV3SetElem(result, idx, value);
|
||||
}
|
||||
|
||||
static inline float vmathV3GetElem_V( VmathVector3 vec, int idx )
|
||||
{
|
||||
return vmathV3GetElem(&vec, idx);
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Add_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Add(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Sub_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Sub(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathV3AddP3_V( VmathVector3 vec, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathV3AddP3(&result, &vec, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3ScalarMul_V( VmathVector3 vec, float scalar )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3ScalarMul(&result, &vec, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3ScalarDiv_V( VmathVector3 vec, float scalar )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3ScalarDiv(&result, &vec, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Neg_V( VmathVector3 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Neg(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MulPerElem_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MulPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3DivPerElem_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3DivPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3RecipPerElem_V( VmathVector3 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3RecipPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3SqrtPerElem_V( VmathVector3 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3SqrtPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3RsqrtPerElem_V( VmathVector3 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3RsqrtPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3AbsPerElem_V( VmathVector3 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3AbsPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3CopySignPerElem_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3CopySignPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MaxPerElem_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MaxPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV3MaxElem_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3MaxElem(&vec);
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3MinPerElem_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3MinPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV3MinElem_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3MinElem(&vec);
|
||||
}
|
||||
|
||||
static inline float vmathV3Sum_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3Sum(&vec);
|
||||
}
|
||||
|
||||
static inline float vmathV3Dot_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
return vmathV3Dot(&vec0, &vec1);
|
||||
}
|
||||
|
||||
static inline float vmathV3LengthSqr_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3LengthSqr(&vec);
|
||||
}
|
||||
|
||||
static inline float vmathV3Length_V( VmathVector3 vec )
|
||||
{
|
||||
return vmathV3Length(&vec);
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Normalize_V( VmathVector3 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Normalize(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Cross_V( VmathVector3 vec0, VmathVector3 vec1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Cross(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV3Select_V( VmathVector3 vec0, VmathVector3 vec1, unsigned int select1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV3Select(&result, &vec0, &vec1, select1);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathV3Print_V( VmathVector3 vec )
|
||||
{
|
||||
vmathV3Print(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV3Prints_V( VmathVector3 vec, const char *name )
|
||||
{
|
||||
vmathV3Prints(&vec, name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline VmathVector4 vmathV4MakeFromElems_V( float _x, float _y, float _z, float _w )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeFromElems(&result, _x, _y, _z, _w);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeFromV3Scalar_V( VmathVector3 xyz, float _w )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeFromV3Scalar(&result, &xyz, _w);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeFromV3_V( VmathVector3 vec )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeFromV3(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeFromP3_V( VmathPoint3 pnt )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeFromP3(&result, &pnt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeFromQ_V( VmathQuat quat )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeFromQ(&result, &quat);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeFromScalar_V( float scalar )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeFromScalar(&result, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeXAxis_V( )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeXAxis(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeYAxis_V( )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeYAxis(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeZAxis_V( )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeZAxis(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MakeWAxis_V( )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MakeWAxis(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4Lerp_V( float t, VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4Lerp(&result, t, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4Slerp_V( float t, VmathVector4 unitVec0, VmathVector4 unitVec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4Slerp(&result, t, &unitVec0, &unitVec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathV4SetXYZ_V( VmathVector4 *result, VmathVector3 vec )
|
||||
{
|
||||
vmathV4SetXYZ(result, &vec);
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathV4GetXYZ_V( VmathVector4 vec )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathV4GetXYZ(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathV4SetX_V( VmathVector4 *result, float _x )
|
||||
{
|
||||
vmathV4SetX(result, _x);
|
||||
}
|
||||
|
||||
static inline float vmathV4GetX_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4GetX(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV4SetY_V( VmathVector4 *result, float _y )
|
||||
{
|
||||
vmathV4SetY(result, _y);
|
||||
}
|
||||
|
||||
static inline float vmathV4GetY_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4GetY(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV4SetZ_V( VmathVector4 *result, float _z )
|
||||
{
|
||||
vmathV4SetZ(result, _z);
|
||||
}
|
||||
|
||||
static inline float vmathV4GetZ_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4GetZ(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV4SetW_V( VmathVector4 *result, float _w )
|
||||
{
|
||||
vmathV4SetW(result, _w);
|
||||
}
|
||||
|
||||
static inline float vmathV4GetW_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4GetW(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV4SetElem_V( VmathVector4 *result, int idx, float value )
|
||||
{
|
||||
vmathV4SetElem(result, idx, value);
|
||||
}
|
||||
|
||||
static inline float vmathV4GetElem_V( VmathVector4 vec, int idx )
|
||||
{
|
||||
return vmathV4GetElem(&vec, idx);
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4Add_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4Add(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4Sub_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4Sub(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4ScalarMul_V( VmathVector4 vec, float scalar )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4ScalarMul(&result, &vec, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4ScalarDiv_V( VmathVector4 vec, float scalar )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4ScalarDiv(&result, &vec, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4Neg_V( VmathVector4 vec )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4Neg(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MulPerElem_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MulPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4DivPerElem_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4DivPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4RecipPerElem_V( VmathVector4 vec )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4RecipPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4SqrtPerElem_V( VmathVector4 vec )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4SqrtPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4RsqrtPerElem_V( VmathVector4 vec )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4RsqrtPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4AbsPerElem_V( VmathVector4 vec )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4AbsPerElem(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4CopySignPerElem_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4CopySignPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MaxPerElem_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MaxPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV4MaxElem_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4MaxElem(&vec);
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4MinPerElem_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4MinPerElem(&result, &vec0, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathV4MinElem_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4MinElem(&vec);
|
||||
}
|
||||
|
||||
static inline float vmathV4Sum_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4Sum(&vec);
|
||||
}
|
||||
|
||||
static inline float vmathV4Dot_V( VmathVector4 vec0, VmathVector4 vec1 )
|
||||
{
|
||||
return vmathV4Dot(&vec0, &vec1);
|
||||
}
|
||||
|
||||
static inline float vmathV4LengthSqr_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4LengthSqr(&vec);
|
||||
}
|
||||
|
||||
static inline float vmathV4Length_V( VmathVector4 vec )
|
||||
{
|
||||
return vmathV4Length(&vec);
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4Normalize_V( VmathVector4 vec )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4Normalize(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathVector4 vmathV4Select_V( VmathVector4 vec0, VmathVector4 vec1, unsigned int select1 )
|
||||
{
|
||||
VmathVector4 result;
|
||||
vmathV4Select(&result, &vec0, &vec1, select1);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathV4Print_V( VmathVector4 vec )
|
||||
{
|
||||
vmathV4Print(&vec);
|
||||
}
|
||||
|
||||
static inline void vmathV4Prints_V( VmathVector4 vec, const char *name )
|
||||
{
|
||||
vmathV4Prints(&vec, name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline VmathPoint3 vmathP3MakeFromElems_V( float _x, float _y, float _z )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3MakeFromElems(&result, _x, _y, _z);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3MakeFromV3_V( VmathVector3 vec )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3MakeFromV3(&result, &vec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3MakeFromScalar_V( float scalar )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3MakeFromScalar(&result, scalar);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3Lerp_V( float t, VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3Lerp(&result, t, &pnt0, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void vmathP3SetX_V( VmathPoint3 *result, float _x )
|
||||
{
|
||||
vmathP3SetX(result, _x);
|
||||
}
|
||||
|
||||
static inline float vmathP3GetX_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3GetX(&pnt);
|
||||
}
|
||||
|
||||
static inline void vmathP3SetY_V( VmathPoint3 *result, float _y )
|
||||
{
|
||||
vmathP3SetY(result, _y);
|
||||
}
|
||||
|
||||
static inline float vmathP3GetY_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3GetY(&pnt);
|
||||
}
|
||||
|
||||
static inline void vmathP3SetZ_V( VmathPoint3 *result, float _z )
|
||||
{
|
||||
vmathP3SetZ(result, _z);
|
||||
}
|
||||
|
||||
static inline float vmathP3GetZ_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3GetZ(&pnt);
|
||||
}
|
||||
|
||||
static inline void vmathP3SetElem_V( VmathPoint3 *result, int idx, float value )
|
||||
{
|
||||
vmathP3SetElem(result, idx, value);
|
||||
}
|
||||
|
||||
static inline float vmathP3GetElem_V( VmathPoint3 pnt, int idx )
|
||||
{
|
||||
return vmathP3GetElem(&pnt, idx);
|
||||
}
|
||||
|
||||
static inline VmathVector3 vmathP3Sub_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathVector3 result;
|
||||
vmathP3Sub(&result, &pnt0, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3AddV3_V( VmathPoint3 pnt, VmathVector3 vec1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3AddV3(&result, &pnt, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3SubV3_V( VmathPoint3 pnt, VmathVector3 vec1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3SubV3(&result, &pnt, &vec1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3MulPerElem_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3MulPerElem(&result, &pnt0, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3DivPerElem_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3DivPerElem(&result, &pnt0, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3RecipPerElem_V( VmathPoint3 pnt )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3RecipPerElem(&result, &pnt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3SqrtPerElem_V( VmathPoint3 pnt )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3SqrtPerElem(&result, &pnt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3RsqrtPerElem_V( VmathPoint3 pnt )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3RsqrtPerElem(&result, &pnt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3AbsPerElem_V( VmathPoint3 pnt )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3AbsPerElem(&result, &pnt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3CopySignPerElem_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3CopySignPerElem(&result, &pnt0, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3MaxPerElem_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3MaxPerElem(&result, &pnt0, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathP3MaxElem_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3MaxElem(&pnt);
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3MinPerElem_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3MinPerElem(&result, &pnt0, &pnt1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathP3MinElem_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3MinElem(&pnt);
|
||||
}
|
||||
|
||||
static inline float vmathP3Sum_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3Sum(&pnt);
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3Scale_V( VmathPoint3 pnt, float scaleVal )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3Scale(&result, &pnt, scaleVal);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3NonUniformScale_V( VmathPoint3 pnt, VmathVector3 scaleVec )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3NonUniformScale(&result, &pnt, &scaleVec);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline float vmathP3Projection_V( VmathPoint3 pnt, VmathVector3 unitVec )
|
||||
{
|
||||
return vmathP3Projection(&pnt, &unitVec);
|
||||
}
|
||||
|
||||
static inline float vmathP3DistSqrFromOrigin_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3DistSqrFromOrigin(&pnt);
|
||||
}
|
||||
|
||||
static inline float vmathP3DistFromOrigin_V( VmathPoint3 pnt )
|
||||
{
|
||||
return vmathP3DistFromOrigin(&pnt);
|
||||
}
|
||||
|
||||
static inline float vmathP3DistSqr_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
return vmathP3DistSqr(&pnt0, &pnt1);
|
||||
}
|
||||
|
||||
static inline float vmathP3Dist_V( VmathPoint3 pnt0, VmathPoint3 pnt1 )
|
||||
{
|
||||
return vmathP3Dist(&pnt0, &pnt1);
|
||||
}
|
||||
|
||||
static inline VmathPoint3 vmathP3Select_V( VmathPoint3 pnt0, VmathPoint3 pnt1, unsigned int select1 )
|
||||
{
|
||||
VmathPoint3 result;
|
||||
vmathP3Select(&result, &pnt0, &pnt1, select1);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
static inline void vmathP3Print_V( VmathPoint3 pnt )
|
||||
{
|
||||
vmathP3Print(&pnt);
|
||||
}
|
||||
|
||||
static inline void vmathP3Prints_V( VmathPoint3 pnt, const char *name )
|
||||
{
|
||||
vmathP3Prints(&pnt, name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1643
Extras/vectormathlibrary/include/vectormath/scalar/cpp/mat_aos.h
Normal file
1643
Extras/vectormathlibrary/include/vectormath/scalar/cpp/mat_aos.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Sony Computer Entertainment Inc nor the names
|
||||
of its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VECTORMATH_QUAT_AOS_CPP_H
|
||||
#define _VECTORMATH_QUAT_AOS_CPP_H
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
|
||||
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
#define _VECTORMATH_INTERNAL_FUNCTIONS
|
||||
|
||||
#endif
|
||||
|
||||
namespace Vectormath {
|
||||
namespace Aos {
|
||||
|
||||
inline Quat::Quat( const Quat & quat )
|
||||
{
|
||||
mX = quat.mX;
|
||||
mY = quat.mY;
|
||||
mZ = quat.mZ;
|
||||
mW = quat.mW;
|
||||
}
|
||||
|
||||
inline Quat::Quat( float _x, float _y, float _z, float _w )
|
||||
{
|
||||
mX = _x;
|
||||
mY = _y;
|
||||
mZ = _z;
|
||||
mW = _w;
|
||||
}
|
||||
|
||||
inline Quat::Quat( const Vector3 & xyz, float _w )
|
||||
{
|
||||
this->setXYZ( xyz );
|
||||
this->setW( _w );
|
||||
}
|
||||
|
||||
inline Quat::Quat( const Vector4 & vec )
|
||||
{
|
||||
mX = vec.getX();
|
||||
mY = vec.getY();
|
||||
mZ = vec.getZ();
|
||||
mW = vec.getW();
|
||||
}
|
||||
|
||||
inline Quat::Quat( float scalar )
|
||||
{
|
||||
mX = scalar;
|
||||
mY = scalar;
|
||||
mZ = scalar;
|
||||
mW = scalar;
|
||||
}
|
||||
|
||||
inline const Quat Quat::identity( )
|
||||
{
|
||||
return Quat( 0.0f, 0.0f, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
inline const Quat lerp( float t, const Quat & quat0, const Quat & quat1 )
|
||||
{
|
||||
return ( quat0 + ( ( quat1 - quat0 ) * t ) );
|
||||
}
|
||||
|
||||
inline const Quat slerp( float t, const Quat & unitQuat0, const Quat & unitQuat1 )
|
||||
{
|
||||
Quat start;
|
||||
float recipSinAngle, scale0, scale1, cosAngle, angle;
|
||||
cosAngle = dot( unitQuat0, unitQuat1 );
|
||||
if ( cosAngle < 0.0f ) {
|
||||
cosAngle = -cosAngle;
|
||||
start = ( -unitQuat0 );
|
||||
} else {
|
||||
start = unitQuat0;
|
||||
}
|
||||
if ( cosAngle < _VECTORMATH_SLERP_TOL ) {
|
||||
angle = acosf( cosAngle );
|
||||
recipSinAngle = ( 1.0f / sinf( angle ) );
|
||||
scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle );
|
||||
scale1 = ( sinf( ( t * angle ) ) * recipSinAngle );
|
||||
} else {
|
||||
scale0 = ( 1.0f - t );
|
||||
scale1 = t;
|
||||
}
|
||||
return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) );
|
||||
}
|
||||
|
||||
inline const Quat squad( float t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 )
|
||||
{
|
||||
Quat tmp0, tmp1;
|
||||
tmp0 = slerp( t, unitQuat0, unitQuat3 );
|
||||
tmp1 = slerp( t, unitQuat1, unitQuat2 );
|
||||
return slerp( ( ( 2.0f * t ) * ( 1.0f - t ) ), tmp0, tmp1 );
|
||||
}
|
||||
|
||||
inline Quat & Quat::operator =( const Quat & quat )
|
||||
{
|
||||
mX = quat.mX;
|
||||
mY = quat.mY;
|
||||
mZ = quat.mZ;
|
||||
mW = quat.mW;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Quat & Quat::setXYZ( const Vector3 & vec )
|
||||
{
|
||||
mX = vec.getX();
|
||||
mY = vec.getY();
|
||||
mZ = vec.getZ();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const Vector3 Quat::getXYZ( ) const
|
||||
{
|
||||
return Vector3( mX, mY, mZ );
|
||||
}
|
||||
|
||||
inline Quat & Quat::setX( float _x )
|
||||
{
|
||||
mX = _x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline float Quat::getX( ) const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
inline Quat & Quat::setY( float _y )
|
||||
{
|
||||
mY = _y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline float Quat::getY( ) const
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
|
||||
inline Quat & Quat::setZ( float _z )
|
||||
{
|
||||
mZ = _z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline float Quat::getZ( ) const
|
||||
{
|
||||
return mZ;
|
||||
}
|
||||
|
||||
inline Quat & Quat::setW( float _w )
|
||||
{
|
||||
mW = _w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline float Quat::getW( ) const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
inline Quat & Quat::setElem( int idx, float value )
|
||||
{
|
||||
*(&mX + idx) = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline float Quat::getElem( int idx ) const
|
||||
{
|
||||
return *(&mX + idx);
|
||||
}
|
||||
|
||||
inline float & Quat::operator []( int idx )
|
||||
{
|
||||
return *(&mX + idx);
|
||||
}
|
||||
|
||||
inline float Quat::operator []( int idx ) const
|
||||
{
|
||||
return *(&mX + idx);
|
||||
}
|
||||
|
||||
inline const Quat Quat::operator +( const Quat & quat ) const
|
||||
{
|
||||
return Quat(
|
||||
( mX + quat.mX ),
|
||||
( mY + quat.mY ),
|
||||
( mZ + quat.mZ ),
|
||||
( mW + quat.mW )
|
||||
);
|
||||
}
|
||||
|
||||
inline const Quat Quat::operator -( const Quat & quat ) const
|
||||
{
|
||||
return Quat(
|
||||
( mX - quat.mX ),
|
||||
( mY - quat.mY ),
|
||||
( mZ - quat.mZ ),
|
||||
( mW - quat.mW )
|
||||
);
|
||||
}
|
||||
|
||||
inline const Quat Quat::operator *( float scalar ) const
|
||||
{
|
||||
return Quat(
|
||||
( mX * scalar ),
|
||||
( mY * scalar ),
|
||||
( mZ * scalar ),
|
||||
( mW * scalar )
|
||||
);
|
||||
}
|
||||
|
||||
inline Quat & Quat::operator +=( const Quat & quat )
|
||||
{
|
||||
*this = *this + quat;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Quat & Quat::operator -=( const Quat & quat )
|
||||
{
|
||||
*this = *this - quat;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Quat & Quat::operator *=( float scalar )
|
||||
{
|
||||
*this = *this * scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const Quat Quat::operator /( float scalar ) const
|
||||
{
|
||||
return Quat(
|
||||
( mX / scalar ),
|
||||
( mY / scalar ),
|
||||
( mZ / scalar ),
|
||||
( mW / scalar )
|
||||
);
|
||||
}
|
||||
|
||||
inline Quat & Quat::operator /=( float scalar )
|
||||
{
|
||||
*this = *this / scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const Quat Quat::operator -( ) const
|
||||
{
|
||||
return Quat(
|
||||
-mX,
|
||||
-mY,
|
||||
-mZ,
|
||||
-mW
|
||||
);
|
||||
}
|
||||
|
||||
inline const Quat operator *( float scalar, const Quat & quat )
|
||||
{
|
||||
return quat * scalar;
|
||||
}
|
||||
|
||||
inline float dot( const Quat & quat0, const Quat & quat1 )
|
||||
{
|
||||
float result;
|
||||
result = ( quat0.getX() * quat1.getX() );
|
||||
result = ( result + ( quat0.getY() * quat1.getY() ) );
|
||||
result = ( result + ( quat0.getZ() * quat1.getZ() ) );
|
||||
result = ( result + ( quat0.getW() * quat1.getW() ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline float norm( const Quat & quat )
|
||||
{
|
||||
float result;
|
||||
result = ( quat.getX() * quat.getX() );
|
||||
result = ( result + ( quat.getY() * quat.getY() ) );
|
||||
result = ( result + ( quat.getZ() * quat.getZ() ) );
|
||||
result = ( result + ( quat.getW() * quat.getW() ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline float length( const Quat & quat )
|
||||
{
|
||||
return sqrtf( norm( quat ) );
|
||||
}
|
||||
|
||||
inline const Quat normalize( const Quat & quat )
|
||||
{
|
||||
float lenSqr, lenInv;
|
||||
lenSqr = norm( quat );
|
||||
lenInv = ( 1.0f / sqrtf( lenSqr ) );
|
||||
return Quat(
|
||||
( quat.getX() * lenInv ),
|
||||
( quat.getY() * lenInv ),
|
||||
( quat.getZ() * lenInv ),
|
||||
( quat.getW() * lenInv )
|
||||
);
|
||||
}
|
||||
|
||||
inline const Quat Quat::rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 )
|
||||
{
|
||||
float cosHalfAngleX2, recipCosHalfAngleX2;
|
||||
cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f + dot( unitVec0, unitVec1 ) ) ) );
|
||||
recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 );
|
||||
return Quat( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), ( cosHalfAngleX2 * 0.5f ) );
|
||||
}
|
||||
|
||||
inline const Quat Quat::rotation( float radians, const Vector3 & unitVec )
|
||||
{
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
return Quat( ( unitVec * s ), c );
|
||||
}
|
||||
|
||||
inline const Quat Quat::rotationX( float radians )
|
||||
{
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
return Quat( s, 0.0f, 0.0f, c );
|
||||
}
|
||||
|
||||
inline const Quat Quat::rotationY( float radians )
|
||||
{
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
return Quat( 0.0f, s, 0.0f, c );
|
||||
}
|
||||
|
||||
inline const Quat Quat::rotationZ( float radians )
|
||||
{
|
||||
float s, c, angle;
|
||||
angle = ( radians * 0.5f );
|
||||
s = sinf( angle );
|
||||
c = cosf( angle );
|
||||
return Quat( 0.0f, 0.0f, s, c );
|
||||
}
|
||||
|
||||
inline const Quat Quat::operator *( const Quat & quat ) const
|
||||
{
|
||||
return Quat(
|
||||
( ( ( ( mW * quat.mX ) + ( mX * quat.mW ) ) + ( mY * quat.mZ ) ) - ( mZ * quat.mY ) ),
|
||||
( ( ( ( mW * quat.mY ) + ( mY * quat.mW ) ) + ( mZ * quat.mX ) ) - ( mX * quat.mZ ) ),
|
||||
( ( ( ( mW * quat.mZ ) + ( mZ * quat.mW ) ) + ( mX * quat.mY ) ) - ( mY * quat.mX ) ),
|
||||
( ( ( ( mW * quat.mW ) - ( mX * quat.mX ) ) - ( mY * quat.mY ) ) - ( mZ * quat.mZ ) )
|
||||
);
|
||||
}
|
||||
|
||||
inline Quat & Quat::operator *=( const Quat & quat )
|
||||
{
|
||||
*this = *this * quat;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const Vector3 rotate( const Quat & quat, const Vector3 & vec )
|
||||
{
|
||||
float tmpX, tmpY, tmpZ, tmpW;
|
||||
tmpX = ( ( ( quat.getW() * vec.getX() ) + ( quat.getY() * vec.getZ() ) ) - ( quat.getZ() * vec.getY() ) );
|
||||
tmpY = ( ( ( quat.getW() * vec.getY() ) + ( quat.getZ() * vec.getX() ) ) - ( quat.getX() * vec.getZ() ) );
|
||||
tmpZ = ( ( ( quat.getW() * vec.getZ() ) + ( quat.getX() * vec.getY() ) ) - ( quat.getY() * vec.getX() ) );
|
||||
tmpW = ( ( ( quat.getX() * vec.getX() ) + ( quat.getY() * vec.getY() ) ) + ( quat.getZ() * vec.getZ() ) );
|
||||
return Vector3(
|
||||
( ( ( ( tmpW * quat.getX() ) + ( tmpX * quat.getW() ) ) - ( tmpY * quat.getZ() ) ) + ( tmpZ * quat.getY() ) ),
|
||||
( ( ( ( tmpW * quat.getY() ) + ( tmpY * quat.getW() ) ) - ( tmpZ * quat.getX() ) ) + ( tmpX * quat.getZ() ) ),
|
||||
( ( ( ( tmpW * quat.getZ() ) + ( tmpZ * quat.getW() ) ) - ( tmpX * quat.getY() ) ) + ( tmpY * quat.getX() ) )
|
||||
);
|
||||
}
|
||||
|
||||
inline const Quat conj( const Quat & quat )
|
||||
{
|
||||
return Quat( -quat.getX(), -quat.getY(), -quat.getZ(), quat.getW() );
|
||||
}
|
||||
|
||||
inline const Quat select( const Quat & quat0, const Quat & quat1, bool select1 )
|
||||
{
|
||||
return Quat(
|
||||
( select1 )? quat1.getX() : quat0.getX(),
|
||||
( select1 )? quat1.getY() : quat0.getY(),
|
||||
( select1 )? quat1.getZ() : quat0.getZ(),
|
||||
( select1 )? quat1.getW() : quat0.getW()
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef _VECTORMATH_DEBUG
|
||||
|
||||
inline void print( const Quat & quat )
|
||||
{
|
||||
printf( "( %f %f %f %f )\n", quat.getX(), quat.getY(), quat.getZ(), quat.getW() );
|
||||
}
|
||||
|
||||
inline void print( const Quat & quat, const char * name )
|
||||
{
|
||||
printf( "%s: ( %f %f %f %f )\n", name, quat.getX(), quat.getY(), quat.getZ(), quat.getW() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace Aos
|
||||
} // namespace Vectormath
|
||||
|
||||
#endif
|
||||
1173
Extras/vectormathlibrary/include/vectormath/scalar/cpp/vec_aos.h
Normal file
1173
Extras/vectormathlibrary/include/vectormath/scalar/cpp/vec_aos.h
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user