d3drm: Fix compilation on systems that don't support nameless unions.

Francois Gouget fgouget at free.fr
Sun Apr 29 19:07:42 CDT 2007


---

In particular this fixes compilation with gcc 2.95.

 dlls/d3drm/math.c         |   54 +++++++++++++++++---------------
 dlls/d3drm/tests/vector.c |   75 +++++++++++++++++++++++----------------------
 2 files changed, 66 insertions(+), 63 deletions(-)

diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c
index 0355b22..1e57cf8 100644
--- a/dlls/d3drm/math.c
+++ b/dlls/d3drm/math.c
@@ -17,6 +17,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#define NONAMELESSUNION
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -38,9 +40,9 @@ LPD3DRMQUATERNION WINAPI D3DRMQuaternionMultiply(LPD3DRMQUATERNION q, LPD3DRMQUA
     D3DVECTOR cross_product;
     D3DRMVectorCrossProduct(&cross_product, &a->v, &b->v);
     q->s = a->s * b->s - D3DRMVectorDotProduct(&a->v, &b->v);
-    q->v.x = a->s * b->v.x + b->s * a->v.x + cross_product.x;
-    q->v.y = a->s * b->v.y + b->s * a->v.y + cross_product.y;
-    q->v.z = a->s * b->v.z + b->s * a->v.z + cross_product.z;
+    q->v.u1.x = a->s * b->v.u1.x + b->s * a->v.u1.x + cross_product.u1.x;
+    q->v.u2.y = a->s * b->v.u2.y + b->s * a->v.u2.y + cross_product.u2.y;
+    q->v.u3.z = a->s * b->v.u3.z + b->s * a->v.u3.z + cross_product.u3.z;
     return q;
 }
 
