📄 xpl.h
字号:
/* ************************************************************************* *\
**
** INTEL Corporation Proprietary Information
**
** This listing is supplied under the terms of a license
** agreement with INTEL Corporation and may not be copied
** nor disclosed except in accordance with the terms of
** that agreement.
**
** Copyright (c) 2003 Intel Corporation.
** All Rights Reserved.
**
** ************************************************************************* **
** FILE: XPL.h
** DESCRIPTION: Math Types and Operations
**
** CREATED: November 30, 2004
**
\* ************************************************************************* */
#if !defined( __XPL_H__ )
#define __XPL_H__
#if defined( __cplusplus )
extern "C" {
#endif /* __cplusplus */
// Compile-Time assert - takes up no space in generated code
#define CT_ASSERT(c) typedef char cassert_t[(c)?1:-1];
/*****************************************************************************\
Basic types
\*****************************************************************************/
typedef char I8; // 8-bit signed
typedef unsigned char U8; // 8-bit unsigned
CT_ASSERT( 1 == sizeof( U8 ));
typedef short I16; // 16-bit signed
typedef unsigned short U16; // 16-bit unsigned
CT_ASSERT( 2 == sizeof( U16 ));
typedef long I32; // 32-bit signed integer
typedef unsigned long U32; // 32-bit unsigned integer
CT_ASSERT( 4 == sizeof( U32 ));
typedef U32 BOOLE; // BOOLE type
typedef I32 X32; // 32-bit fixed point in S16.16 format
typedef I16 X16_14; // 16-bit fixed point in S2.14 format
typedef float F32; // 32-bit IEEE float
CT_ASSERT( 4 == sizeof( F32 ));
typedef struct tagFATFLOAT // separate 32-bit mantissa and exponent
{
U32 m, e;
} FATFLOAT;
CT_ASSERT( 8 == sizeof( FATFLOAT ));
#define TRUE 1
#define FALSE 0
/*****************************************************************************\
Multi-dimensional types
\*****************************************************************************/
typedef struct tagMatrix4f
{
F32 _11, _12, _13, _14;
F32 _21, _22, _23, _24;
F32 _31, _32, _33, _34;
F32 _41, _42, _43, _44;
} Matrix4f;
typedef struct tagVector4f
{
F32 x, y, z, w;
} Vector4f;
typedef struct tagVector3f
{
F32 x, y, z;
} Vector3f;
typedef struct tagVector2f
{
F32 x, y;
} Vector2f;
typedef struct tagMatrix4x
{
X32 _11, _12, _13, _14;
X32 _21, _22, _23, _24;
X32 _31, _32, _33, _34;
X32 _41, _42, _43, _44;
} Matrix4x;
typedef struct tagVector4x
{
X32 x, y, z, w;
} Vector4x;
typedef struct tagVector3x
{
X32 x, y, z;
} Vector3x;
typedef struct tagNormal
{
X16_14 x, y, z, w;
} Normal;
typedef struct tagColor4s
{
U16 b, g, r, a;
} Color4s;
/*****************************************************************************\
Prototypes - Float routines
\*****************************************************************************/
//void HMat4F_Multiply(HMATRIX4F *in_pDst, const HMATRIX4F *in_pA, const HMATRIX4F *in_pB)
void Matrix4f_Multiply ( F32* pDst, F32 const * pA, F32 const * pB );
//float HMat4F_Determinate3x3(const HMATRIX4F* in_pA)
F32 Matrix4f_Determinate3x3 ( F32 const * pMat );
//HBOOLE HMat4F_Invert3x4(HMATRIX4F* in_pDst, const HMATRIX4F* in_pA)
BOOLE Matrix4f_Invert3x4 ( F32* pDst, F32 const * pMat );
//BOOLE HMat4F_IsIdentity(HMATRIX4F *psMatrix);
BOOLE Matrix4f_IsIdentity ( F32 const * pMat );
//void HMat4F_SetIdentity(HMATRIX4F *psMatrix);
void Matrix4f_SetIdentity ( F32* pMat );
//HVECTOR3F* HVec3F_Normalize(HVECTOR3F*in_pDst, const HVECTOR3F* in_pB)
F32* Vector3f_Normalize ( F32* pDst, F32 const * pVec );
//HVECTOR3F* HVec3F_Transform(HVECTOR3F* in_pDst, const HVECTOR3F* in_pB, const HMATRIX4F* in_pMat)
F32* Vector3f_Transform ( F32* pDst, F32 const * pVec, F32 const * pMat );
//HVECTOR3F* HVec3F_Transform3x3(HVECTOR3F* in_pDst, const HVECTOR3F* in_pB, const HMATRIX4F* in_pMat)
F32* Vector3f_Transform3x3 ( F32* pDst, F32 const * pVec, F32 const * pMat );
//HVECTOR4F* HVec4F_Transform(HVECTOR4F* in_pDst, const HVECTOR4F* in_pB, const HMATRIX4F* in_pMat)
F32* Vector4f_Transform ( F32* pDst, F32 const * pVec, F32 const * pMat );
//float HXFMakeFloat(HINT32 m, HINT8 e)
F32 Float_Make ( I32 m, I8 e );
//void HXFBreakFloat(float x, HINT32* m, HINT8* e)
void Float_Break ( F32 f, I32* pm, I8* pe );
#define fZERO (0.0f)
#define fHALF (0.5f)
#define fONE (1.0f)
#define fPI (3.141592654f)
#define fDEG_TO_RAD (fPI/180.0f)
#define fRAD_TO_DEG (180.0f/fPI)
/*****************************************************************************\
Prototypes - Fixed point routines
\*****************************************************************************/
//void HMat4FX_Multiply(HMATRIX4F *in_pDst, const HMATRIX4F *in_pA, const HMATRIX4F *in_pB)
void Matrix4x_Multiply ( X32* pDst, X32 const * pA, X32 const * pB );
//HBOOLE HMat4FX_Invert3x4(HMATRIX4FX* in_pDst, const HMATRIX4FX* in_pA)
BOOLE Matrix4x_Invert3x4 ( X32* pDst, X32 const * pMat );
//BOOLE HMat4FX_IsIdentity(HMATRIX4FX *psMatrix);
BOOLE Matrix4x_IsIdentity ( X32 const * pMat );
//void HMat4FX_SetIdentity(HMATRIX4FX *psMatrix);
void Matrix4x_SetIdentity ( X32* pMat );
//HVECTOR3FX* HVec3FX_Normalize(HVECTOR3FX*in_pDst, const HVECTOR3FX* in_pB)
X32* Vector3x_Normalize ( X32* pDst, X32 const * pVec );
//HVECTOR3F* HVec3FX_Transform(HVECTOR3F* in_pDst, const HVECTOR3F* in_pB, const HMATRIX4F* in_pMat)
X32* Vector3x_Transform ( X32* pDst, X32 const * pVec, X32 const * pMat );
//HVECTOR3F* HVec3F_Transform3x3(HVECTOR3F* in_pDst, const HVECTOR3F* in_pB, const HMATRIX4F* in_pMat)
X32* Vector3x_Transform3x3 ( X32* pDst, X32 const * pVec, X32 const * pMat );
//HVECTOR4F* HVec4FX_Transform(HVECTOR4F* in_pDst, const HVECTOR4F* in_pB, const HMATRIX4F* in_pMat)
X32* Vector4x_Transform ( X32* pDst, X32 const * pVec, X32 const * pMat );
//HFIXED HAbsFX(HFIXED);
X32 Fixed_Abs ( X32 x );
//HFIXED HMulFX(HFIXED, HFIXED);
X32 Fixed_Mul ( X32 lhs, X32 rhs );
//HFIXED HDivFX(HFIXED, HFIXED);
X32 Fixed_Div ( X32 lhs, X32 rhs );
//HFIXED HSinFX( HFIXED );
X32 Fixed_Sin ( X32 x );
//HFIXED HCosFX( HFIXED );
X32 Fixed_Cos ( X32 x );
//HFIXED HInvSqrtFX(HFIXED);
X32 Fixed_InvSqrt ( X32 x );
#define xZERO (0x00000000)
#define xHALF (0x00008000)
#define xONE (0x00010000)
#define xMAX (0x7FFFFFFF) // 32767.99998
#define xMIN (0x80000000) // -32768.
#define xDEG_TO_RAD (0x00000477) // PI/180 = 0.017453293
#define xRAD_TO_DEG (0x00394BB8) // 180/PI = 57.29577951
/*****************************************************************************\
Prototypes - Normal routines
\*****************************************************************************/
//HXFNORMAL* HXFPackNormalF(HXFNORMAL* in_pDst, float x, float y, float z)
X16_14* Normal_Pack3f ( X16_14* pDst, F32 x, F32 y, F32 z );
//HXFNORMAL* HXFPackNormalFX(HXFNORMAL* in_pDst, HFIXED x, HFIXED y, HFIXED z)
X16_14* Normal_Pack3x ( X16_14* pDst, X32 x, X32 y, X32 z );
/*****************************************************************************\
Prototypes - Color routines
\*****************************************************************************/
//HBOOLE HXFColor4S_Multiply(HXFCOLOR4S*, const HXFCOLOR4S*, const HXFCOLOR4S*);
BOOLE Color4s_Multiply ( U16* pDst, U16 const * pA, U16 const * pB );
//HXFCOLOR4S* HXFPackColorF(HXFCOLOR4S* in_pDst, const float* pClr)
U16* Color4s_Pack4f ( U16* pDst, F32 const * af );
//HXFCOLOR4S* HXFPackColorFX(HXFCOLOR4S* in_pDst, const HFIXED* pClr)
U16* Color4s_Pack4x ( U16* pDst, X32 const * ax );
//HBOOLE HXFColor4S_IsZero(const HXFCOLOR4S*);
BOOLE Color4s_IsZero ( U16 const * ac );
//HUINT32 HXFColor4SToABGR(const HXFCOLOR4S*);
U32 ABGR_Color4s ( U16 const * ac );
//HUINT32 HXFColor4FXToARGB(const HFIXED r, const HFIXED g, const HFIXED b, const HFIXED a)
U32 ARGB_Color4x ( X32 r, X32 g, X32 b, X32 a );
U32 ARGB_Color4f ( F32 r, F32 g, F32 b, F32 a );
/*****************************************************************************\
Prototypes - Conversion routines
\*****************************************************************************/
//float HFXToF(HFIXED);
F32 XtoF ( X32 x );
//float* HFXToFArray(float*, const HFIXED*, HUINT32);
F32* ArrayXtoF ( F32* af, X32 const * ax, U32 c );
//HFIXED HFToFX(float);
X32 FtoX ( F32 f );
//HFIXED HFFToFX(const HFATFLOAT*);
X32 FFtoX ( FATFLOAT const * pff );
//HFIXED* HFToFXArray(HFIXED*, const float*, HUINT32);
X32* ArrayFtoX ( X32* ax, F32 const * af, U32 c );
// Conversions that can be done by preprocessor (note: 'as' vs. 'to')
#define FasX(x) ((X32)((x)*65536.0f)) // 65536.0 = 2^16 (fractional bits) as a float
#define IasX(x) (((I32)(x))<<16) // 16 fractional bits
/*****************************************************************************\
Prototypes - Miscellaneous routines
\*****************************************************************************/
U32 HXFClz ( U32 u );
U32 HXFSignedClz ( U32 u );
U32 HXFCtz ( U32 u );
F32 HXFAbsF ( F32 f );
/*****************************************************************************\
\*****************************************************************************/
#if defined( __cplusplus )
}
#endif /* __cplusplus */
#endif /* __XPL_H__ */
/*****************************************************************************\
EOF: XPL.H
\*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -