Tony Wasserka : d3dx8: Implement the C++ stuff of the D3DXQUATERNION structure.

Alexandre Julliard julliard at winehq.org
Mon Nov 12 06:27:36 CST 2007


Module: wine
Branch: master
Commit: 00bcbe254ffaf67238141ff18e8c1cf1bc286c9e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=00bcbe254ffaf67238141ff18e8c1cf1bc286c9e

Author: Tony Wasserka <tony.wasserka at freenet.de>
Date:   Sat Nov 10 14:58:48 2007 +0100

d3dx8: Implement the C++ stuff of the D3DXQUATERNION structure.

---

 include/d3dx8math.h   |   28 ++++++++++
 include/d3dx8math.inl |  131 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 159 insertions(+), 0 deletions(-)

diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index c8af5a4..f35bed8 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -168,6 +168,34 @@ typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
 
 typedef struct D3DXQUATERNION
 {
+#ifdef __cplusplus
+    D3DXQUATERNION();
+    D3DXQUATERNION(CONST FLOAT *pf);
+    D3DXQUATERNION(FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw);
+
+    operator FLOAT* ();
+    operator CONST FLOAT* () const;
+
+    D3DXQUATERNION& operator += (CONST D3DXQUATERNION&);
+    D3DXQUATERNION& operator -= (CONST D3DXQUATERNION&);
+    D3DXQUATERNION& operator *= (CONST D3DXQUATERNION&);
+    D3DXQUATERNION& operator *= (FLOAT);
+    D3DXQUATERNION& operator /= (FLOAT);
+
+    D3DXQUATERNION  operator + () const;
+    D3DXQUATERNION  operator - () const;
+
+    D3DXQUATERNION operator + (CONST D3DXQUATERNION&) const;
+    D3DXQUATERNION operator - (CONST D3DXQUATERNION&) const;
+    D3DXQUATERNION operator * (CONST D3DXQUATERNION&) const;
+    D3DXQUATERNION operator * (FLOAT) const;
+    D3DXQUATERNION operator / (FLOAT) const;
+
+    friend D3DXQUATERNION operator * (FLOAT, CONST D3DXQUATERNION&);
+
+    BOOL operator == (CONST D3DXQUATERNION&) const;
+    BOOL operator != (CONST D3DXQUATERNION&) const;
+#endif /* __cplusplus */
     FLOAT x, y, z, w;
 } D3DXQUATERNION, *LPD3DXQUATERNION;
 
diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl
index a634c73..bce6070 100644
--- a/include/d3dx8math.inl
+++ b/include/d3dx8math.inl
@@ -508,6 +508,137 @@ inline BOOL D3DXMATRIX::operator != (CONST D3DXMATRIX& mat) const
     return (memcmp(this, &mat, sizeof(D3DXMATRIX)) != 0);
 }
 
+inline D3DXQUATERNION::D3DXQUATERNION()
+{
+}
+
+inline D3DXQUATERNION::D3DXQUATERNION(CONST FLOAT *pf)
+{
+    if(!pf) return;
+    x = pf[0];
+    y = pf[1];
+    z = pf[2];
+    w = pf[3];
+}
+
+inline D3DXQUATERNION::D3DXQUATERNION(FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw)
+{
+    x = fx;
+    y = fy;
+    z = fz;
+    w = fw;
+}
+
+inline D3DXQUATERNION::operator FLOAT* ()
+{
+    return (FLOAT*)&x;
+}
+
+inline D3DXQUATERNION::operator CONST FLOAT* () const
+{
+    return (CONST FLOAT*)&x;
+}
+
+inline D3DXQUATERNION& D3DXQUATERNION::operator += (CONST D3DXQUATERNION& quat)
+{
+    x += quat.x;
+    y += quat.y;
+    z += quat.z;
+    w += quat.w;
+    return *this;
+}
+
+inline D3DXQUATERNION& D3DXQUATERNION::operator -= (CONST D3DXQUATERNION& quat)
+{
+    x -= quat.x;
+    y -= quat.y;
+    z -= quat.z;
+    w -= quat.w;
+    return *this;
+}
+
+/* TODO: uncomment this when D3DXQuaternionMultiply has been implemented
+inline D3DXQUATERNION& D3DXQUATERNION::operator *= (CONST D3DXQUATERNION& quat)
+{
+    D3DXQuaternionMultiply(this, this, &quat);
+    return *this;
+}
+*/
+
+inline D3DXQUATERNION& D3DXQUATERNION::operator *= (FLOAT f)
+{
+    x *= f;
+    y *= f;
+    z *= f;
+    w *= f;
+    return *this;
+}
+
+inline D3DXQUATERNION& D3DXQUATERNION::operator /= (FLOAT f)
+{
+    FLOAT inv = 1.0f / f;
+    x *= inv;
+    y *= inv;
+    z *= inv;
+    w *= inv;
+    return *this;
+}
+
+inline D3DXQUATERNION D3DXQUATERNION::operator + () const
+{
+    return *this;
+}
+
+inline D3DXQUATERNION D3DXQUATERNION::operator - () const
+{
+    return D3DXQUATERNION(-x, -y, -z, -w);
+}
+
+inline D3DXQUATERNION D3DXQUATERNION::operator + (CONST D3DXQUATERNION& quat) const
+{
+    return D3DXQUATERNION(x + quat.x, y + quat.y, z + quat.z, w + quat.w);
+}
+
+inline D3DXQUATERNION D3DXQUATERNION::operator - (CONST D3DXQUATERNION& quat) const
+{
+    return D3DXQUATERNION(x - quat.x, y - quat.y, z - quat.z, w - quat.w);
+}
+
+/* TODO: uncomment this when D3DXQuaternionMultiply has been implemented
+inline D3DXQUATERNION D3DXQUATERNION::operator * (CONST D3DXQUATERNION& quat) const
+{
+    D3DXQUATERNION buf;
+    D3DXQuaternionMultiply(&buf, this, &quat);
+    return buf;
+}
+*/
+
+inline D3DXQUATERNION D3DXQUATERNION::operator * (FLOAT f) const
+{
+    return D3DXQUATERNION(x * f, y * f, z * f, w * f);
+}
+
+inline D3DXQUATERNION D3DXQUATERNION::operator / (FLOAT f) const
+{
+    FLOAT inv = 1.0f / f;
+    return D3DXQUATERNION(x * inv, y * inv, z * inv, w * inv);
+}
+
+inline D3DXQUATERNION operator * (FLOAT f, CONST D3DXQUATERNION& quat)
+{
+    return D3DXQUATERNION(f * quat.x, f * quat.y, f * quat.z, f * quat.w);
+}
+
+inline BOOL D3DXQUATERNION::operator == (CONST D3DXQUATERNION& quat) const
+{
+    return x == quat.x && y == quat.y && z == quat.z && w == quat.w;
+}
+
+inline BOOL D3DXQUATERNION::operator != (CONST D3DXQUATERNION& quat) const
+{
+    return x != quat.x || y != quat.y || z != quat.z || w != quat.w;
+}
+
 #endif /* __cplusplus */
 
 /*_______________D3DXCOLOR_____________________*/




More information about the wine-cvs mailing list