From 74750c3c6449c00ab6eafad189d234b1986c24be Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 9 Nov 2007 18:04:40 +0100 Subject: [PATCH] d3dx8: Implement the C++ stuff of the D3DXVECTOR2 structure. --- include/d3dx8math.h | 26 +++++++++++ include/d3dx8math.inl | 105 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/include/d3dx8math.h b/include/d3dx8math.h index bd1dc4fb8e9..385599fafd9 100644 --- a/include/d3dx8math.h +++ b/include/d3dx8math.h @@ -31,6 +31,32 @@ typedef struct D3DXVECTOR2 { +#ifdef __cplusplus + D3DXVECTOR2(); + D3DXVECTOR2(CONST FLOAT *pf); + D3DXVECTOR2(FLOAT fx, FLOAT fy); + + operator FLOAT* (); + operator CONST FLOAT* () const; + + D3DXVECTOR2& operator += (CONST D3DXVECTOR2&); + D3DXVECTOR2& operator -= (CONST D3DXVECTOR2&); + D3DXVECTOR2& operator *= (FLOAT); + D3DXVECTOR2& operator /= (FLOAT); + + D3DXVECTOR2 operator + () const; + D3DXVECTOR2 operator - () const; + + D3DXVECTOR2 operator + (CONST D3DXVECTOR2&) const; + D3DXVECTOR2 operator - (CONST D3DXVECTOR2&) const; + D3DXVECTOR2 operator * (FLOAT) const; + D3DXVECTOR2 operator / (FLOAT) const; + + friend D3DXVECTOR2 operator * (FLOAT, CONST D3DXVECTOR2&); + + BOOL operator == (CONST D3DXVECTOR2&) const; + BOOL operator != (CONST D3DXVECTOR2&) const; +#endif /* __cplusplus */ FLOAT x, y; } D3DXVECTOR2, *LPD3DXVECTOR2; diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl index cdcea0694a1..8c21f68fd12 100644 --- a/include/d3dx8math.inl +++ b/include/d3dx8math.inl @@ -21,6 +21,111 @@ /*_______________D3DXCOLOR_____________________*/ +/* constructors & operators */ +#ifdef __cplusplus + +inline D3DXVECTOR2::D3DXVECTOR2() +{ +} + +inline D3DXVECTOR2::D3DXVECTOR2(CONST FLOAT *pf) +{ + if(!pf) return; + x = pf[0]; + y = pf[1]; +} + +inline D3DXVECTOR2::D3DXVECTOR2(FLOAT fx, FLOAT fy) +{ + x = fx; + y = fy; +} + +inline D3DXVECTOR2::operator FLOAT* () +{ + return (FLOAT*)&x; +} + +inline D3DXVECTOR2::operator CONST FLOAT* () const +{ + return (CONST FLOAT*)&x; +} + +inline D3DXVECTOR2& D3DXVECTOR2::operator += (CONST D3DXVECTOR2& v) +{ + x += v.x; + y += v.y; + return *this; +} + +inline D3DXVECTOR2& D3DXVECTOR2::operator -= (CONST D3DXVECTOR2& v) +{ + x -= v.x; + y -= v.y; + return *this; +} + +inline D3DXVECTOR2& D3DXVECTOR2::operator *= (FLOAT f) +{ + x *= f; + y *= f; + return *this; +} + +inline D3DXVECTOR2& D3DXVECTOR2::operator /= (FLOAT f) +{ + x /= f; + y /= f; + return *this; +} + +inline D3DXVECTOR2 D3DXVECTOR2::operator + () const +{ + return *this; +} + +inline D3DXVECTOR2 D3DXVECTOR2::operator - () const +{ + return D3DXVECTOR2(-x, -y); +} + +inline D3DXVECTOR2 D3DXVECTOR2::operator + (CONST D3DXVECTOR2& v) const +{ + return D3DXVECTOR2(x + v.x, y + v.y); +} + +inline D3DXVECTOR2 D3DXVECTOR2::operator - (CONST D3DXVECTOR2& v) const +{ + return D3DXVECTOR2(x - v.x, y - v.y); +} + +inline D3DXVECTOR2 D3DXVECTOR2::operator * (FLOAT f) const +{ + return D3DXVECTOR2(x * f, y * f); +} + +inline D3DXVECTOR2 D3DXVECTOR2::operator / (FLOAT f) const +{ + return D3DXVECTOR2(x / f, y / f); +} + +inline D3DXVECTOR2 operator * (FLOAT f, CONST D3DXVECTOR2& v) +{ + return D3DXVECTOR2(f * v.x, f * v.y); +} + +inline BOOL D3DXVECTOR2::operator == (CONST D3DXVECTOR2& v) const +{ + return x == v.x && y == v.y; +} + +inline BOOL D3DXVECTOR2::operator != (CONST D3DXVECTOR2& v) const +{ + return x != v.x || y != v.y; +} + +#endif /* __cplusplus */ + static inline D3DXCOLOR* D3DXColorAdd(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2) { if ( !pout || !pc1 || !pc2 ) return NULL;