Nozomi Kodama : d3dx9_36: D3DXQuaternionLn computes as if the norm of the input is 1.

Alexandre Julliard julliard at winehq.org
Wed Jun 13 16:08:33 CDT 2012


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

Author: Nozomi Kodama <Nozomi.Kodama at yahoo.com>
Date:   Tue Jun 12 08:13:39 2012 +0800

d3dx9_36: D3DXQuaternionLn computes as if the norm of the input is 1.

---

 dlls/d3dx9_36/math.c       |   33 ++++++++++++---------------------
 dlls/d3dx9_36/tests/math.c |   19 ++++++++++++++++---
 2 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c
index 10a6cb9..5c6530a 100644
--- a/dlls/d3dx9_36/math.c
+++ b/dlls/d3dx9_36/math.c
@@ -1215,29 +1215,20 @@ D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3DXQUA
 
 D3DXQUATERNION* WINAPI D3DXQuaternionLn(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq)
 {
-    FLOAT norm, normvec, theta;
+    FLOAT t;
 
-    norm = D3DXQuaternionLengthSq(pq);
-    if ( norm > 1.0001f )
-    {
-     pout->x = pq->x;
-     pout->y = pq->y;
-     pout->z = pq->z;
-     pout->w = 0.0f;
-    }
-    else if( norm > 0.99999f)
-    {
-     normvec = sqrt( pq->x * pq->x + pq->y * pq->y + pq->z * pq->z );
-     theta = atan2(normvec, pq->w) / normvec;
-     pout->x = theta * pq->x;
-     pout->y = theta * pq->y;
-     pout->z = theta * pq->z;
-     pout->w = 0.0f;
-    }
+    TRACE("(%p, %p)\n", pout, pq);
+
+    if ( (pq->w >= 1.0f) || (pq->w == -1.0f) )
+        t = 1.0f;
     else
-    {
-     FIXME("The quaternion (%f, %f, %f, %f) has a norm <1. This should not happen. Windows returns a result anyway. This case is not implemented yet.\n", pq->x, pq->y, pq->z, pq->w);
-    }
+        t = acos( pq->w ) / sqrt( 1.0f - pq->w * pq->w );
+
+    pout->x = t * pq->x;
+    pout->y = t * pq->y;
+    pout->z = t * pq->z;
+    pout->w = 0.0f;
+
     return pout;
 }
 
diff --git a/dlls/d3dx9_36/tests/math.c b/dlls/d3dx9_36/tests/math.c
index 61f8567..c93044d 100644
--- a/dlls/d3dx9_36/tests/math.c
+++ b/dlls/d3dx9_36/tests/math.c
@@ -746,11 +746,24 @@ static void D3DXQuaternionTest(void)
     expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
     D3DXQuaternionLn(&gotquat,&Nq);
     expect_vec4(expectedquat,gotquat);
-    /* Test the cas where the norm of the quaternion is <1 */
-    Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
+    Nq.x = 0.0f; Nq.y = 0.0f; Nq.z = 0.0f; Nq.w = 1.0f;
+    expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
+    D3DXQuaternionLn(&gotquat,&Nq);
+    expect_vec4(expectedquat,gotquat);
+    Nq.x = 5.4f; Nq.y = 1.2f; Nq.z = -0.3f; Nq.w = -0.3f;
+    expectedquat.x = 10.616652f; expectedquat.y = 2.359256f; expectedquat.z = -0.589814f; expectedquat.w = 0.0f;
+    D3DXQuaternionLn(&gotquat,&Nq);
+    expect_vec4(expectedquat,gotquat);
+    /* Test the case where the norm of the quaternion is <1 */
+    Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = 0.9f;
     expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
     D3DXQuaternionLn(&gotquat,&Nq1);
-    todo_wine{ expect_vec4(expectedquat,gotquat) };
+    expect_vec4(expectedquat,gotquat);
+    /* Test the case where the real part of the quaternion is -1.0f */
+    Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = -1.0f;
+    expectedquat.x = 0.2f; expectedquat.y = 0.1f; expectedquat.z = 0.3f; expectedquat.w = 0.0f;
+    D3DXQuaternionLn(&gotquat,&Nq1);
+    expect_vec4(expectedquat,gotquat);
 
 /*_______________D3DXQuaternionMultiply________________________*/
     expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;




More information about the wine-cvs mailing list