David Adam : d3dx8: Implement the spherical interpolation part for D3DXQuaternionSlerp.
Alexandre Julliard
julliard at winehq.org
Mon Feb 16 09:35:42 CST 2009
Module: wine
Branch: master
Commit: 2347862571f20e13278649a6bd8fc49ce3b2a448
URL: http://source.winehq.org/git/wine.git/?a=commit;h=2347862571f20e13278649a6bd8fc49ce3b2a448
Author: David Adam <david.adam.cnrs at gmail.com>
Date: Sat Feb 14 14:56:27 2009 +0100
d3dx8: Implement the spherical interpolation part for D3DXQuaternionSlerp.
---
dlls/d3dx8/math.c | 24 ++++++++++++++++++------
dlls/d3dx8/tests/math.c | 9 +++++++--
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 54f5afb..34f6fed 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -1173,15 +1173,27 @@ D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION *pout,
D3DXQUATERNION* WINAPI D3DXQuaternionSlerp(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, FLOAT t)
{
- FLOAT dot, epsilon;
+ FLOAT dot, epsilon, temp, theta, u;
epsilon = 1.0f;
+ temp = 1.0f - t;
+ u = t;
dot = D3DXQuaternionDot(pq1, pq2);
- if ( dot < 0.0f) epsilon = -1.0f;
- pout->x = (1.0f - t) * pq1->x + epsilon * t * pq2->x;
- pout->y = (1.0f - t) * pq1->y + epsilon * t * pq2->y;
- pout->z = (1.0f - t) * pq1->z + epsilon * t * pq2->z;
- pout->w = (1.0f - t) * pq1->w + epsilon * t * pq2->w;
+ if ( dot < 0.0f )
+ {
+ epsilon = -1.0f;
+ dot = -dot;
+ }
+ if( 1.0f - dot > 0.001f )
+ {
+ theta = acos(dot);
+ temp = sin(theta * temp) / sin(theta);
+ u = sin(theta * u) / sin(theta);
+ }
+ pout->x = temp * pq1->x + epsilon * u * pq2->x;
+ pout->y = temp * pq1->y + epsilon * u * pq2->y;
+ pout->z = temp * pq1->z + epsilon * u * pq2->z;
+ pout->w = temp * pq1->w + epsilon * u * pq2->w;
return pout;
}
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 6a7f99d..ec05fad 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -582,7 +582,7 @@ static void D3DXPlaneTest(void)
static void D3X8QuaternionTest(void)
{
D3DXMATRIX mat;
- D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, q, r, s, t, u;
+ D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, smallq, smallr, q, r, s, t, u;
LPD3DXQUATERNION funcpointer;
D3DXVECTOR3 axis, expectedvec;
FLOAT angle, expected, got, scale, scale2;
@@ -591,8 +591,10 @@ static void D3X8QuaternionTest(void)
nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
- t.x = -1111.0f, t.y= 111.0f; t.z = -11.0f; t.w = 1.0f;
+ t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
+ smallq.x = 0.1f; smallq.y = 0.2f; smallq.z= 0.3f; smallq.w = 0.4f;
+ smallr.x = 0.5f; smallr.y = 0.6f; smallr.z= 0.7f; smallq.w = 0.8f;
scale = 0.3f;
scale2 = 0.78f;
@@ -873,6 +875,9 @@ static void D3X8QuaternionTest(void)
expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
expect_vec4(expectedquat,gotquat);
+ expectedquat.x = 0.267071f; expectedquat.y = 0.384114f; expectedquat.z = 0.501157f; expectedquat.w = 0.636291f;
+ D3DXQuaternionSlerp(&gotquat,&smallq,&smallr,scale);
+ expect_vec4(expectedquat,gotquat);
/*_______________D3DXQuaternionSquad________________________*/
expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
More information about the wine-cvs
mailing list