2007-10-13 22:39:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 David Adam
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __D3DX8MATH_INL__
|
|
|
|
#define __D3DX8MATH_INL__
|
|
|
|
|
2007-10-23 09:54:32 +00:00
|
|
|
/*_______________D3DXCOLOR_____________________*/
|
|
|
|
|
2007-10-23 11:14:19 +00:00
|
|
|
static inline D3DXCOLOR* D3DXColorAdd(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pc1 || !pc2 ) return NULL;
|
|
|
|
pout->r = (pc1->r) + (pc2->r);
|
|
|
|
pout->g = (pc1->g) + (pc2->g);
|
|
|
|
pout->b = (pc1->b) + (pc2->b);
|
|
|
|
pout->a = (pc1->a) + (pc2->a);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-23 09:54:32 +00:00
|
|
|
static inline D3DXCOLOR* D3DXColorLerp(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2, FLOAT s)
|
|
|
|
{
|
|
|
|
if ( !pout || !pc1 || !pc2 ) return NULL;
|
|
|
|
pout->r = (1-s) * (pc1->r) + s *(pc2->r);
|
|
|
|
pout->g = (1-s) * (pc1->g) + s *(pc2->g);
|
|
|
|
pout->b = (1-s) * (pc1->b) + s *(pc2->b);
|
|
|
|
pout->a = (1-s) * (pc1->a) + s *(pc2->a);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-23 10:09:02 +00:00
|
|
|
static inline D3DXCOLOR* D3DXColorModulate(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pc1 || !pc2 ) return NULL;
|
|
|
|
pout->r = (pc1->r) * (pc2->r);
|
|
|
|
pout->g = (pc1->g) * (pc2->g);
|
|
|
|
pout->b = (pc1->b) * (pc2->b);
|
|
|
|
pout->a = (pc1->a) * (pc2->a);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-23 09:30:55 +00:00
|
|
|
static inline D3DXCOLOR* D3DXColorNegative(D3DXCOLOR *pout, CONST D3DXCOLOR *pc)
|
|
|
|
{
|
|
|
|
if ( !pout || !pc ) return NULL;
|
|
|
|
pout->r = 1.0f - pc->r;
|
|
|
|
pout->g = 1.0f - pc->g;
|
|
|
|
pout->b = 1.0f - pc->b;
|
|
|
|
pout->a = pc->a;
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-23 11:06:51 +00:00
|
|
|
static inline D3DXCOLOR* D3DXColorScale(D3DXCOLOR *pout, CONST D3DXCOLOR *pc, FLOAT s)
|
|
|
|
{
|
|
|
|
if ( !pout || !pc ) return NULL;
|
|
|
|
pout->r = s* (pc->r);
|
|
|
|
pout->g = s* (pc->g);
|
|
|
|
pout->b = s* (pc->b);
|
|
|
|
pout->a = s* (pc->a);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-23 11:19:27 +00:00
|
|
|
static inline D3DXCOLOR* D3DXColorSubtract(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pc1 || !pc2 ) return NULL;
|
|
|
|
pout->r = (pc1->r) - (pc2->r);
|
|
|
|
pout->g = (pc1->g) - (pc2->g);
|
|
|
|
pout->b = (pc1->b) - (pc2->b);
|
|
|
|
pout->a = (pc1->a) - (pc2->a);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 12:03:03 +00:00
|
|
|
/*_______________D3DXVECTOR2________________________*/
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline D3DXVECTOR2* D3DXVec2Add(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
2007-10-14 17:06:20 +00:00
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = pv1->x + pv2->x;
|
|
|
|
pout->y = pv1->y + pv2->y;
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline FLOAT D3DXVec2CCW(CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
2007-10-14 16:33:25 +00:00
|
|
|
{
|
|
|
|
if ( !pv1 || !pv2) return 0.0f;
|
|
|
|
return ( (pv1->x) * (pv2->y) - (pv1->y) * (pv2->x) );
|
|
|
|
}
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline FLOAT D3DXVec2Dot(CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
2007-10-14 16:24:33 +00:00
|
|
|
{
|
|
|
|
if ( !pv1 || !pv2) return 0.0f;
|
|
|
|
return ( (pv1->x * pv2->x + pv1->y * pv2->y) );
|
|
|
|
}
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline FLOAT D3DXVec2Length(CONST D3DXVECTOR2 *pv)
|
2007-10-13 22:39:54 +00:00
|
|
|
{
|
|
|
|
if (!pv) return 0.0f;
|
|
|
|
return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) );
|
|
|
|
}
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline FLOAT D3DXVec2LengthSq(CONST D3DXVECTOR2 *pv)
|
2007-10-13 23:15:30 +00:00
|
|
|
{
|
|
|
|
if (!pv) return 0.0f;
|
|
|
|
return( (pv->x) * (pv->x) + (pv->y) * (pv->y) );
|
|
|
|
}
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline D3DXVECTOR2* D3DXVec2Lerp(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, FLOAT s)
|
2007-10-14 18:31:58 +00:00
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = (1-s) * (pv1->x) + s * (pv2->x);
|
|
|
|
pout->y = (1-s) * (pv1->y) + s * (pv2->y);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline D3DXVECTOR2* D3DXVec2Maximize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
2007-10-14 18:04:59 +00:00
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = max(pv1->x , pv2->x);
|
|
|
|
pout->y = max(pv1->y , pv2->y);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline D3DXVECTOR2* D3DXVec2Minimize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
2007-10-14 17:28:03 +00:00
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = min(pv1->x , pv2->x);
|
|
|
|
pout->y = min(pv1->y , pv2->y);
|
|
|
|
return pout;
|
|
|
|
}
|
2007-10-14 18:31:58 +00:00
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline D3DXVECTOR2* D3DXVec2Scale(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv, FLOAT s)
|
2007-10-14 18:20:01 +00:00
|
|
|
{
|
|
|
|
if ( !pout || !pv) return NULL;
|
|
|
|
pout->x = s * (pv->x);
|
|
|
|
pout->y = s * (pv->y);
|
|
|
|
return pout;
|
|
|
|
}
|
2007-10-14 17:28:03 +00:00
|
|
|
|
2007-10-16 12:09:43 +00:00
|
|
|
static inline D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
2007-10-14 17:22:17 +00:00
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = pv1->x - pv2->x;
|
|
|
|
pout->y = pv1->y - pv2->y;
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 12:03:03 +00:00
|
|
|
/*__________________D3DXVECTOR3_______________________*/
|
|
|
|
|
2007-10-18 16:32:17 +00:00
|
|
|
static inline D3DXVECTOR3* D3DXVec3Add(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = pv1->x + pv2->x;
|
|
|
|
pout->y = pv1->y + pv2->y;
|
|
|
|
pout->z = pv1->z + pv2->z;
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 18:12:29 +00:00
|
|
|
static inline D3DXVECTOR3* D3DXVec3Cross(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = (pv1->y) * (pv2->z) - (pv1->z) * (pv2->y);
|
|
|
|
pout->y = (pv1->z) * (pv2->x) - (pv1->x) * (pv2->z);
|
|
|
|
pout->z = (pv1->x) * (pv2->y) - (pv1->y) * (pv2->x);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:06:37 +00:00
|
|
|
static inline FLOAT D3DXVec3Dot(CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pv1 || !pv2 ) return 0.0f;
|
|
|
|
return (pv1->x) * (pv2->x) + (pv1->y) * (pv2->y) + (pv1->z) * (pv2->z);
|
|
|
|
}
|
|
|
|
|
2007-10-18 12:03:03 +00:00
|
|
|
static inline FLOAT D3DXVec3Length(CONST D3DXVECTOR3 *pv)
|
|
|
|
{
|
|
|
|
if (!pv) return 0.0f;
|
|
|
|
return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) );
|
|
|
|
}
|
|
|
|
|
2007-10-18 15:47:50 +00:00
|
|
|
static inline FLOAT D3DXVec3LengthSq(CONST D3DXVECTOR3 *pv)
|
|
|
|
{
|
|
|
|
if (!pv) return 0.0f;
|
|
|
|
return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z);
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:01:57 +00:00
|
|
|
static inline D3DXVECTOR3* D3DXVec3Lerp(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2, FLOAT s)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = (1-s) * (pv1->x) + s * (pv2->x);
|
|
|
|
pout->y = (1-s) * (pv1->y) + s * (pv2->y);
|
|
|
|
pout->z = (1-s) * (pv1->z) + s * (pv2->z);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:29:21 +00:00
|
|
|
static inline D3DXVECTOR3* D3DXVec3Maximize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = max(pv1->x , pv2->x);
|
|
|
|
pout->y = max(pv1->y , pv2->y);
|
|
|
|
pout->z = max(pv1->z , pv2->z);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:35:52 +00:00
|
|
|
static inline D3DXVECTOR3* D3DXVec3Minimize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = min(pv1->x , pv2->x);
|
|
|
|
pout->y = min(pv1->y , pv2->y);
|
|
|
|
pout->z = min(pv1->z , pv2->z);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:53:30 +00:00
|
|
|
static inline D3DXVECTOR3* D3DXVec3Scale(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv, FLOAT s)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv) return NULL;
|
|
|
|
pout->x = s * (pv->x);
|
|
|
|
pout->y = s * (pv->y);
|
|
|
|
pout->z = s * (pv->z);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:38:32 +00:00
|
|
|
static inline D3DXVECTOR3* D3DXVec3Subtract(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = pv1->x - pv2->x;
|
|
|
|
pout->y = pv1->y - pv2->y;
|
|
|
|
pout->z = pv1->z - pv2->z;
|
|
|
|
return pout;
|
|
|
|
}
|
2007-10-18 12:03:03 +00:00
|
|
|
/*__________________D3DXVECTOR4_______________________*/
|
|
|
|
|
2007-10-18 16:32:17 +00:00
|
|
|
static inline D3DXVECTOR4* D3DXVec4Add(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = pv1->x + pv2->x;
|
|
|
|
pout->y = pv1->y + pv2->y;
|
|
|
|
pout->z = pv1->z + pv2->z;
|
|
|
|
pout->w = pv1->w + pv2->w;
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:06:37 +00:00
|
|
|
static inline FLOAT D3DXVec4Dot(CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
|
|
|
{
|
|
|
|
if (!pv1 || !pv2 ) return 0.0f;
|
|
|
|
return (pv1->x) * (pv2->x) + (pv1->y) * (pv2->y) + (pv1->z) * (pv2->z) + (pv1->w) * (pv2->w);
|
|
|
|
}
|
|
|
|
|
2007-10-18 12:03:03 +00:00
|
|
|
static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv)
|
|
|
|
{
|
|
|
|
if (!pv) return 0.0f;
|
|
|
|
return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w) );
|
|
|
|
}
|
|
|
|
|
2007-10-18 15:47:50 +00:00
|
|
|
static inline FLOAT D3DXVec4LengthSq(CONST D3DXVECTOR4 *pv)
|
|
|
|
{
|
|
|
|
if (!pv) return 0.0f;
|
|
|
|
return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w);
|
|
|
|
}
|
2007-10-18 12:03:03 +00:00
|
|
|
|
2007-10-18 17:01:57 +00:00
|
|
|
static inline D3DXVECTOR4* D3DXVec4Lerp(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2, FLOAT s)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = (1-s) * (pv1->x) + s * (pv2->x);
|
|
|
|
pout->y = (1-s) * (pv1->y) + s * (pv2->y);
|
|
|
|
pout->z = (1-s) * (pv1->z) + s * (pv2->z);
|
|
|
|
pout->w = (1-s) * (pv1->w) + s * (pv2->w);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:29:21 +00:00
|
|
|
|
|
|
|
static inline D3DXVECTOR4* D3DXVec4Maximize(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = max(pv1->x , pv2->x);
|
|
|
|
pout->y = max(pv1->y , pv2->y);
|
|
|
|
pout->z = max(pv1->z , pv2->z);
|
|
|
|
pout->w = max(pv1->w , pv2->w);
|
2007-10-18 17:35:52 +00:00
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline D3DXVECTOR4* D3DXVec4Minimize(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = min(pv1->x , pv2->x);
|
|
|
|
pout->y = min(pv1->y , pv2->y);
|
|
|
|
pout->z = min(pv1->z , pv2->z);
|
|
|
|
pout->w = min(pv1->w , pv2->w);
|
2007-10-18 17:29:21 +00:00
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:53:30 +00:00
|
|
|
static inline D3DXVECTOR4* D3DXVec4Scale(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv, FLOAT s)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv) return NULL;
|
|
|
|
pout->x = s * (pv->x);
|
|
|
|
pout->y = s * (pv->y);
|
|
|
|
pout->z = s * (pv->z);
|
|
|
|
pout->w = s * (pv->w);
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:38:32 +00:00
|
|
|
static inline D3DXVECTOR4* D3DXVec4Subtract(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
|
|
|
{
|
|
|
|
if ( !pout || !pv1 || !pv2) return NULL;
|
|
|
|
pout->x = pv1->x - pv2->x;
|
|
|
|
pout->y = pv1->y - pv2->y;
|
|
|
|
pout->z = pv1->z - pv2->z;
|
|
|
|
pout->w = pv1->w - pv2->w;
|
|
|
|
return pout;
|
|
|
|
}
|
2007-10-18 17:01:57 +00:00
|
|
|
|
2007-10-23 11:28:52 +00:00
|
|
|
/*__________________D3DXMatrix____________________*/
|
2007-10-28 00:49:40 +00:00
|
|
|
#ifdef NONAMELESSUNION
|
|
|
|
# define D3DX_U(x) (x).u
|
|
|
|
#else
|
|
|
|
# define D3DX_U(x) (x)
|
|
|
|
#endif
|
2007-10-23 11:28:52 +00:00
|
|
|
|
2007-10-23 12:12:25 +00:00
|
|
|
static inline D3DXMATRIX* D3DXMatrixIdentity(D3DXMATRIX *pout)
|
2007-10-23 11:28:52 +00:00
|
|
|
{
|
|
|
|
if ( !pout ) return NULL;
|
2007-10-28 00:49:40 +00:00
|
|
|
D3DX_U(*pout).m[0][1] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[0][2] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[0][3] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[1][0] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[1][2] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[1][3] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[2][0] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[2][1] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[2][3] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[3][0] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[3][1] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[3][2] = 0.0f;
|
|
|
|
D3DX_U(*pout).m[0][0] = 1.0f;
|
|
|
|
D3DX_U(*pout).m[1][1] = 1.0f;
|
|
|
|
D3DX_U(*pout).m[2][2] = 1.0f;
|
|
|
|
D3DX_U(*pout).m[3][3] = 1.0f;
|
2007-10-23 11:28:52 +00:00
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-23 12:12:25 +00:00
|
|
|
static inline BOOL D3DXMatrixIsIdentity(D3DXMATRIX *pm)
|
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
D3DXMATRIX testmatrix;
|
|
|
|
|
|
|
|
if ( !pm ) return FALSE;
|
|
|
|
D3DXMatrixIdentity(&testmatrix);
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
for (j=0; j<4; j++)
|
|
|
|
{
|
2007-10-30 13:18:51 +00:00
|
|
|
if ( D3DX_U(*pm).m[i][j] != D3DX_U(testmatrix).m[i][j] ) return FALSE;
|
2007-10-23 12:12:25 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-30 13:18:51 +00:00
|
|
|
return TRUE;
|
2007-10-23 12:12:25 +00:00
|
|
|
}
|
2007-10-28 00:49:40 +00:00
|
|
|
#undef D3DX_U
|
2007-10-23 11:28:52 +00:00
|
|
|
|
|
|
|
/*__________________D3DXPLANE____________________*/
|
2007-10-18 12:03:03 +00:00
|
|
|
|
2007-10-23 09:01:43 +00:00
|
|
|
static inline FLOAT D3DXPlaneDot(CONST D3DXPLANE *pp, CONST D3DXVECTOR4 *pv)
|
2007-10-23 08:58:41 +00:00
|
|
|
{
|
|
|
|
if ( !pp || !pv ) return 0.0f;
|
|
|
|
return ( (pp->a) * (pv->x) + (pp->b) * (pv->y) + (pp->c) * (pv->z) + (pp->d) * (pv->w) );
|
|
|
|
}
|
|
|
|
|
2007-10-23 09:01:43 +00:00
|
|
|
static inline FLOAT D3DXPlaneDotCoord(CONST D3DXPLANE *pp, CONST D3DXVECTOR4 *pv)
|
|
|
|
{
|
|
|
|
if ( !pp || !pv ) return 0.0f;
|
|
|
|
return ( (pp->a) * (pv->x) + (pp->b) * (pv->y) + (pp->c) * (pv->z) + (pp->d) );
|
|
|
|
}
|
|
|
|
|
2007-10-23 09:06:33 +00:00
|
|
|
static inline FLOAT D3DXPlaneDotNormal(CONST D3DXPLANE *pp, CONST D3DXVECTOR4 *pv)
|
|
|
|
{
|
|
|
|
if ( !pp || !pv ) return 0.0f;
|
|
|
|
return ( (pp->a) * (pv->x) + (pp->b) * (pv->y) + (pp->c) * (pv->z) );
|
|
|
|
}
|
|
|
|
|
2007-10-23 08:58:41 +00:00
|
|
|
/*__________________D3DXQUATERNION____________________*/
|
|
|
|
|
2007-10-18 18:28:36 +00:00
|
|
|
static inline D3DXQUATERNION* D3DXQuaternionConjugate(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq)
|
|
|
|
{
|
|
|
|
if ( !pout || !pq) return NULL;
|
|
|
|
pout->x = -pq->x;
|
|
|
|
pout->y = -pq->y;
|
|
|
|
pout->z = -pq->z;
|
|
|
|
pout->w = pq->w;
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:06:37 +00:00
|
|
|
static inline FLOAT D3DXQuaternionDot(CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2)
|
|
|
|
{
|
|
|
|
if ( !pq1 || !pq2 ) return 0.0f;
|
|
|
|
return (pq1->x) * (pq2->x) + (pq1->y) * (pq2->y) + (pq1->z) * (pq2->z) + (pq1->w) * (pq2->w);
|
|
|
|
}
|
|
|
|
|
2007-10-18 19:01:24 +00:00
|
|
|
static inline D3DXQUATERNION* D3DXQuaternionIdentity(D3DXQUATERNION *pout)
|
|
|
|
{
|
|
|
|
if ( !pout) return NULL;
|
|
|
|
pout->x = 0.0f;
|
|
|
|
pout->y = 0.0f;
|
|
|
|
pout->z = 0.0f;
|
|
|
|
pout->w = 1.0f;
|
|
|
|
return pout;
|
|
|
|
}
|
|
|
|
|
2007-10-18 21:15:18 +00:00
|
|
|
static inline BOOL D3DXQuaternionIsIdentity(D3DXQUATERNION *pq)
|
|
|
|
{
|
|
|
|
if ( !pq) return FALSE;
|
|
|
|
return ( (pq->x == 0.0f) && (pq->y == 0.0f) && (pq->z == 0.0f) && (pq->w == 1.0f) );
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:06:37 +00:00
|
|
|
static inline FLOAT D3DXQuaternionLength(CONST D3DXQUATERNION *pq)
|
2007-10-18 12:03:03 +00:00
|
|
|
{
|
|
|
|
if (!pq) return 0.0f;
|
|
|
|
return sqrt( (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w) );
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:06:37 +00:00
|
|
|
static inline FLOAT D3DXQuaternionLengthSq(CONST D3DXQUATERNION *pq)
|
2007-10-18 15:47:50 +00:00
|
|
|
{
|
|
|
|
if (!pq) return 0.0f;
|
|
|
|
return (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w);
|
|
|
|
}
|
2007-10-18 12:03:03 +00:00
|
|
|
|
2007-10-13 22:39:54 +00:00
|
|
|
#endif
|