2 * Copyright (C) 2007 David Adam
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef __D3DX8MATH_INL__
20 #define __D3DX8MATH_INL__
22 static inline D3DXVECTOR2* D3DXVec2Add(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
24 if ( !pout || !pv1 || !pv2) return NULL;
25 pout->x = pv1->x + pv2->x;
26 pout->y = pv1->y + pv2->y;
30 static inline FLOAT D3DXVec2CCW(CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
32 if ( !pv1 || !pv2) return 0.0f;
33 return ( (pv1->x) * (pv2->y) - (pv1->y) * (pv2->x) );
36 static inline FLOAT D3DXVec2Dot(CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
38 if ( !pv1 || !pv2) return 0.0f;
39 return ( (pv1->x * pv2->x + pv1->y * pv2->y) );
42 static inline FLOAT D3DXVec2Length(CONST D3DXVECTOR2 *pv)
45 return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) );
48 static inline FLOAT D3DXVec2LengthSq(CONST D3DXVECTOR2 *pv)
51 return( (pv->x) * (pv->x) + (pv->y) * (pv->y) );
54 static inline D3DXVECTOR2* D3DXVec2Lerp(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, FLOAT s)
56 if ( !pout || !pv1 || !pv2) return NULL;
57 pout->x = (1-s) * (pv1->x) + s * (pv2->x);
58 pout->y = (1-s) * (pv1->y) + s * (pv2->y);
62 static inline D3DXVECTOR2* D3DXVec2Maximize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
64 if ( !pout || !pv1 || !pv2) return NULL;
65 pout->x = max(pv1->x , pv2->x);
66 pout->y = max(pv1->y , pv2->y);
70 static inline D3DXVECTOR2* D3DXVec2Minimize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
72 if ( !pout || !pv1 || !pv2) return NULL;
73 pout->x = min(pv1->x , pv2->x);
74 pout->y = min(pv1->y , pv2->y);
78 static inline D3DXVECTOR2* D3DXVec2Scale(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv, FLOAT s)
80 if ( !pout || !pv) return NULL;
81 pout->x = s * (pv->x);
82 pout->y = s * (pv->y);
86 static inline D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
88 if ( !pout || !pv1 || !pv2) return NULL;
89 pout->x = pv1->x - pv2->x;
90 pout->y = pv1->y - pv2->y;