@@ -49,9 +51,9 @@ void WINAPI D3DRMMatrixFromQuaternion(D3DRMMATRIX4D m, LPD3DRMQUATERNION q)
 {
     D3DVALUE w,x,y,z;
     w = q->s;
-    x = q->v.x;
-    y = q->v.y;
-    z = q->v.z;
+    x = q->v.u1.x;
+    y = q->v.u2.y;
+    z = q->v.u3.z;
     m[0][0] = 1.0-2.0*(y*y+z*z);
     m[1][1] = 1.0-2.0*(x*x+z*z);
     m[2][2] = 1.0-2.0*(x*x+y*y);
@@ -93,27 +95,27 @@ LPD3DRMQUATERNION WINAPI D3DRMQuaternionSlerp(LPD3DRMQUATERNION q, LPD3DRMQUATER
 /* Add Two Vectors */
 LPD3DVECTOR WINAPI D3DRMVectorAdd(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
 {
-    d->x=s1->x + s2->x;
-    d->y=s1->y + s2->y;
-    d->z=s1->z + s2->z;
+    d->u1.x=s1->u1.x + s2->u1.x;
+    d->u2.y=s1->u2.y + s2->u2.y;
+    d->u3.z=s1->u3.z + s2->u3.z;
     return d;
 }
 
 /* Subtract Two Vectors */
 LPD3DVECTOR WINAPI D3DRMVectorSubtract(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
 {
-    d->x=s1->x - s2->x;
-    d->y=s1->y - s2->y;
-    d->z=s1->z - s2->z;
+    d->u1.x=s1->u1.x - s2->u1.x;
+    d->u2.y=s1->u2.y - s2->u2.y;
+    d->u3.z=s1->u3.z - s2->u3.z;
     return d;
 }
 
 /* Cross Product of Two Vectors */
 LPD3DVECTOR WINAPI D3DRMVectorCrossProduct(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
 {
-    d->x=s1->y * s2->z - s1->z * s2->y;
-    d->y=s1->z * s2->x - s1->x * s2->z;
-    d->z=s1->x * s2->y - s1->y * s2->x;
+    d->u1.x=s1->u2.y * s2->u3.z - s1->u3.z * s2->u2.y;
+    d->u2.y=s1->u3.z * s2->u1.x - s1->u1.x * s2->u3.z;
+    d->u3.z=s1->u1.x * s2->u2.y - s1->u2.y * s2->u1.x;
     return d;
 }
 
@@ -121,7 +123,7 @@ LPD3DVECTOR WINAPI D3DRMVectorCrossProduct(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DV
 D3DVALUE WINAPI D3DRMVectorDotProduct(LPD3DVECTOR s1, LPD3DVECTOR s2)
 {
     D3DVALUE dot_product;
-    dot_product=s1->x * s2->x + s1->y * s2->y + s1->z * s2->z;
+    dot_product=s1->u1.x * s2->u1.x + s1->u2.y * s2->u2.y + s1->u3.z * s2->u3.z;
     return dot_product;
 }
 
@@ -129,7 +131,7 @@ D3DVALUE WINAPI D3DRMVectorDotProduct(LPD3DVECTOR s1, LPD3DVECTOR s2)
 D3DVALUE WINAPI D3DRMVectorModulus(LPD3DVECTOR v)
 {
     D3DVALUE result;
-    result=sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
+    result=sqrt(v->u1.x * v->u1.x + v->u2.y * v->u2.y + v->u3.z * v->u3.z);
     return result;
 }
 
@@ -143,9 +145,9 @@ LPD3DVECTOR WINAPI D3DRMVectorNormalize(LPD3DVECTOR u)
     }
     else
     {
-        u->x=1.0;
-        u->y=0.0;
-        u->z=0.0;
+        u->u1.x=1.0;
+        u->u2.y=0.0;
+        u->u3.z=0.0;
     }
     return u;
 }
@@ -153,9 +155,9 @@ LPD3DVECTOR WINAPI D3DRMVectorNormalize(LPD3DVECTOR u)
 /* Returns a random unit vector */
 LPD3DVECTOR WINAPI D3DRMVectorRandom(LPD3DVECTOR d)
 {
-    d->x = rand();
-    d->y = rand();
-    d->z = rand();
+    d->u1.x = rand();
+    d->u2.y = rand();
+    d->u3.z = rand();
     D3DRMVectorNormalize(d);
     return d;
 }
@@ -190,8 +192,8 @@ LPD3DVECTOR WINAPI D3DRMVectorRotate(LPD3DVECTOR r, LPD3DVECTOR v, LPD3DVECTOR a
 /* Scale a vector */
 LPD3DVECTOR WINAPI D3DRMVectorScale(LPD3DVECTOR d, LPD3DVECTOR s, D3DVALUE factor)
 {
-    d->x=factor * s->x;
-    d->y=factor * s->y;
-    d->z=factor * s->z;
+    d->u1.x=factor * s->u1.x;
+    d->u2.y=factor * s->u2.y;
+    d->u3.z=factor * s->u3.z;
     return d;
 }
diff --git a/dlls/d3drm/tests/vector.c b/dlls/d3drm/tests/vector.c
index cc16a05..e4c65ce 100644
--- a/dlls/d3drm/tests/vector.c
+++ b/dlls/d3drm/tests/vector.c
@@ -18,10 +18,11 @@
  */
 
 #include <assert.h>
-#include "wine/test.h"
 #include "d3drmdef.h"
 #include <math.h>
 
+#include "wine/test.h"
+
 #define PI (4*atan(1.0))
 #define admit_error 0.000001
 
@@ -51,40 +52,40 @@
 }
 
 #define expect_quat(expectedquat,gotquat) \
-  ok( (fabs(expectedquat.v.x-gotquat.v.x)<admit_error) && \
-      (fabs(expectedquat.v.y-gotquat.v.y)<admit_error) && \
-      (fabs(expectedquat.v.z-gotquat.v.z)<admit_error) && \
+  ok( (fabs(U1(expectedquat.v).x-U1(gotquat.v).x)<admit_error) &&     \
+      (fabs(U2(expectedquat.v).y-U2(gotquat.v).y)<admit_error) &&     \
+      (fabs(U3(expectedquat.v).z-U3(gotquat.v).z)<admit_error) &&     \
       (fabs(expectedquat.s-gotquat.s)<admit_error), \
   "Expected Quaternion %f %f %f %f , Got Quaternion %f %f %f %f\n", \
-  expectedquat.s,expectedquat.v.x,expectedquat.v.y,expectedquat.v.z, \
-  gotquat.s,gotquat.v.x,gotquat.v.y,gotquat.v.z);
+      expectedquat.s,U1(expectedquat.v).x,U2(expectedquat.v).y,U3(expectedquat.v).z, \
+      gotquat.s,U1(gotquat.v).x,U2(gotquat.v).y,U3(gotquat.v).z);
 
 #define expect_vec(expectedvec,gotvec) \
-  ok( ((fabs(expectedvec.x-gotvec.x)<admit_error)&&(fabs(expectedvec.y-gotvec.y)<admit_error)&&(fabs(expectedvec.z-gotvec.z)<admit_error)), \
+  ok( ((fabs(U1(expectedvec).x-U1(gotvec).x)<admit_error)&&(fabs(U2(expectedvec).y-U2(gotvec).y)<admit_error)&&(fabs(U3(expectedvec).z-U3(gotvec).z)<admit_error)), \
   "Expected Vector= (%f, %f, %f)\n , Got Vector= (%f, %f, %f)\n", \
-  expectedvec.x,expectedvec.y,expectedvec.z, gotvec.x, gotvec.y, gotvec.z);
+  U1(expectedvec).x,U2(expectedvec).y,U3(expectedvec).z, U1(gotvec).x, U2(gotvec).y, U3(gotvec).z);
 
 static void VectorTest(void)
 {
     D3DVALUE mod,par,theta;
     D3DVECTOR e,r,u,v,w,axis,casnul,norm,ray;
 
-    u.x=2.0;u.y=2.0;u.z=1.0;
-    v.x=4.0;v.y=4.0;v.z=0.0;
+    U1(u).x=2.0;U2(u).y=2.0;U3(u).z=1.0;
+    U1(v).x=4.0;U2(v).y=4.0;U3(v).z=0.0;
 
 /*______________________VectorAdd_________________________________*/
     D3DRMVectorAdd(&r,&u,&v);
-    e.x=6.0;e.y=6.0;e.z=1.0;
+    U1(e).x=6.0;U2(e).y=6.0;U3(e).z=1.0;
     expect_vec(e,r);
 
 /*_______________________VectorSubtract__________________________*/
     D3DRMVectorSubtract(&r,&u,&v);
-    e.x=-2.0;e.y=-2.0;e.z=1.0;
+    U1(e).x=-2.0;U2(e).y=-2.0;U3(e).z=1.0;
     expect_vec(e,r);
 
 /*_______________________VectorCrossProduct_______________________*/
     D3DRMVectorCrossProduct(&r,&u,&v);
-    e.x=-4.0;e.y=4.0;e.z=0.0;
+    U1(e).x=-4.0;U2(e).y=4.0;U3(e).z=0.0;
     expect_vec(e,r);
 
 /*_______________________VectorDotProduct__________________________*/
@@ -97,41 +98,41 @@ static void VectorTest(void)
 
 /*_______________________VectorNormalize___________________________*/
     D3DRMVectorNormalize(&u);
-    e.x=2.0/3.0;e.y=2.0/3.0;e.z=1.0/3.0;
+    U1(e).x=2.0/3.0;U2(e).y=2.0/3.0;U3(e).z=1.0/3.0;
     expect_vec(e,u);
 
 /* If u is the NULL vector, MSDN says that the return vector is NULL. In fact, the returned vector is (1,0,0). The following test case prove it. */
 
-    casnul.x=0.0; casnul.y=0.0; casnul.z=0.0;
+    U1(casnul).x=0.0; U2(casnul).y=0.0; U3(casnul).z=0.0;
     D3DRMVectorNormalize(&casnul);
-    e.x=1.0; e.y=0.0; e.z=0.0;
+    U1(e).x=1.0; U2(e).y=0.0; U3(e).z=0.0;
     expect_vec(e,casnul);
 
 /*____________________VectorReflect_________________________________*/
-    ray.x=3.0; ray.y=-4.0; ray.z=5.0;
-    norm.x=1.0; norm.y=-2.0; norm.z=6.0;
-    e.x=79.0; e.y=-160.0; e.z=487.0;
+    U1(ray).x=3.0; U2(ray).y=-4.0; U3(ray).z=5.0;
+    U1(norm).x=1.0; U2(norm).y=-2.0; U3(norm).z=6.0;
+    U1(e).x=79.0; U2(e).y=-160.0; U3(e).z=487.0;
     D3DRMVectorReflect(&r,&ray,&norm);
     expect_vec(e,r);
 
 /*_______________________VectorRotate_______________________________*/
-    w.x=3.0;w.y=4.0;w.z=0.0;
-    axis.x=0.0;axis.y=0.0;axis.z=1.0;
+    U1(w).x=3.0; U2(w).y=4.0; U3(w).z=0.0;
+    U1(axis).x=0.0; U2(axis).y=0.0; U3(axis).z=1.0;
     theta=2.0*PI/3.0;
     D3DRMVectorRotate(&r,&w,&axis,theta);
-    e.x=-0.3-0.4*sqrt(3.0); e.y=0.3*sqrt(3.0)-0.4; e.z=0.0;
+    U1(e).x=-0.3-0.4*sqrt(3.0); U2(e).y=0.3*sqrt(3.0)-0.4; U3(e).z=0.0;
     expect_vec(e,r);
 
 /* The same formula gives D3DRMVectorRotate, for theta in [-PI/2;+PI/2] or not. The following test proves this fact.*/
     theta=-PI/4.0;
     D3DRMVectorRotate(&r,&w,&axis,-PI/4);
-    e.x=1.4/sqrt(2.0); e.y=0.2/sqrt(2.0); e.z=0.0;
+    U1(e).x=1.4/sqrt(2.0); U2(e).y=0.2/sqrt(2.0); U3(e).z=0.0;
     expect_vec(e,r);
 
 /*_______________________VectorScale__________________________*/
     par=2.5;
     D3DRMVectorScale(&r,&v,par);
-    e.x=10.0; e.y=10.0; e.z=0.0;
+    U1(e).x=10.0; U2(e).y=10.0; U3(e).z=0.0;
     expect_vec(e,r);
 }
 
@@ -144,7 +145,7 @@ static void MatrixTest(void)
     exp[1][0]=20.0;  exp[1][1]=-39.0; exp[1][2]=20.0;  exp[1][3]=0.0;
     exp[2][0]=10.0;  exp[2][1]=28.0;  exp[2][2]=-25.0; exp[2][3]=0.0;
     exp[3][0]=0.0;   exp[3][1]=0.0;   exp[3][2]=0.0;   exp[3][3]=1.0;
-    q.s=1.0; q.v.x=2.0; q.v.y=3.0; q.v.z=4.0;
+    q.s=1.0; U1(q.v).x=2.0; U2(q.v).y=3.0; U3(q.v).z=4.0;
 
    D3DRMMatrixFromQuaternion(mat,&q);
    expect_mat(exp,mat);
@@ -157,10 +158,10 @@ static void QuaternionTest(void)
     D3DRMQUATERNION q,q1,q2,r;
 
 /*_________________QuaternionFromRotation___________________*/
-    axis.x=1.0;axis.y=1.0;axis.z=1.0;
+    U1(axis).x=1.0; U2(axis).y=1.0; U3(axis).z=1.0;
     theta=2.0*PI/3.0;
     D3DRMQuaternionFromRotation(&r,&axis,theta);
-    q.s=0.5;q.v.x=0.5;q.v.y=0.5;q.v.z=0.5;
+    q.s=0.5; U1(q.v).x=0.5; U2(q.v).y=0.5; U3(q.v).z=0.5;
     expect_quat(q,r);
 
 /*_________________QuaternionSlerp_________________________*/
@@ -169,28 +170,28 @@ static void QuaternionTest(void)
  * interpolates between the first quaternion and the opposite of the second one. The test proves
  * these two facts. */
     par=0.31;
-    q1.s=1.0; q1.v.x=2.0; q1.v.y=3.0; q1.v.z=50.0;
-    q2.s=-4.0; q2.v.x=6.0; q2.v.y=7.0; q2.v.z=8.0;
+    q1.s=1.0; U1(q1.v).x=2.0; U2(q1.v).y=3.0; U3(q1.v).z=50.0;
+    q2.s=-4.0; U1(q2.v).x=6.0; U2(q2.v).y=7.0; U3(q2.v).z=8.0;
 /* The angle between q1 and q2 is in [-PI/2,PI/2]. So, one interpolates between q1 and q2. */
     epsilon=1.0;
     g=1.0-par; h=epsilon*par;
 /* Part of the test proving that the interpolation is linear. */
     q.s=g*q1.s+h*q2.s;
-    q.v.x=g*q1.v.x+h*q2.v.x;
-    q.v.y=g*q1.v.y+h*q2.v.y;
-    q.v.z=g*q1.v.z+h*q2.v.z;
+    U1(q.v).x=g*U1(q1.v).x+h*U1(q2.v).x;
+    U2(q.v).y=g*U2(q1.v).y+h*U2(q2.v).y;
+    U3(q.v).z=g*U3(q1.v).z+h*U3(q2.v).z;
     D3DRMQuaternionSlerp(&r,&q1,&q2,par);
     expect_quat(q,r);
 
-    q1.s=1.0; q1.v.x=2.0; q1.v.y=3.0; q1.v.z=50.0;
-    q2.s=-94.0; q2.v.x=6.0; q2.v.y=7.0; q2.v.z=-8.0;
+    q1.s=1.0; U1(q1.v).x=2.0; U2(q1.v).y=3.0; U3(q1.v).z=50.0;
+    q2.s=-94.0; U1(q2.v).x=6.0; U2(q2.v).y=7.0; U3(q2.v).z=-8.0;
 /* The angle between q1 and q2 is not in [-PI/2,PI/2]. So, one interpolates between q1 and -q2. */
     epsilon=-1.0;
     g=1.0-par; h=epsilon*par;
     q.s=g*q1.s+h*q2.s;
-    q.v.x=g*q1.v.x+h*q2.v.x;
-    q.v.y=g*q1.v.y+h*q2.v.y;
-    q.v.z=g*q1.v.z+h*q2.v.z;
+    U1(q.v).x=g*U1(q1.v).x+h*U1(q2.v).x;
+    U2(q.v).y=g*U2(q1.v).y+h*U2(q2.v).y;
+    U3(q.v).z=g*U3(q1.v).z+h*U3(q2.v).z;
     D3DRMQuaternionSlerp(&r,&q1,&q2,par);
     expect_quat(q,r);
 }
-- 
1.4.4.4



More information about the wine-patches mailing list