From d320460765c16a990f4f6425c9a1483c08fe9046 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 9 Nov 2007 18:54:12 +0100 Subject: [PATCH] d3dx8: Implement the C++ stuff of the D3DXVECTOR3 structure. --- include/d3dx8math.h | 32 ++++++++++++++ include/d3dx8math.inl | 118 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 148 insertions(+), 2 deletions(-) diff --git a/include/d3dx8math.h b/include/d3dx8math.h index 385599fafd9..383c80c78f5 100644 --- a/include/d3dx8math.h +++ b/include/d3dx8math.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2007 David Adam + * Copyright (C) 2007 Tony Wasserka * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -60,7 +61,38 @@ typedef struct D3DXVECTOR2 FLOAT x, y; } D3DXVECTOR2, *LPD3DXVECTOR2; +#ifdef __cplusplus +typedef struct D3DXVECTOR3 : public D3DVECTOR +{ + D3DXVECTOR3(); + D3DXVECTOR3(CONST FLOAT *pf); + D3DXVECTOR3(CONST D3DVECTOR& v); + D3DXVECTOR3(FLOAT fx, FLOAT fy, FLOAT fz); + + operator FLOAT* (); + operator CONST FLOAT* () const; + + D3DXVECTOR3& operator += (CONST D3DXVECTOR3&); + D3DXVECTOR3& operator -= (CONST D3DXVECTOR3&); + D3DXVECTOR3& operator *= (FLOAT); + D3DXVECTOR3& operator /= (FLOAT); + + D3DXVECTOR3 operator + () const; + D3DXVECTOR3 operator - () const; + + D3DXVECTOR3 operator + (CONST D3DXVECTOR3&) const; + D3DXVECTOR3 operator - (CONST D3DXVECTOR3&) const; + D3DXVECTOR3 operator * (FLOAT) const; + D3DXVECTOR3 operator / (FLOAT) const; + + friend D3DXVECTOR3 operator * (FLOAT, CONST struct D3DXVECTOR3&); + + BOOL operator == (CONST D3DXVECTOR3&) const; + BOOL operator != (CONST D3DXVECTOR3&) const; +} D3DXVECTOR3, *LPD3DXVECTOR3; +#else /* !__cplusplus */ typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3; +#endif /* !__cplusplus */ typedef struct D3DXVECTOR4 { diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl index 8c21f68fd12..a2fd130e096 100644 --- a/include/d3dx8math.inl +++ b/include/d3dx8math.inl @@ -1,5 +1,6 @@ /* * Copyright (C) 2007 David Adam + * Copyright (C) 2007 Tony Wasserka * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,8 +20,6 @@ #ifndef __D3DX8MATH_INL__ #define __D3DX8MATH_INL__ -/*_______________D3DXCOLOR_____________________*/ - /* constructors & operators */ #ifdef __cplusplus @@ -124,8 +123,123 @@ inline BOOL D3DXVECTOR2::operator != (CONST D3DXVECTOR2& v) const return x != v.x || y != v.y; } +inline D3DXVECTOR3::D3DXVECTOR3() +{ +} + +inline D3DXVECTOR3::D3DXVECTOR3(CONST FLOAT *pf) +{ + if(!pf) return; + x = pf[0]; + y = pf[1]; + z = pf[2]; +} + +inline D3DXVECTOR3::D3DXVECTOR3(CONST D3DVECTOR& v) +{ + x = v.x; + y = v.y; + z = v.z; +} + +inline D3DXVECTOR3::D3DXVECTOR3(FLOAT fx, FLOAT fy, FLOAT fz) +{ + x = fx; + y = fy; + z = fz; +} + +inline D3DXVECTOR3::operator FLOAT* () +{ + return (FLOAT*)&x; +} + +inline D3DXVECTOR3::operator CONST FLOAT* () const +{ + return (CONST FLOAT*)&x; +} + +inline D3DXVECTOR3& D3DXVECTOR3::operator += (CONST D3DXVECTOR3& v) +{ + x += v.x; + y += v.y; + z += v.z; + return *this; +} + +inline D3DXVECTOR3& D3DXVECTOR3::operator -= (CONST D3DXVECTOR3& v) +{ + x -= v.x; + y -= v.y; + z -= v.z; + return *this; +} + +inline D3DXVECTOR3& D3DXVECTOR3::operator *= (FLOAT f) +{ + x *= f; + y *= f; + z *= f; + return *this; +} + +inline D3DXVECTOR3& D3DXVECTOR3::operator /= (FLOAT f) +{ + x /= f; + y /= f; + z /= f; + return *this; +} + +inline D3DXVECTOR3 D3DXVECTOR3::operator + () const +{ + return *this; +} + +inline D3DXVECTOR3 D3DXVECTOR3::operator - () const +{ + return D3DXVECTOR3(-x, -y, -z); +} + +inline D3DXVECTOR3 D3DXVECTOR3::operator + (CONST D3DXVECTOR3& v) const +{ + return D3DXVECTOR3(x + v.x, y + v.y, z + v.z); +} + +inline D3DXVECTOR3 D3DXVECTOR3::operator - (CONST D3DXVECTOR3& v) const +{ + return D3DXVECTOR3(x - v.x, y - v.y, z - v.z); +} + +inline D3DXVECTOR3 D3DXVECTOR3::operator * (FLOAT f) const +{ + return D3DXVECTOR3(x * f, y * f, z * f); +} + +inline D3DXVECTOR3 D3DXVECTOR3::operator / (FLOAT f) const +{ + return D3DXVECTOR3(x / f, y / f, z / f); +} + +inline D3DXVECTOR3 operator * (FLOAT f, CONST D3DXVECTOR3& v) +{ + return D3DXVECTOR3(f * v.x, f * v.y, f * v.z); +} + +inline BOOL D3DXVECTOR3::operator == (CONST D3DXVECTOR3& v) const +{ + return x == v.x && y == v.y && z == v.z; +} + +inline BOOL D3DXVECTOR3::operator != (CONST D3DXVECTOR3& v) const +{ + return x != v.x || y != v.y || z != v.z; +} + #endif /* __cplusplus */ +/*_______________D3DXCOLOR_____________________*/ + static inline D3DXCOLOR* D3DXColorAdd(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2) { if ( !pout || !pc1 || !pc2 ) return NULL; -- 2.11.4.GIT