add regular RageQuatFromHPR and simple AABB functions
This commit is contained in:
+52
-19
@@ -19,6 +19,22 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "arch/ArchHooks/ArchHooks.h"
|
#include "arch/ArchHooks/ArchHooks.h"
|
||||||
|
|
||||||
|
void RageVec3ClearBounds( RageVector3 &mins, RageVector3 &maxs )
|
||||||
|
{
|
||||||
|
mins = RageVector3( 999999, 999999, 999999 );
|
||||||
|
maxs = mins * -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RageVec3AddToBounds( const RageVector3 &p, RageVector3 &mins, RageVector3 &maxs )
|
||||||
|
{
|
||||||
|
mins.x = min( mins.x, p.x );
|
||||||
|
mins.y = min( mins.y, p.y );
|
||||||
|
mins.z = min( mins.z, p.z );
|
||||||
|
maxs.x = max( maxs.x, p.x );
|
||||||
|
maxs.y = max( maxs.y, p.y );
|
||||||
|
maxs.z = max( maxs.z, p.z );
|
||||||
|
}
|
||||||
|
|
||||||
void RageVec2Normalize( RageVector2* pOut, const RageVector2* pV )
|
void RageVec2Normalize( RageVector2* pOut, const RageVector2* pV )
|
||||||
{
|
{
|
||||||
float scale = 1.0f / sqrtf( pV->x*pV->x + pV->y*pV->y );
|
float scale = 1.0f / sqrtf( pV->x*pV->x + pV->y*pV->y );
|
||||||
@@ -325,35 +341,52 @@ RageVector4 RageQuatFromR(float theta )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* From http://www.gamasutra.com/features/19980703/quaternions_01.htm .
|
/* Math from http://www.gamasutra.com/features/19980703/quaternions_01.htm . */
|
||||||
*
|
|
||||||
* The math on this page treats HPR as if Z is up and we're looking down Y; that
|
/* prh.xyz -> heading, pitch, roll */
|
||||||
* is, if you're in a room, the floor is on the XY plane and Z is height.
|
|
||||||
* However, we treat the floor as the XZ plane, and Y is height; in other
|
|
||||||
* words, as if the screen is the XY plane and negative Z goes into it.
|
|
||||||
* So, instead of HPR.xyz being heading, pitch, roll, it's pitch, roll, heading. */
|
|
||||||
void RageQuatFromHPR(RageVector4* pOut, RageVector3 hpr )
|
void RageQuatFromHPR(RageVector4* pOut, RageVector3 hpr )
|
||||||
{
|
{
|
||||||
hpr *= PI;
|
hpr *= PI;
|
||||||
hpr /= 180.0f;
|
hpr /= 180.0f;
|
||||||
hpr /= 2.0f;
|
hpr /= 2.0f;
|
||||||
|
|
||||||
|
const float sX = sinf(hpr.x);
|
||||||
|
const float cX = cosf(hpr.x);
|
||||||
|
const float sY = sinf(hpr.y);
|
||||||
|
const float cY = cosf(hpr.y);
|
||||||
|
const float sZ = sinf(hpr.z);
|
||||||
|
const float cZ = cosf(hpr.z);
|
||||||
|
|
||||||
|
pOut->w = cX * cY * cZ + sX * sY * sZ;
|
||||||
|
pOut->x = sX * cY * cZ - cX * sY * sZ;
|
||||||
|
pOut->y = cX * sY * cZ + sX * cY * sZ;
|
||||||
|
pOut->z = cX * cY * sZ - sX * sY * cZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Screen orientatoin: the "floor" is the XZ plane, and Y is height; in other
|
||||||
|
* words, the screen is the XY plane and negative Z goes into it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* prh.xyz -> pitch, roll, heading */
|
||||||
|
void RageQuatFromPRH(RageVector4* pOut, RageVector3 prh )
|
||||||
|
{
|
||||||
|
prh *= PI;
|
||||||
|
prh /= 180.0f;
|
||||||
|
prh /= 2.0f;
|
||||||
|
|
||||||
/* Set cX to the cosine of the angle we want to rotate on the X axis,
|
/* Set cX to the cosine of the angle we want to rotate on the X axis,
|
||||||
* and so on. Here, hpr.z (roll) rotates on the Z axis, hpr.x (heading)
|
* and so on. Here, hpr.z (roll) rotates on the Z axis, hpr.x (heading)
|
||||||
* on Y, and hpr.y (pitch) on X. */
|
* on Y, and hpr.y (pitch) on X. */
|
||||||
const float cZ = cosf(hpr.z);
|
const float sX = sinf(prh.y);
|
||||||
const float cY = cosf(hpr.x);
|
const float cX = cosf(prh.y);
|
||||||
const float cX = cosf(hpr.y);
|
const float sY = sinf(prh.x);
|
||||||
|
const float cY = cosf(prh.x);
|
||||||
|
const float sZ = sinf(prh.z);
|
||||||
|
const float cZ = cosf(prh.z);
|
||||||
|
|
||||||
const float sZ = sinf(hpr.z);
|
pOut->w = cX * cY * cZ + sX * sY * sZ;
|
||||||
const float sY = sinf(hpr.x);
|
pOut->x = sX * cY * cZ - cX * sY * sZ;
|
||||||
const float sX = sinf(hpr.y);
|
|
||||||
|
|
||||||
const float cYcZ = cY * cZ;
|
|
||||||
const float sYsZ = sY * sZ;
|
|
||||||
|
|
||||||
pOut->w = cX * cYcZ + sX * sYsZ;
|
|
||||||
pOut->x = sX * cYcZ - cX * sYsZ;
|
|
||||||
pOut->y = cX * sY * cZ + sX * cY * sZ;
|
pOut->y = cX * sY * cZ + sX * cY * sZ;
|
||||||
pOut->z = cX * cY * sZ - sX * sY * cZ;
|
pOut->z = cX * cY * sZ - sX * sY * cZ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ struct RageVector3;
|
|||||||
struct RageVector4;
|
struct RageVector4;
|
||||||
struct RageMatrix;
|
struct RageMatrix;
|
||||||
|
|
||||||
|
void RageVec3ClearBounds( RageVector3 &mins, RageVector3 &maxs );
|
||||||
|
void RageVec3AddToBounds( const RageVector3 &p, RageVector3 &mins, RageVector3 &maxs );
|
||||||
|
|
||||||
void RageVec2Normalize( RageVector2* pOut, const RageVector2* pV );
|
void RageVec2Normalize( RageVector2* pOut, const RageVector2* pV );
|
||||||
void RageVec3Normalize( RageVector3* pOut, const RageVector3* pV );
|
void RageVec3Normalize( RageVector3* pOut, const RageVector3* pV );
|
||||||
@@ -34,6 +36,7 @@ RageMatrix RageMatrixRotationY( float fTheta );
|
|||||||
RageMatrix RageMatrixRotationZ( float fTheta );
|
RageMatrix RageMatrixRotationZ( float fTheta );
|
||||||
void RageMatrixCommand( CString sCommandString, RageMatrix &mat );
|
void RageMatrixCommand( CString sCommandString, RageMatrix &mat );
|
||||||
void RageQuatFromHPR(RageVector4* pOut, RageVector3 hpr );
|
void RageQuatFromHPR(RageVector4* pOut, RageVector3 hpr );
|
||||||
|
void RageQuatFromPRH(RageVector4* pOut, RageVector3 prh );
|
||||||
void RageMatrixFromQuat( RageMatrix* pOut, const RageVector4 q );
|
void RageMatrixFromQuat( RageMatrix* pOut, const RageVector4 q );
|
||||||
void RageQuatSlerp(RageVector4 *pOut, const RageVector4 &from, const RageVector4 &to, float t);
|
void RageQuatSlerp(RageVector4 *pOut, const RageVector4 &from, const RageVector4 &to, float t);
|
||||||
RageVector4 RageQuatFromH(float theta);
|
RageVector4 RageQuatFromH(float theta);
|
||||||
|
|||||||
Reference in New Issue
Block a user