Commit 50ae1e36 authored by David Adam's avatar David Adam Committed by Alexandre Julliard

d3dx8: Implement D3DX*Normalize.

parent 9a04b754
......@@ -9,7 +9,8 @@ EXTRALIBS = -ldxguid -luuid
C_SRCS = \
d3dx8_main.c \
d3dxbuffer.c
d3dxbuffer.c \
math.c
@MAKE_DLL_RULES@
......
@ stub D3DXVec2Normalize
@ stdcall D3DXVec2Normalize(ptr ptr)
@ stub D3DXVec2Hermite
@ stub D3DXVec2CatmullRom
@ stub D3DXVec2BaryCentric
@ stub D3DXVec2Transform
@ stub D3DXVec2TransformCoord
@ stub D3DXVec2TransformNormal
@ stub D3DXVec3Normalize
@ stdcall D3DXVec3Normalize(ptr ptr)
@ stub D3DXVec3Hermite
@ stub D3DXVec3CatmullRom
@ stub D3DXVec3BaryCentric
......@@ -15,7 +15,7 @@
@ stub D3DXVec3Project
@ stub D3DXVec3Unproject
@ stub D3DXVec4Cross
@ stub D3DXVec4Normalize
@ stdcall D3DXVec4Normalize(ptr ptr)
@ stub D3DXVec4Hermite
@ stub D3DXVec4CatmullRom
@ stub D3DXVec4BaryCentric
......@@ -53,7 +53,7 @@
@ stub D3DXQuaternionRotationAxis
@ stub D3DXQuaternionRotationYawPitchRoll
@ stub D3DXQuaternionMultiply
@ stub D3DXQuaternionNormalize
@ stdcall D3DXQuaternionNormalize(ptr ptr)
@ stub D3DXQuaternionInverse
@ stub D3DXQuaternionLn
@ stub D3DXQuaternionExp
......
/*
* Copyright 2007 David Adam
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "d3dx8.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx8);
/*_________________D3DXQUATERNION________________*/
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq)
{
FLOAT norm;
norm = D3DXQuaternionLength(pq);
if ( !norm )
{
pout->x = 0.0f;
pout->y = 0.0f;
pout->z = 0.0f;
pout->w = 0.0f;
}
else
{
pout->x = pq->x / norm;
pout->y = pq->y / norm;
pout->z = pq->z / norm;
pout->w = pq->w / norm;
}
return pout;
}
/*_________________D3DXVec2_____________________*/
D3DXVECTOR2* WINAPI D3DXVec2Normalize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv)
{
FLOAT norm;
norm = D3DXVec2Length(pv);
if ( !norm )
{
pout->x = 0.0f;
pout->y = 0.0f;
}
else
{
pout->x = pv->x / norm;
pout->y = pv->y / norm;
}
return pout;
}
/*_________________D3DXVec3_____________________*/
D3DXVECTOR3* WINAPI D3DXVec3Normalize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv)
{
FLOAT norm;
norm = D3DXVec3Length(pv);
if ( !norm )
{
pout->x = 0.0f;
pout->y = 0.0f;
pout->z = 0.0f;
}
else
{
pout->x = pv->x / norm;
pout->y = pv->y / norm;
pout->z = pv->z / norm;
}
return pout;
}
/*_________________D3DXVec4_____________________*/
D3DXVECTOR4* WINAPI D3DXVec4Normalize(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv)
{
FLOAT norm;
norm = D3DXVec4Length(pv);
if ( !norm )
{
pout->x = 0.0f;
pout->y = 0.0f;
pout->z = 0.0f;
pout->w = 0.0f;
}
else
{
pout->x = pv->x / norm;
pout->y = pv->y / norm;
pout->z = pv->z / norm;
pout->w = pv->w / norm;
}
return pout;
}
......@@ -3,7 +3,7 @@ TOPOBJDIR = ../../..
SRCDIR = @srcdir@
VPATH = @srcdir@
TESTDLL = d3dx8.dll
IMPORTS = kernel32
IMPORTS = d3dx8 kernel32
EXTRALIBS = -ldxguid
CTESTS = math.c
......
......@@ -17,8 +17,7 @@
*/
#include <assert.h>
#include "d3dx8math.h"
#include "d3dx8math.inl"
#include "d3dx8.h"
#include "wine/test.h"
......@@ -147,8 +146,6 @@ static void D3DXMatrixTest(void)
ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
}
static void D3DXPlaneTest(void)
{
D3DXPLANE plane;
......@@ -194,11 +191,12 @@ static void D3DXPlaneTest(void)
static void D3X8QuaternionTest(void)
{
D3DXQUATERNION expectedquat, gotquat, q, r, s;
D3DXQUATERNION expectedquat, gotquat, nul, q, r, s;
LPD3DXQUATERNION funcpointer;
FLOAT expected, got;
BOOL expectedbool, gotbool;
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;
......@@ -262,14 +260,24 @@ static void D3X8QuaternionTest(void)
expected=0.0f;
got = D3DXQuaternionLengthSq(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
/*_______________D3DXQuaternionNormalize________________________*/
expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
D3DXQuaternionNormalize(&gotquat,&q);
expect_vec4(expectedquat,gotquat);
/* Test the nul quaternion */
expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
D3DXQuaternionNormalize(&gotquat,&nul);
expect_vec4(expectedquat,gotquat);
}
static void D3X8Vector2Test(void)
{
D3DXVECTOR2 expectedvec, gotvec, u, v;
D3DXVECTOR2 expectedvec, gotvec, nul, u, v;
LPD3DXVECTOR2 funcpointer;
FLOAT expected, got, scale;
nul.x = 0.0f; nul.y = 0.0f;
u.x=3.0f; u.y=4.0f;
v.x=-7.0f; v.y=9.0f;
scale = -6.5f;
......@@ -347,15 +355,24 @@ static void D3X8Vector2Test(void)
ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
/*_______________D3DXVec2Minimize__________________________*/
expectedvec.x = -7.0f; expectedvec.y = 4.0f;
D3DXVec2Minimize(&gotvec,&u,&v);
expect_vec(expectedvec,gotvec);
/* Tests the case NULL */
expectedvec.x = -7.0f; expectedvec.y = 4.0f;
D3DXVec2Minimize(&gotvec,&u,&v);
expect_vec(expectedvec,gotvec);
/* Tests the case NULL */
funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
/*_______________D3DXVec2Normalize_________________________*/
expectedvec.x = 0.6f; expectedvec.y = 0.8f;
D3DXVec2Normalize(&gotvec,&u);
expect_vec(expectedvec,gotvec);
/* Test the nul vector */
expectedvec.x = 0.0f; expectedvec.y = 0.0f;
D3DXVec2Normalize(&gotvec,&nul);
expect_vec(expectedvec,gotvec);
/*_______________D3DXVec2Scale____________________________*/
expectedvec.x = -19.5f; expectedvec.y = -26.0f;
D3DXVec2Scale(&gotvec,&u,scale);
......@@ -380,10 +397,11 @@ static void D3X8Vector2Test(void)
static void D3X8Vector3Test(void)
{
D3DXVECTOR3 expectedvec, gotvec, u, v;
D3DXVECTOR3 expectedvec, gotvec, nul, u, v;
LPD3DXVECTOR3 funcpointer;
FLOAT expected, got, scale;
nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
scale = -6.5f;
......@@ -467,6 +485,15 @@ static void D3X8Vector3Test(void)
funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
/*_______________D3DXVec3Normalize_________________________*/
expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
D3DXVec3Normalize(&gotvec,&u);
expect_vec3(expectedvec,gotvec);
/* Test the nul vector */
expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
D3DXVec3Normalize(&gotvec,&nul);
expect_vec3(expectedvec,gotvec);
/*_______________D3DXVec3Scale____________________________*/
expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
D3DXVec3Scale(&gotvec,&u,scale);
......@@ -491,13 +518,14 @@ static void D3X8Vector3Test(void)
static void D3X8Vector4Test(void)
{
D3DXVECTOR4 expectedvec, gotvec, u, v;
D3DXVECTOR4 expectedvec, gotvec, nul, u, v;
LPD3DXVECTOR4 funcpointer;
FLOAT expected, got, scale;
scale = -6.5f;
nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
scale = -6.5f;
/*_______________D3DXVec4Add__________________________*/
expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
......@@ -569,6 +597,15 @@ static void D3X8Vector4Test(void)
funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
/*_______________D3DXVec4Normalize_________________________*/
expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
D3DXVec4Normalize(&gotvec,&u);
expect_vec4(expectedvec,gotvec);
/* Test the nul vector */
expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; expectedvec.w = 0.0f;
D3DXVec4Normalize(&gotvec,&nul);
expect_vec4(expectedvec,gotvec);
/*_______________D3DXVec4Scale____________________________*/
expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
D3DXVec4Scale(&gotvec,&u,scale);
......
......@@ -58,6 +58,14 @@ typedef struct D3DXCOLOR
FLOAT r, g, b, a;
} D3DXCOLOR, *LPD3DXCOLOR;
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
D3DXVECTOR2* WINAPI D3DXVec2Normalize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv);
D3DXVECTOR3* WINAPI D3DXVec3Normalize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv);
D3DXVECTOR4* WINAPI D3DXVec4Normalize(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv);
#include <d3dx8math.inl>
#endif /* __D3DX8MATH_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment