Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
d1c2d2a4
Commit
d1c2d2a4
authored
Jul 11, 2009
by
David Adam
Committed by
Alexandre Julliard
Jul 13, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d3dx9: Merge d3dx8 math into d3dx9.
parent
35ada0dc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1691 additions
and
201 deletions
+1691
-201
d3dx9_36.spec
dlls/d3dx9_36/d3dx9_36.spec
+72
-72
d3dx9_36_private.h
dlls/d3dx9_36/d3dx9_36_private.h
+13
-0
math.c
dlls/d3dx9_36/math.c
+1537
-129
d3dx9math.h
include/d3dx9math.h
+69
-0
No files found.
dlls/d3dx9_36/d3dx9_36.spec
View file @
d1c2d2a4
...
...
@@ -9,8 +9,8 @@
@ stdcall D3DXCheckVersion(long long)
@ stub D3DXCheckVolumeTextureRequirements
@ stub D3DXCleanMesh
@ stdcall D3DXColorAdjustContrast(ptr ptr long)
d3dx8.D3DXColorAdjustContrast
@ stdcall D3DXColorAdjustSaturation(ptr ptr long)
d3dx8.D3DXColorAdjustSaturation
@ stdcall D3DXColorAdjustContrast(ptr ptr long)
@ stdcall D3DXColorAdjustSaturation(ptr ptr long)
@ stub D3DXCompileShader
@ stub D3DXCompileShaderFromFileA
@ stub D3DXCompileShaderFromFileW
...
...
@@ -70,7 +70,7 @@
@ stub D3DXCreateFragmentLinkerEx
@ stub D3DXCreateKeyframedAnimationSet
@ stub D3DXCreateLine
@ stdcall D3DXCreateMatrixStack(long ptr)
d3dx8.D3DXCreateMatrixStack
@ stdcall D3DXCreateMatrixStack(long ptr)
@ stub D3DXCreateMesh
@ stub D3DXCreateMeshFVF
@ stub D3DXCreateNPatchMesh
...
...
@@ -138,7 +138,7 @@
@ stub D3DXFrameFind
@ stub D3DXFrameNumNamedMatrices
@ stub D3DXFrameRegisterNamedMatrices
@ stdcall D3DXFresnelTerm(long long)
d3dx8.D3DXFresnelTerm
@ stdcall D3DXFresnelTerm(long long)
@ stub D3DXFVFFromDeclarator
@ stub D3DXGatherFragments
@ stub D3DXGatherFragmentsFromFileA
...
...
@@ -196,64 +196,64 @@
@ stub D3DXLoadVolumeFromResourceA
@ stub D3DXLoadVolumeFromResourceW
@ stub D3DXLoadVolumeFromVolume
@ stdcall D3DXMatrixAffineTransformation(ptr long ptr ptr ptr)
d3dx8.D3DXMatrixAffineTransformation
@ stdcall D3DXMatrixAffineTransformation(ptr long ptr ptr ptr)
@ stdcall D3DXMatrixAffineTransformation2D(ptr long ptr long ptr)
@ stdcall D3DXMatrixDecompose(ptr ptr ptr ptr)
@ stdcall D3DXMatrixDeterminant(ptr)
d3dx8.D3DXMatrixfDeterminant
@ stdcall D3DXMatrixInverse(ptr ptr ptr)
d3dx8.D3DXMatrixInverse
@ stdcall D3DXMatrixLookAtLH(ptr ptr ptr ptr)
d3dx8.D3DXMatrixLookAtLH
@ stdcall D3DXMatrixLookAtRH(ptr ptr ptr ptr)
d3dx8.D3DXMatrixLookAtRH
@ stdcall D3DXMatrixMultiply(ptr ptr ptr)
d3dx8.D3DXMatrixMultiply
@ stdcall D3DXMatrixMultiplyTranspose(ptr ptr ptr)
d3dx8.D3DXMatrixMultiplyTranspose
@ stdcall D3DXMatrixOrthoLH(ptr long long long long)
d3dx8.D3DXMatrixOrthoLH
@ stdcall D3DXMatrixOrthoOffCenterLH(ptr long long long long long long)
d3dx8.D3DXMatrixOrthoOffCenterLH
@ stdcall D3DXMatrixOrthoOffCenterRH(ptr long long long long long long)
d3dx8.D3DXMatrixOrthoOffCenterRH
@ stdcall D3DXMatrixOrthoRH(ptr long long long long)
d3dx8.D3DXMatrixOrthoRH
@ stdcall D3DXMatrixPerspectiveFovLH(ptr long long long long)
d3dx8.D3DXMatrixPerspectiveFovLH
@ stdcall D3DXMatrixPerspectiveFovRH(ptr long long long long)
d3dx8.D3DXMatrixPerspectiveFovRH
@ stdcall D3DXMatrixPerspectiveLH(ptr long long long long)
d3dx8.D3DXMatrixPerspectiveLH
@ stdcall D3DXMatrixPerspectiveOffCenterLH(ptr long long long long long long)
d3dx8.D3DXMatrixPerspectiveOffCenterLH
@ stdcall D3DXMatrixPerspectiveOffCenterRH(ptr long long long long long long)
d3dx8.D3DXMatrixPerspectiveOffCenterRH
@ stdcall D3DXMatrixPerspectiveRH(ptr long long long long)
d3dx8.D3DXMatrixPerspectiveRH
@ stdcall D3DXMatrixReflect(ptr ptr)
d3dx8.D3DXMatrixReflect
@ stdcall D3DXMatrixRotationAxis(ptr ptr long)
d3dx8.D3DXMatrixRotationAxis
@ stdcall D3DXMatrixRotationQuaternion(ptr ptr)
d3dx8.D3DXMatrixRotationQuaternion
@ stdcall D3DXMatrixRotationX(ptr long)
d3dx8.D3DXMatrixRotationX
@ stdcall D3DXMatrixRotationY(ptr long)
d3dx8.D3DXMatrixRotationY
@ stdcall D3DXMatrixRotationYawPitchRoll(ptr long long long)
d3dx8.D3DXMatrixRotationYawPitchRoll
@ stdcall D3DXMatrixRotationZ(ptr long)
d3dx8.D3DXMatrixRotationZ
@ stdcall D3DXMatrixScaling(ptr long long long)
d3dx8.D3DXMatrixScaling
@ stdcall D3DXMatrixShadow(ptr ptr ptr)
d3dx8.D3DXMatrixShadow
@ stdcall D3DXMatrixTransformation(ptr ptr ptr ptr ptr ptr ptr)
d3dx8.D3DXMatrixTransformation
@ stdcall D3DXMatrixDeterminant(ptr)
@ stdcall D3DXMatrixInverse(ptr ptr ptr)
@ stdcall D3DXMatrixLookAtLH(ptr ptr ptr ptr)
@ stdcall D3DXMatrixLookAtRH(ptr ptr ptr ptr)
@ stdcall D3DXMatrixMultiply(ptr ptr ptr)
@ stdcall D3DXMatrixMultiplyTranspose(ptr ptr ptr)
@ stdcall D3DXMatrixOrthoLH(ptr long long long long)
@ stdcall D3DXMatrixOrthoOffCenterLH(ptr long long long long long long)
@ stdcall D3DXMatrixOrthoOffCenterRH(ptr long long long long long long)
@ stdcall D3DXMatrixOrthoRH(ptr long long long long)
@ stdcall D3DXMatrixPerspectiveFovLH(ptr long long long long)
@ stdcall D3DXMatrixPerspectiveFovRH(ptr long long long long)
@ stdcall D3DXMatrixPerspectiveLH(ptr long long long long)
@ stdcall D3DXMatrixPerspectiveOffCenterLH(ptr long long long long long long)
@ stdcall D3DXMatrixPerspectiveOffCenterRH(ptr long long long long long long)
@ stdcall D3DXMatrixPerspectiveRH(ptr long long long long)
@ stdcall D3DXMatrixReflect(ptr ptr)
@ stdcall D3DXMatrixRotationAxis(ptr ptr long)
@ stdcall D3DXMatrixRotationQuaternion(ptr ptr)
@ stdcall D3DXMatrixRotationX(ptr long)
@ stdcall D3DXMatrixRotationY(ptr long)
@ stdcall D3DXMatrixRotationYawPitchRoll(ptr long long long)
@ stdcall D3DXMatrixRotationZ(ptr long)
@ stdcall D3DXMatrixScaling(ptr long long long)
@ stdcall D3DXMatrixShadow(ptr ptr ptr)
@ stdcall D3DXMatrixTransformation(ptr ptr ptr ptr ptr ptr ptr)
@ stdcall D3DXMatrixTransformation2D(ptr ptr long ptr ptr long ptr)
@ stdcall D3DXMatrixTranslation(ptr long long long)
d3dx8.D3DXMatrixTranslation
@ stdcall D3DXMatrixTranspose(ptr ptr)
d3dx8.D3DXMatrixTranspose
@ stdcall D3DXMatrixTranslation(ptr long long long)
@ stdcall D3DXMatrixTranspose(ptr ptr)
@ stub D3DXOptimizeFaces
@ stub D3DXOptimizeVertices
@ stdcall D3DXPlaneFromPointNormal(ptr ptr ptr)
d3dx8.D3DXPlaneFromPointNormal
@ stdcall D3DXPlaneFromPoints(ptr ptr ptr ptr)
d3dx8.D3DXPlaneFromPoints
@ stdcall D3DXPlaneIntersectLine(ptr ptr ptr ptr)
d3dx8.D3DXPlaneIntersectLine
@ stdcall D3DXPlaneNormalize(ptr ptr)
d3dx8.D3DXPlaneNormalize
@ stdcall D3DXPlaneTransform(ptr ptr ptr)
d3dx8.D3DXPlaneTransform
@ stdcall D3DXPlaneFromPointNormal(ptr ptr ptr)
@ stdcall D3DXPlaneFromPoints(ptr ptr ptr ptr)
@ stdcall D3DXPlaneIntersectLine(ptr ptr ptr ptr)
@ stdcall D3DXPlaneNormalize(ptr ptr)
@ stdcall D3DXPlaneTransform(ptr ptr ptr)
@ stdcall D3DXPlaneTransformArray(ptr long ptr long ptr long)
@ stub D3DXPreprocessShader
@ stub D3DXPreprocessShaderFromFileA
@ stub D3DXPreprocessShaderFromFileW
@ stub D3DXPreprocessShaderFromResourceA
@ stub D3DXPreprocessShaderFromResourceW
@ stdcall D3DXQuaternionBaryCentric(ptr ptr ptr ptr long long)
d3dx8.D3DXQuaternionBaryCentric
@ stdcall D3DXQuaternionExp(ptr ptr)
d3dx8.D3DXQuaternionExp
@ stdcall D3DXQuaternionInverse(ptr ptr)
d3dx8.D3DXQuaternionInverse
@ stdcall D3DXQuaternionLn(ptr ptr)
d3dx8.D3DXQuaternionLn
@ stdcall D3DXQuaternionMultiply(ptr ptr ptr)
d3dx8.D3DXQuaternionMultiply
@ stdcall D3DXQuaternionNormalize(ptr ptr)
d3dx8.D3DXQuaternionNormalize
@ stdcall D3DXQuaternionRotationAxis(ptr ptr long)
d3dx8.D3DXQuaternionRotationAxis
@ stdcall D3DXQuaternionRotationMatrix(ptr ptr)
d3dx8.D3DXQuaternionRotationMatrix
@ stdcall D3DXQuaternionRotationYawPitchRoll(ptr long long long)
d3dx8.D3DXQuaternionRotationYawPitchRoll
@ stdcall D3DXQuaternionSlerp(ptr ptr ptr long)
d3dx8.D3DXQuaternionSlerp
@ stdcall D3DXQuaternionSquad(ptr ptr ptr ptr ptr long)
d3dx8.D3DXQuaternionSquad
@ stdcall D3DXQuaternionBaryCentric(ptr ptr ptr ptr long long)
@ stdcall D3DXQuaternionExp(ptr ptr)
@ stdcall D3DXQuaternionInverse(ptr ptr)
@ stdcall D3DXQuaternionLn(ptr ptr)
@ stdcall D3DXQuaternionMultiply(ptr ptr ptr)
@ stdcall D3DXQuaternionNormalize(ptr ptr)
@ stdcall D3DXQuaternionRotationAxis(ptr ptr long)
@ stdcall D3DXQuaternionRotationMatrix(ptr ptr)
@ stdcall D3DXQuaternionRotationYawPitchRoll(ptr long long long)
@ stdcall D3DXQuaternionSlerp(ptr ptr ptr long)
@ stdcall D3DXQuaternionSquad(ptr ptr ptr ptr ptr long)
@ stdcall D3DXQuaternionSquadSetup(ptr ptr ptr ptr ptr ptr ptr) d3dx8.D3DXQuaternionSquadSetup
@ stdcall D3DXQuaternionToAxisAngle(ptr ptr ptr)
d3dx8.D3DXQuaternionToAxisAngle
@ stdcall D3DXQuaternionToAxisAngle(ptr ptr ptr)
@ stub D3DXRectPatchSize
@ stub D3DXSaveMeshHierarchyToFileA
@ stub D3DXSaveMeshHierarchyToFileW
...
...
@@ -302,35 +302,35 @@
@ stub D3DXUVAtlasPartition
@ stdcall D3DXValidMesh(ptr ptr ptr) d3dx8.D3DXValidMesh
@ stub D3DXValidPatchMesh
@ stdcall D3DXVec2BaryCentric(ptr ptr ptr ptr long long)
d3dx8.D3DXVec2BaryCentric
@ stdcall D3DXVec2CatmullRom(ptr ptr ptr ptr ptr long)
d3dx8.D3DXVec2CatmullRom
@ stdcall D3DXVec2Hermite(ptr ptr ptr ptr ptr long)
d3dx8.D3DXVec2Hermite
@ stdcall D3DXVec2Normalize(ptr ptr)
d3dx8.D3DXVec2Normalize
@ stdcall D3DXVec2Transform(ptr ptr ptr)
d3dx8.D3DXVec2Transform
@ stdcall D3DXVec2BaryCentric(ptr ptr ptr ptr long long)
@ stdcall D3DXVec2CatmullRom(ptr ptr ptr ptr ptr long)
@ stdcall D3DXVec2Hermite(ptr ptr ptr ptr ptr long)
@ stdcall D3DXVec2Normalize(ptr ptr)
@ stdcall D3DXVec2Transform(ptr ptr ptr)
@ stdcall D3DXVec2TransformArray(ptr long ptr long ptr long)
@ stdcall D3DXVec2TransformCoord(ptr ptr ptr)
d3dx8.D3DXVec2TransformCoord
@ stdcall D3DXVec2TransformCoord(ptr ptr ptr)
@ stdcall D3DXVec2TransformCoordArray(ptr long ptr long ptr long)
@ stdcall D3DXVec2TransformNormal(ptr ptr ptr)
d3dx8.D3DXVec2TransformNormal
@ stdcall D3DXVec2TransformNormal(ptr ptr ptr)
@ stdcall D3DXVec2TransformNormalArray(ptr long ptr long ptr long)
@ stdcall D3DXVec3BaryCentric(ptr ptr ptr ptr long long)
d3dx8.D3DXVec3BaryCentric
@ stdcall D3DXVec3CatmullRom(ptr ptr ptr ptr ptr long)
d3dx8.D3DXVec3CatmullRom
@ stdcall D3DXVec3Hermite(ptr ptr ptr ptr ptr long)
d3dx8.D3DXVec3Hermite
@ stdcall D3DXVec3Normalize(ptr ptr)
d3dx8.D3DXVec3Normalize
@ stdcall D3DXVec3Project(ptr ptr ptr ptr ptr ptr)
d3dx8.D3DXVec3Project
@ stdcall D3DXVec3BaryCentric(ptr ptr ptr ptr long long)
@ stdcall D3DXVec3CatmullRom(ptr ptr ptr ptr ptr long)
@ stdcall D3DXVec3Hermite(ptr ptr ptr ptr ptr long)
@ stdcall D3DXVec3Normalize(ptr ptr)
@ stdcall D3DXVec3Project(ptr ptr ptr ptr ptr ptr)
@ stdcall D3DXVec3ProjectArray(ptr long ptr long ptr ptr ptr ptr long)
@ stdcall D3DXVec3Transform(ptr ptr ptr)
d3dx8.D3DXVec3Transform
@ stdcall D3DXVec3Transform(ptr ptr ptr)
@ stdcall D3DXVec3TransformArray(ptr long ptr long ptr long)
@ stdcall D3DXVec3TransformCoord(ptr ptr ptr)
d3dx8.D3DXVec3TransformCoord
@ stdcall D3DXVec3TransformCoord(ptr ptr ptr)
@ stdcall D3DXVec3TransformCoordArray(ptr long ptr long ptr long)
@ stdcall D3DXVec3TransformNormal(ptr ptr ptr)
d3dx8.D3DXVec3TransformNormal
@ stdcall D3DXVec3TransformNormal(ptr ptr ptr)
@ stdcall D3DXVec3TransformNormalArray(ptr long ptr long ptr long)
@ stdcall D3DXVec3Unproject(ptr ptr ptr ptr ptr ptr)
d3dx8.D3DXVec3Unproject
@ stdcall D3DXVec3Unproject(ptr ptr ptr ptr ptr ptr)
@ stdcall D3DXVec3UnprojectArray(ptr long ptr long ptr ptr ptr ptr long)
@ stdcall D3DXVec4BaryCentric(ptr ptr ptr ptr long long)
d3dx8.D3DXVec4BaryCentric
@ stdcall D3DXVec4CatmullRom(ptr ptr ptr ptr ptr long)
d3dx8.D3DXVec4CatmullRom
@ stdcall D3DXVec4Cross(ptr ptr ptr ptr)
d3dx8.D3DXVec4Cross
@ stdcall D3DXVec4Hermite(ptr ptr ptr ptr ptr long)
d3dx8.D3DXVec4Hermite
@ stdcall D3DXVec4Normalize(ptr ptr)
d3dx8.D3DXVec4Normalize
@ stdcall D3DXVec4Transform(ptr ptr ptr)
d3dx8.D3DXVec4Transform
@ stdcall D3DXVec4BaryCentric(ptr ptr ptr ptr long long)
@ stdcall D3DXVec4CatmullRom(ptr ptr ptr ptr ptr long)
@ stdcall D3DXVec4Cross(ptr ptr ptr ptr)
@ stdcall D3DXVec4Hermite(ptr ptr ptr ptr ptr long)
@ stdcall D3DXVec4Normalize(ptr ptr)
@ stdcall D3DXVec4Transform(ptr ptr ptr)
@ stdcall D3DXVec4TransformArray(ptr long ptr long ptr long)
@ stub D3DXWeldVertices
dlls/d3dx9_36/d3dx9_36_private.h
View file @
d1c2d2a4
/*
* Copyright (C) 2002 Raphael Junqueira
* Copyright (C) 2008 David Adam
* Copyright (C) 2008 Tony Wasserka
*
* This library is free software; you can redistribute it and/or
...
...
@@ -63,6 +64,18 @@ typedef struct ID3DXFontImpl
HFONT
hfont
;
}
ID3DXFontImpl
;
/* ID3DXMatrixStack */
typedef
struct
ID3DXMatrixStackImpl
{
/* IUnknown fields */
const
ID3DXMatrixStackVtbl
*
lpVtbl
;
LONG
ref
;
/* ID3DXMatrixStack fields */
unsigned
int
current
;
unsigned
int
stack_size
;
D3DXMATRIX
*
stack
;
}
ID3DXMatrixStackImpl
;
/*ID3DXSprite */
typedef
struct
_SPRITE
{
...
...
dlls/d3dx9_36/math.c
View file @
d1c2d2a4
...
...
@@ -2,7 +2,10 @@
* Mathematical operations specific to D3DX9.
*
* Copyright (C) 2008 David Adam
* Copyright (C) 2008 Luis Busquets
* Copyright (C) 2008 Jérôme Gardou
* Copyright (C) 2008 Philip Nilsson
* Copyright (C) 2008 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -24,16 +27,84 @@
#include "config.h"
#include "windef.h"
#include "wingdi.h"
#include "d3dx9.h"
#include "d3dx9
_36_private
.h"
#include "wine/debug.h"
/*************************************************************************
* D3DXMatrixAffineTransformation2D
*/
D3DXMATRIX
*
WINAPI
D3DXMatrixAffineTransformation2D
(
D3DXMATRIX
*
pout
,
FLOAT
scaling
,
CONST
D3DXVECTOR2
*
protationcenter
,
FLOAT
rotation
,
CONST
D3DXVECTOR2
*
ptranslation
)
WINE_DEFAULT_DEBUG_CHANNEL
(
d3dx
);
static
const
ID3DXMatrixStackVtbl
ID3DXMatrixStack_Vtbl
;
/*_________________D3DXColor____________________*/
D3DXCOLOR
*
WINAPI
D3DXColorAdjustContrast
(
D3DXCOLOR
*
pout
,
CONST
D3DXCOLOR
*
pc
,
FLOAT
s
)
{
pout
->
r
=
0
.
5
f
+
s
*
(
pc
->
r
-
0
.
5
f
);
pout
->
g
=
0
.
5
f
+
s
*
(
pc
->
g
-
0
.
5
f
);
pout
->
b
=
0
.
5
f
+
s
*
(
pc
->
b
-
0
.
5
f
);
pout
->
a
=
pc
->
a
;
return
pout
;
}
D3DXCOLOR
*
WINAPI
D3DXColorAdjustSaturation
(
D3DXCOLOR
*
pout
,
CONST
D3DXCOLOR
*
pc
,
FLOAT
s
)
{
FLOAT
grey
;
grey
=
pc
->
r
*
0
.
2125
f
+
pc
->
g
*
0
.
7154
f
+
pc
->
b
*
0
.
0721
f
;
pout
->
r
=
grey
+
s
*
(
pc
->
r
-
grey
);
pout
->
g
=
grey
+
s
*
(
pc
->
g
-
grey
);
pout
->
b
=
grey
+
s
*
(
pc
->
b
-
grey
);
pout
->
a
=
pc
->
a
;
return
pout
;
}
/*_________________Misc__________________________*/
FLOAT
WINAPI
D3DXFresnelTerm
(
FLOAT
costheta
,
FLOAT
refractionindex
)
{
FLOAT
a
,
d
,
g
,
result
;
g
=
sqrt
(
refractionindex
*
refractionindex
+
costheta
*
costheta
-
1
.
0
f
);
a
=
g
+
costheta
;
d
=
g
-
costheta
;
result
=
(
costheta
*
a
-
1
.
0
f
)
*
(
costheta
*
a
-
1
.
0
f
)
/
(
(
costheta
*
d
+
1
.
0
f
)
*
(
costheta
*
d
+
1
.
0
f
)
)
+
1
.
0
f
;
result
=
result
*
0
.
5
f
*
d
*
d
/
(
a
*
a
);
return
result
;
}
/*_________________D3DXMatrix____________________*/
D3DXMATRIX
*
WINAPI
D3DXMatrixAffineTransformation
(
D3DXMATRIX
*
pout
,
FLOAT
scaling
,
CONST
D3DXVECTOR3
*
rotationcenter
,
CONST
D3DXQUATERNION
*
rotation
,
CONST
D3DXVECTOR3
*
translation
)
{
D3DXMATRIX
m1
,
m2
,
m3
,
m4
,
m5
;
D3DXMatrixScaling
(
&
m1
,
scaling
,
scaling
,
scaling
);
if
(
!
rotationcenter
)
{
D3DXMatrixIdentity
(
&
m2
);
D3DXMatrixIdentity
(
&
m4
);
}
else
{
D3DXMatrixTranslation
(
&
m2
,
-
rotationcenter
->
x
,
-
rotationcenter
->
y
,
-
rotationcenter
->
z
);
D3DXMatrixTranslation
(
&
m4
,
rotationcenter
->
x
,
rotationcenter
->
y
,
rotationcenter
->
z
);
}
if
(
!
rotation
)
D3DXMatrixIdentity
(
&
m3
);
else
D3DXMatrixRotationQuaternion
(
&
m3
,
rotation
);
if
(
!
translation
)
D3DXMatrixIdentity
(
&
m5
);
else
D3DXMatrixTranslation
(
&
m5
,
translation
->
x
,
translation
->
y
,
translation
->
z
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m2
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m3
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m4
);
D3DXMatrixMultiply
(
pout
,
&
m1
,
&
m5
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixAffineTransformation2D
(
D3DXMATRIX
*
pout
,
FLOAT
scaling
,
CONST
D3DXVECTOR2
*
protationcenter
,
FLOAT
rotation
,
CONST
D3DXVECTOR2
*
ptranslation
)
{
D3DXMATRIX
m1
,
m2
,
m3
,
m4
,
m5
;
D3DXQUATERNION
rot
;
...
...
@@ -84,9 +155,6 @@ D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D(
return
pout
;
}
/*************************************************************************
* D3DXMatrixDecompose
*/
HRESULT
WINAPI
D3DXMatrixDecompose
(
D3DXVECTOR3
*
poutscale
,
D3DXQUATERNION
*
poutrotation
,
D3DXVECTOR3
*
pouttranslation
,
CONST
D3DXMATRIX
*
pm
)
{
D3DXMATRIX
normalized
;
...
...
@@ -114,10 +182,7 @@ HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutr
pouttranslation
->
z
=
pm
->
u
.
m
[
3
][
2
];
/*Let's calculate the rotation now*/
if
(
(
poutscale
->
x
==
0
.
0
f
)
||
(
poutscale
->
y
==
0
.
0
f
)
||
(
poutscale
->
z
==
0
.
0
f
)
)
{
return
D3DERR_INVALIDCALL
;
}
if
(
(
poutscale
->
x
==
0
.
0
f
)
||
(
poutscale
->
y
==
0
.
0
f
)
||
(
poutscale
->
z
==
0
.
0
f
)
)
return
D3DERR_INVALIDCALL
;
normalized
.
u
.
m
[
0
][
0
]
=
pm
->
u
.
m
[
0
][
0
]
/
poutscale
->
x
;
normalized
.
u
.
m
[
0
][
1
]
=
pm
->
u
.
m
[
0
][
1
]
/
poutscale
->
x
;
...
...
@@ -133,14 +198,463 @@ HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutr
return
S_OK
;
}
/*************************************************************************
* D3DXMatrixTransformation2D
*/
D3DXMATRIX
*
WINAPI
D3DXMatrixTransformation2D
(
D3DXMATRIX
*
pout
,
CONST
D3DXVECTOR2
*
pscalingcenter
,
FLOAT
scalingrotation
,
CONST
D3DXVECTOR2
*
pscaling
,
CONST
D3DXVECTOR2
*
protationcenter
,
FLOAT
rotation
,
CONST
D3DXVECTOR2
*
ptranslation
)
FLOAT
WINAPI
D3DXMatrixDeterminant
(
CONST
D3DXMATRIX
*
pm
)
{
D3DXVECTOR4
minor
,
v1
,
v2
,
v3
;
FLOAT
det
;
v1
.
x
=
pm
->
u
.
m
[
0
][
0
];
v1
.
y
=
pm
->
u
.
m
[
1
][
0
];
v1
.
z
=
pm
->
u
.
m
[
2
][
0
];
v1
.
w
=
pm
->
u
.
m
[
3
][
0
];
v2
.
x
=
pm
->
u
.
m
[
0
][
1
];
v2
.
y
=
pm
->
u
.
m
[
1
][
1
];
v2
.
z
=
pm
->
u
.
m
[
2
][
1
];
v2
.
w
=
pm
->
u
.
m
[
3
][
1
];
v3
.
x
=
pm
->
u
.
m
[
0
][
2
];
v3
.
y
=
pm
->
u
.
m
[
1
][
2
];
v3
.
z
=
pm
->
u
.
m
[
2
][
2
];
v3
.
w
=
pm
->
u
.
m
[
3
][
2
];
D3DXVec4Cross
(
&
minor
,
&
v1
,
&
v2
,
&
v3
);
det
=
-
(
pm
->
u
.
m
[
0
][
3
]
*
minor
.
x
+
pm
->
u
.
m
[
1
][
3
]
*
minor
.
y
+
pm
->
u
.
m
[
2
][
3
]
*
minor
.
z
+
pm
->
u
.
m
[
3
][
3
]
*
minor
.
w
);
return
det
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixInverse
(
D3DXMATRIX
*
pout
,
FLOAT
*
pdeterminant
,
CONST
D3DXMATRIX
*
pm
)
{
int
a
,
i
,
j
;
D3DXMATRIX
out
;
D3DXVECTOR4
v
,
vec
[
3
];
FLOAT
det
;
det
=
D3DXMatrixDeterminant
(
pm
);
if
(
!
det
)
return
NULL
;
if
(
pdeterminant
)
*
pdeterminant
=
det
;
for
(
i
=
0
;
i
<
4
;
i
++
)
{
for
(
j
=
0
;
j
<
4
;
j
++
)
{
if
(
j
!=
i
)
{
a
=
j
;
if
(
j
>
i
)
a
=
a
-
1
;
vec
[
a
].
x
=
pm
->
u
.
m
[
j
][
0
];
vec
[
a
].
y
=
pm
->
u
.
m
[
j
][
1
];
vec
[
a
].
z
=
pm
->
u
.
m
[
j
][
2
];
vec
[
a
].
w
=
pm
->
u
.
m
[
j
][
3
];
}
}
D3DXVec4Cross
(
&
v
,
&
vec
[
0
],
&
vec
[
1
],
&
vec
[
2
]);
out
.
u
.
m
[
0
][
i
]
=
pow
(
-
1
.
0
f
,
i
)
*
v
.
x
/
det
;
out
.
u
.
m
[
1
][
i
]
=
pow
(
-
1
.
0
f
,
i
)
*
v
.
y
/
det
;
out
.
u
.
m
[
2
][
i
]
=
pow
(
-
1
.
0
f
,
i
)
*
v
.
z
/
det
;
out
.
u
.
m
[
3
][
i
]
=
pow
(
-
1
.
0
f
,
i
)
*
v
.
w
/
det
;
}
*
pout
=
out
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixLookAtLH
(
D3DXMATRIX
*
pout
,
CONST
D3DXVECTOR3
*
peye
,
CONST
D3DXVECTOR3
*
pat
,
CONST
D3DXVECTOR3
*
pup
)
{
D3DXVECTOR3
right
,
rightn
,
up
,
upn
,
vec
,
vec2
;
D3DXVec3Subtract
(
&
vec2
,
pat
,
peye
);
D3DXVec3Normalize
(
&
vec
,
&
vec2
);
D3DXVec3Cross
(
&
right
,
pup
,
&
vec
);
D3DXVec3Cross
(
&
up
,
&
vec
,
&
right
);
D3DXVec3Normalize
(
&
rightn
,
&
right
);
D3DXVec3Normalize
(
&
upn
,
&
up
);
pout
->
u
.
m
[
0
][
0
]
=
rightn
.
x
;
pout
->
u
.
m
[
1
][
0
]
=
rightn
.
y
;
pout
->
u
.
m
[
2
][
0
]
=
rightn
.
z
;
pout
->
u
.
m
[
3
][
0
]
=
-
D3DXVec3Dot
(
&
rightn
,
peye
);
pout
->
u
.
m
[
0
][
1
]
=
upn
.
x
;
pout
->
u
.
m
[
1
][
1
]
=
upn
.
y
;
pout
->
u
.
m
[
2
][
1
]
=
upn
.
z
;
pout
->
u
.
m
[
3
][
1
]
=
-
D3DXVec3Dot
(
&
upn
,
peye
);
pout
->
u
.
m
[
0
][
2
]
=
vec
.
x
;
pout
->
u
.
m
[
1
][
2
]
=
vec
.
y
;
pout
->
u
.
m
[
2
][
2
]
=
vec
.
z
;
pout
->
u
.
m
[
3
][
2
]
=
-
D3DXVec3Dot
(
&
vec
,
peye
);
pout
->
u
.
m
[
0
][
3
]
=
0
.
0
f
;
pout
->
u
.
m
[
1
][
3
]
=
0
.
0
f
;
pout
->
u
.
m
[
2
][
3
]
=
0
.
0
f
;
pout
->
u
.
m
[
3
][
3
]
=
1
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixLookAtRH
(
D3DXMATRIX
*
pout
,
CONST
D3DXVECTOR3
*
peye
,
CONST
D3DXVECTOR3
*
pat
,
CONST
D3DXVECTOR3
*
pup
)
{
D3DXVECTOR3
right
,
rightn
,
up
,
upn
,
vec
,
vec2
;
D3DXVec3Subtract
(
&
vec2
,
pat
,
peye
);
D3DXVec3Normalize
(
&
vec
,
&
vec2
);
D3DXVec3Cross
(
&
right
,
pup
,
&
vec
);
D3DXVec3Cross
(
&
up
,
&
vec
,
&
right
);
D3DXVec3Normalize
(
&
rightn
,
&
right
);
D3DXVec3Normalize
(
&
upn
,
&
up
);
pout
->
u
.
m
[
0
][
0
]
=
-
rightn
.
x
;
pout
->
u
.
m
[
1
][
0
]
=
-
rightn
.
y
;
pout
->
u
.
m
[
2
][
0
]
=
-
rightn
.
z
;
pout
->
u
.
m
[
3
][
0
]
=
D3DXVec3Dot
(
&
rightn
,
peye
);
pout
->
u
.
m
[
0
][
1
]
=
upn
.
x
;
pout
->
u
.
m
[
1
][
1
]
=
upn
.
y
;
pout
->
u
.
m
[
2
][
1
]
=
upn
.
z
;
pout
->
u
.
m
[
3
][
1
]
=
-
D3DXVec3Dot
(
&
upn
,
peye
);
pout
->
u
.
m
[
0
][
2
]
=
-
vec
.
x
;
pout
->
u
.
m
[
1
][
2
]
=
-
vec
.
y
;
pout
->
u
.
m
[
2
][
2
]
=
-
vec
.
z
;
pout
->
u
.
m
[
3
][
2
]
=
D3DXVec3Dot
(
&
vec
,
peye
);
pout
->
u
.
m
[
0
][
3
]
=
0
.
0
f
;
pout
->
u
.
m
[
1
][
3
]
=
0
.
0
f
;
pout
->
u
.
m
[
2
][
3
]
=
0
.
0
f
;
pout
->
u
.
m
[
3
][
3
]
=
1
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixMultiply
(
D3DXMATRIX
*
pout
,
CONST
D3DXMATRIX
*
pm1
,
CONST
D3DXMATRIX
*
pm2
)
{
D3DXMATRIX
out
;
int
i
,
j
;
for
(
i
=
0
;
i
<
4
;
i
++
)
{
for
(
j
=
0
;
j
<
4
;
j
++
)
{
out
.
u
.
m
[
i
][
j
]
=
pm1
->
u
.
m
[
i
][
0
]
*
pm2
->
u
.
m
[
0
][
j
]
+
pm1
->
u
.
m
[
i
][
1
]
*
pm2
->
u
.
m
[
1
][
j
]
+
pm1
->
u
.
m
[
i
][
2
]
*
pm2
->
u
.
m
[
2
][
j
]
+
pm1
->
u
.
m
[
i
][
3
]
*
pm2
->
u
.
m
[
3
][
j
];
}
}
*
pout
=
out
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixMultiplyTranspose
(
D3DXMATRIX
*
pout
,
CONST
D3DXMATRIX
*
pm1
,
CONST
D3DXMATRIX
*
pm2
)
{
D3DXMatrixMultiply
(
pout
,
pm1
,
pm2
);
D3DXMatrixTranspose
(
pout
,
pout
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixOrthoLH
(
D3DXMATRIX
*
pout
,
FLOAT
w
,
FLOAT
h
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
/
w
;
pout
->
u
.
m
[
1
][
1
]
=
2
.
0
f
/
h
;
pout
->
u
.
m
[
2
][
2
]
=
1
.
0
f
/
(
zf
-
zn
);
pout
->
u
.
m
[
3
][
2
]
=
zn
/
(
zn
-
zf
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixOrthoOffCenterLH
(
D3DXMATRIX
*
pout
,
FLOAT
l
,
FLOAT
r
,
FLOAT
b
,
FLOAT
t
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
/
(
r
-
l
);
pout
->
u
.
m
[
1
][
1
]
=
2
.
0
f
/
(
t
-
b
);
pout
->
u
.
m
[
2
][
2
]
=
1
.
0
f
/
(
zf
-
zn
);
pout
->
u
.
m
[
3
][
0
]
=
-
1
.
0
f
-
2
.
0
f
*
l
/
(
r
-
l
);
pout
->
u
.
m
[
3
][
1
]
=
1
.
0
f
+
2
.
0
f
*
t
/
(
b
-
t
);
pout
->
u
.
m
[
3
][
2
]
=
zn
/
(
zn
-
zf
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixOrthoOffCenterRH
(
D3DXMATRIX
*
pout
,
FLOAT
l
,
FLOAT
r
,
FLOAT
b
,
FLOAT
t
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
/
(
r
-
l
);
pout
->
u
.
m
[
1
][
1
]
=
2
.
0
f
/
(
t
-
b
);
pout
->
u
.
m
[
2
][
2
]
=
1
.
0
f
/
(
zn
-
zf
);
pout
->
u
.
m
[
3
][
0
]
=
-
1
.
0
f
-
2
.
0
f
*
l
/
(
r
-
l
);
pout
->
u
.
m
[
3
][
1
]
=
1
.
0
f
+
2
.
0
f
*
t
/
(
b
-
t
);
pout
->
u
.
m
[
3
][
2
]
=
zn
/
(
zn
-
zf
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixOrthoRH
(
D3DXMATRIX
*
pout
,
FLOAT
w
,
FLOAT
h
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
/
w
;
pout
->
u
.
m
[
1
][
1
]
=
2
.
0
f
/
h
;
pout
->
u
.
m
[
2
][
2
]
=
1
.
0
f
/
(
zn
-
zf
);
pout
->
u
.
m
[
3
][
2
]
=
zn
/
(
zn
-
zf
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixPerspectiveFovLH
(
D3DXMATRIX
*
pout
,
FLOAT
fovy
,
FLOAT
aspect
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
1
.
0
f
/
(
aspect
*
tan
(
fovy
/
2
.
0
f
));
pout
->
u
.
m
[
1
][
1
]
=
1
.
0
f
/
tan
(
fovy
/
2
.
0
f
);
pout
->
u
.
m
[
2
][
2
]
=
zf
/
(
zf
-
zn
);
pout
->
u
.
m
[
2
][
3
]
=
1
.
0
f
;
pout
->
u
.
m
[
3
][
2
]
=
(
zf
*
zn
)
/
(
zn
-
zf
);
pout
->
u
.
m
[
3
][
3
]
=
0
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixPerspectiveFovRH
(
D3DXMATRIX
*
pout
,
FLOAT
fovy
,
FLOAT
aspect
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
1
.
0
f
/
(
aspect
*
tan
(
fovy
/
2
.
0
f
));
pout
->
u
.
m
[
1
][
1
]
=
1
.
0
f
/
tan
(
fovy
/
2
.
0
f
);
pout
->
u
.
m
[
2
][
2
]
=
zf
/
(
zn
-
zf
);
pout
->
u
.
m
[
2
][
3
]
=
-
1
.
0
f
;
pout
->
u
.
m
[
3
][
2
]
=
(
zf
*
zn
)
/
(
zn
-
zf
);
pout
->
u
.
m
[
3
][
3
]
=
0
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixPerspectiveLH
(
D3DXMATRIX
*
pout
,
FLOAT
w
,
FLOAT
h
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
*
zn
/
w
;
pout
->
u
.
m
[
1
][
1
]
=
2
.
0
f
*
zn
/
h
;
pout
->
u
.
m
[
2
][
2
]
=
zf
/
(
zf
-
zn
);
pout
->
u
.
m
[
3
][
2
]
=
(
zn
*
zf
)
/
(
zn
-
zf
);
pout
->
u
.
m
[
2
][
3
]
=
1
.
0
f
;
pout
->
u
.
m
[
3
][
3
]
=
0
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixPerspectiveOffCenterLH
(
D3DXMATRIX
*
pout
,
FLOAT
l
,
FLOAT
r
,
FLOAT
b
,
FLOAT
t
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
*
zn
/
(
r
-
l
);
pout
->
u
.
m
[
1
][
1
]
=
-
2
.
0
f
*
zn
/
(
b
-
t
);
pout
->
u
.
m
[
2
][
0
]
=
-
1
.
0
f
-
2
.
0
f
*
l
/
(
r
-
l
);
pout
->
u
.
m
[
2
][
1
]
=
1
.
0
f
+
2
.
0
f
*
t
/
(
b
-
t
);
pout
->
u
.
m
[
2
][
2
]
=
-
zf
/
(
zn
-
zf
);
pout
->
u
.
m
[
3
][
2
]
=
(
zn
*
zf
)
/
(
zn
-
zf
);
pout
->
u
.
m
[
2
][
3
]
=
1
.
0
f
;
pout
->
u
.
m
[
3
][
3
]
=
0
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixPerspectiveOffCenterRH
(
D3DXMATRIX
*
pout
,
FLOAT
l
,
FLOAT
r
,
FLOAT
b
,
FLOAT
t
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
*
zn
/
(
r
-
l
);
pout
->
u
.
m
[
1
][
1
]
=
-
2
.
0
f
*
zn
/
(
b
-
t
);
pout
->
u
.
m
[
2
][
0
]
=
1
.
0
f
+
2
.
0
f
*
l
/
(
r
-
l
);
pout
->
u
.
m
[
2
][
1
]
=
-
1
.
0
f
-
2
.
0
f
*
t
/
(
b
-
t
);
pout
->
u
.
m
[
2
][
2
]
=
zf
/
(
zn
-
zf
);
pout
->
u
.
m
[
3
][
2
]
=
(
zn
*
zf
)
/
(
zn
-
zf
);
pout
->
u
.
m
[
2
][
3
]
=
-
1
.
0
f
;
pout
->
u
.
m
[
3
][
3
]
=
0
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixPerspectiveRH
(
D3DXMATRIX
*
pout
,
FLOAT
w
,
FLOAT
h
,
FLOAT
zn
,
FLOAT
zf
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
2
.
0
f
*
zn
/
w
;
pout
->
u
.
m
[
1
][
1
]
=
2
.
0
f
*
zn
/
h
;
pout
->
u
.
m
[
2
][
2
]
=
zf
/
(
zn
-
zf
);
pout
->
u
.
m
[
3
][
2
]
=
(
zn
*
zf
)
/
(
zn
-
zf
);
pout
->
u
.
m
[
2
][
3
]
=
-
1
.
0
f
;
pout
->
u
.
m
[
3
][
3
]
=
0
.
0
f
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixReflect
(
D3DXMATRIX
*
pout
,
CONST
D3DXPLANE
*
pplane
)
{
D3DXPLANE
Nplane
;
D3DXPlaneNormalize
(
&
Nplane
,
pplane
);
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
1
.
0
f
-
2
.
0
f
*
Nplane
.
a
*
Nplane
.
a
;
pout
->
u
.
m
[
0
][
1
]
=
-
2
.
0
f
*
Nplane
.
a
*
Nplane
.
b
;
pout
->
u
.
m
[
0
][
2
]
=
-
2
.
0
f
*
Nplane
.
a
*
Nplane
.
c
;
pout
->
u
.
m
[
1
][
0
]
=
-
2
.
0
f
*
Nplane
.
a
*
Nplane
.
b
;
pout
->
u
.
m
[
1
][
1
]
=
1
.
0
f
-
2
.
0
f
*
Nplane
.
b
*
Nplane
.
b
;
pout
->
u
.
m
[
1
][
2
]
=
-
2
.
0
f
*
Nplane
.
b
*
Nplane
.
c
;
pout
->
u
.
m
[
2
][
0
]
=
-
2
.
0
f
*
Nplane
.
c
*
Nplane
.
a
;
pout
->
u
.
m
[
2
][
1
]
=
-
2
.
0
f
*
Nplane
.
c
*
Nplane
.
b
;
pout
->
u
.
m
[
2
][
2
]
=
1
.
0
f
-
2
.
0
f
*
Nplane
.
c
*
Nplane
.
c
;
pout
->
u
.
m
[
3
][
0
]
=
-
2
.
0
f
*
Nplane
.
d
*
Nplane
.
a
;
pout
->
u
.
m
[
3
][
1
]
=
-
2
.
0
f
*
Nplane
.
d
*
Nplane
.
b
;
pout
->
u
.
m
[
3
][
2
]
=
-
2
.
0
f
*
Nplane
.
d
*
Nplane
.
c
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixRotationAxis
(
D3DXMATRIX
*
pout
,
CONST
D3DXVECTOR3
*
pv
,
FLOAT
angle
)
{
D3DXVECTOR3
v
;
D3DXVec3Normalize
(
&
v
,
pv
);
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
x
*
v
.
x
+
cos
(
angle
);
pout
->
u
.
m
[
1
][
0
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
x
*
v
.
y
-
sin
(
angle
)
*
v
.
z
;
pout
->
u
.
m
[
2
][
0
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
x
*
v
.
z
+
sin
(
angle
)
*
v
.
y
;
pout
->
u
.
m
[
0
][
1
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
y
*
v
.
x
+
sin
(
angle
)
*
v
.
z
;
pout
->
u
.
m
[
1
][
1
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
y
*
v
.
y
+
cos
(
angle
);
pout
->
u
.
m
[
2
][
1
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
y
*
v
.
z
-
sin
(
angle
)
*
v
.
x
;
pout
->
u
.
m
[
0
][
2
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
z
*
v
.
x
-
sin
(
angle
)
*
v
.
y
;
pout
->
u
.
m
[
1
][
2
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
z
*
v
.
y
+
sin
(
angle
)
*
v
.
x
;
pout
->
u
.
m
[
2
][
2
]
=
(
1
.
0
f
-
cos
(
angle
))
*
v
.
z
*
v
.
z
+
cos
(
angle
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixRotationQuaternion
(
D3DXMATRIX
*
pout
,
CONST
D3DXQUATERNION
*
pq
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
1
.
0
f
-
2
.
0
f
*
(
pq
->
y
*
pq
->
y
+
pq
->
z
*
pq
->
z
);
pout
->
u
.
m
[
0
][
1
]
=
2
.
0
f
*
(
pq
->
x
*
pq
->
y
+
pq
->
z
*
pq
->
w
);
pout
->
u
.
m
[
0
][
2
]
=
2
.
0
f
*
(
pq
->
x
*
pq
->
z
-
pq
->
y
*
pq
->
w
);
pout
->
u
.
m
[
1
][
0
]
=
2
.
0
f
*
(
pq
->
x
*
pq
->
y
-
pq
->
z
*
pq
->
w
);
pout
->
u
.
m
[
1
][
1
]
=
1
.
0
f
-
2
.
0
f
*
(
pq
->
x
*
pq
->
x
+
pq
->
z
*
pq
->
z
);
pout
->
u
.
m
[
1
][
2
]
=
2
.
0
f
*
(
pq
->
y
*
pq
->
z
+
pq
->
x
*
pq
->
w
);
pout
->
u
.
m
[
2
][
0
]
=
2
.
0
f
*
(
pq
->
x
*
pq
->
z
+
pq
->
y
*
pq
->
w
);
pout
->
u
.
m
[
2
][
1
]
=
2
.
0
f
*
(
pq
->
y
*
pq
->
z
-
pq
->
x
*
pq
->
w
);
pout
->
u
.
m
[
2
][
2
]
=
1
.
0
f
-
2
.
0
f
*
(
pq
->
x
*
pq
->
x
+
pq
->
y
*
pq
->
y
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixRotationX
(
D3DXMATRIX
*
pout
,
FLOAT
angle
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
1
][
1
]
=
cos
(
angle
);
pout
->
u
.
m
[
2
][
2
]
=
cos
(
angle
);
pout
->
u
.
m
[
1
][
2
]
=
sin
(
angle
);
pout
->
u
.
m
[
2
][
1
]
=
-
sin
(
angle
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixRotationY
(
D3DXMATRIX
*
pout
,
FLOAT
angle
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
cos
(
angle
);
pout
->
u
.
m
[
2
][
2
]
=
cos
(
angle
);
pout
->
u
.
m
[
0
][
2
]
=
-
sin
(
angle
);
pout
->
u
.
m
[
2
][
0
]
=
sin
(
angle
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixRotationYawPitchRoll
(
D3DXMATRIX
*
pout
,
FLOAT
yaw
,
FLOAT
pitch
,
FLOAT
roll
)
{
D3DXMATRIX
m
;
D3DXMatrixIdentity
(
pout
);
D3DXMatrixRotationZ
(
&
m
,
roll
);
D3DXMatrixMultiply
(
pout
,
pout
,
&
m
);
D3DXMatrixRotationX
(
&
m
,
pitch
);
D3DXMatrixMultiply
(
pout
,
pout
,
&
m
);
D3DXMatrixRotationY
(
&
m
,
yaw
);
D3DXMatrixMultiply
(
pout
,
pout
,
&
m
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixRotationZ
(
D3DXMATRIX
*
pout
,
FLOAT
angle
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
cos
(
angle
);
pout
->
u
.
m
[
1
][
1
]
=
cos
(
angle
);
pout
->
u
.
m
[
0
][
1
]
=
sin
(
angle
);
pout
->
u
.
m
[
1
][
0
]
=
-
sin
(
angle
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixScaling
(
D3DXMATRIX
*
pout
,
FLOAT
sx
,
FLOAT
sy
,
FLOAT
sz
)
{
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
0
][
0
]
=
sx
;
pout
->
u
.
m
[
1
][
1
]
=
sy
;
pout
->
u
.
m
[
2
][
2
]
=
sz
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixShadow
(
D3DXMATRIX
*
pout
,
CONST
D3DXVECTOR4
*
plight
,
CONST
D3DXPLANE
*
pplane
)
{
D3DXPLANE
Nplane
;
FLOAT
dot
;
D3DXPlaneNormalize
(
&
Nplane
,
pplane
);
dot
=
D3DXPlaneDot
(
&
Nplane
,
plight
);
pout
->
u
.
m
[
0
][
0
]
=
dot
-
Nplane
.
a
*
plight
->
x
;
pout
->
u
.
m
[
0
][
1
]
=
-
Nplane
.
a
*
plight
->
y
;
pout
->
u
.
m
[
0
][
2
]
=
-
Nplane
.
a
*
plight
->
z
;
pout
->
u
.
m
[
0
][
3
]
=
-
Nplane
.
a
*
plight
->
w
;
pout
->
u
.
m
[
1
][
0
]
=
-
Nplane
.
b
*
plight
->
x
;
pout
->
u
.
m
[
1
][
1
]
=
dot
-
Nplane
.
b
*
plight
->
y
;
pout
->
u
.
m
[
1
][
2
]
=
-
Nplane
.
b
*
plight
->
z
;
pout
->
u
.
m
[
1
][
3
]
=
-
Nplane
.
b
*
plight
->
w
;
pout
->
u
.
m
[
2
][
0
]
=
-
Nplane
.
c
*
plight
->
x
;
pout
->
u
.
m
[
2
][
1
]
=
-
Nplane
.
c
*
plight
->
y
;
pout
->
u
.
m
[
2
][
2
]
=
dot
-
Nplane
.
c
*
plight
->
z
;
pout
->
u
.
m
[
2
][
3
]
=
-
Nplane
.
c
*
plight
->
w
;
pout
->
u
.
m
[
3
][
0
]
=
-
Nplane
.
d
*
plight
->
x
;
pout
->
u
.
m
[
3
][
1
]
=
-
Nplane
.
d
*
plight
->
y
;
pout
->
u
.
m
[
3
][
2
]
=
-
Nplane
.
d
*
plight
->
z
;
pout
->
u
.
m
[
3
][
3
]
=
dot
-
Nplane
.
d
*
plight
->
w
;
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixTransformation
(
D3DXMATRIX
*
pout
,
CONST
D3DXVECTOR3
*
pscalingcenter
,
CONST
D3DXQUATERNION
*
pscalingrotation
,
CONST
D3DXVECTOR3
*
pscaling
,
CONST
D3DXVECTOR3
*
protationcenter
,
CONST
D3DXQUATERNION
*
protation
,
CONST
D3DXVECTOR3
*
ptranslation
)
{
D3DXMATRIX
m1
,
m2
,
m3
,
m4
,
m5
,
m6
,
m7
;
D3DXQUATERNION
prc
;
D3DXVECTOR3
psc
,
pt
;
if
(
!
pscalingcenter
)
{
psc
.
x
=
0
.
0
f
;
psc
.
y
=
0
.
0
f
;
psc
.
z
=
0
.
0
f
;
}
else
{
psc
.
x
=
pscalingcenter
->
x
;
psc
.
y
=
pscalingcenter
->
y
;
psc
.
z
=
pscalingcenter
->
z
;
}
if
(
!
protationcenter
)
{
prc
.
x
=
0
.
0
f
;
prc
.
y
=
0
.
0
f
;
prc
.
z
=
0
.
0
f
;
}
else
{
prc
.
x
=
protationcenter
->
x
;
prc
.
y
=
protationcenter
->
y
;
prc
.
z
=
protationcenter
->
z
;
}
if
(
!
ptranslation
)
{
pt
.
x
=
0
.
0
f
;
pt
.
y
=
0
.
0
f
;
pt
.
z
=
0
.
0
f
;
}
else
{
pt
.
x
=
ptranslation
->
x
;
pt
.
y
=
ptranslation
->
y
;
pt
.
z
=
ptranslation
->
z
;
}
D3DXMatrixTranslation
(
&
m1
,
-
psc
.
x
,
-
psc
.
y
,
-
psc
.
z
);
if
(
!
pscalingrotation
)
{
D3DXMatrixIdentity
(
&
m2
);
D3DXMatrixIdentity
(
&
m4
);
}
else
{
D3DXMatrixRotationQuaternion
(
&
m4
,
pscalingrotation
);
D3DXMatrixInverse
(
&
m2
,
NULL
,
&
m4
);
}
if
(
!
pscaling
)
D3DXMatrixIdentity
(
&
m3
);
else
D3DXMatrixScaling
(
&
m3
,
pscaling
->
x
,
pscaling
->
y
,
pscaling
->
z
);
if
(
!
protation
)
D3DXMatrixIdentity
(
&
m6
);
else
D3DXMatrixRotationQuaternion
(
&
m6
,
protation
);
D3DXMatrixTranslation
(
&
m5
,
psc
.
x
-
prc
.
x
,
psc
.
y
-
prc
.
y
,
psc
.
z
-
prc
.
z
);
D3DXMatrixTranslation
(
&
m7
,
prc
.
x
+
pt
.
x
,
prc
.
y
+
pt
.
y
,
prc
.
z
+
pt
.
z
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m2
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m3
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m4
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m5
);
D3DXMatrixMultiply
(
&
m1
,
&
m1
,
&
m6
);
D3DXMatrixMultiply
(
pout
,
&
m1
,
&
m7
);
return
pout
;
}
D3DXMATRIX
*
WINAPI
D3DXMatrixTransformation2D
(
D3DXMATRIX
*
pout
,
CONST
D3DXVECTOR2
*
pscalingcenter
,
FLOAT
scalingrotation
,
CONST
D3DXVECTOR2
*
pscaling
,
CONST
D3DXVECTOR2
*
protationcenter
,
FLOAT
rotation
,
CONST
D3DXVECTOR2
*
ptranslation
)
{
D3DXQUATERNION
rot
,
sca_rot
;
D3DXVECTOR3
rot_center
,
sca
,
sca_center
,
trans
;
...
...
@@ -212,111 +726,894 @@ D3DXMATRIX* WINAPI D3DXMatrixTransformation2D(
return
pout
;
}
/*************************************************************************
* D3DXPlaneTransformArray
*/
D3DXPLANE
*
WINAPI
D3DXPlaneTransformArray
(
D3DXPLANE
*
out
,
UINT
outstride
,
CONST
D3DXPLANE
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
D3DXMATRIX
*
WINAPI
D3DXMatrixTranslation
(
D3DXMATRIX
*
pout
,
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
{
UINT
i
;
D3DXMatrixIdentity
(
pout
);
pout
->
u
.
m
[
3
][
0
]
=
x
;
pout
->
u
.
m
[
3
][
1
]
=
y
;
pout
->
u
.
m
[
3
][
2
]
=
z
;
return
pout
;
}
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXPlaneTransform
(
(
D3DXPLANE
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXPLANE
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
}
return
out
;
D3DXMATRIX
*
WINAPI
D3DXMatrixTranspose
(
D3DXMATRIX
*
pout
,
CONST
D3DXMATRIX
*
pm
)
{
CONST
D3DXMATRIX
m
=
*
pm
;
int
i
,
j
;
for
(
i
=
0
;
i
<
4
;
i
++
)
for
(
j
=
0
;
j
<
4
;
j
++
)
pout
->
u
.
m
[
i
][
j
]
=
m
.
u
.
m
[
j
][
i
];
return
pout
;
}
/*************************************************************************
* D3DXVec2TransformArray
*
* Transform an array of vectors by a matrix.
*/
D3DXVECTOR4
*
WINAPI
D3DXVec2TransformArray
(
D3DXVECTOR4
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR2
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
/*_________________D3DXMatrixStack____________________*/
static
const
unsigned
int
INITIAL_STACK_SIZE
=
32
;
HRESULT
WINAPI
D3DXCreateMatrixStack
(
DWORD
flags
,
LPD3DXMATRIXSTACK
*
ppstack
)
{
UINT
i
;
ID3DXMatrixStackImpl
*
object
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec2Transform
(
(
D3DXVECTOR4
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR2
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
TRACE
(
"flags %#x, ppstack %p
\n
"
,
flags
,
ppstack
);
object
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
sizeof
(
ID3DXMatrixStackImpl
));
if
(
object
==
NULL
)
{
*
ppstack
=
NULL
;
return
E_OUTOFMEMORY
;
}
return
out
;
object
->
lpVtbl
=
&
ID3DXMatrixStack_Vtbl
;
object
->
ref
=
1
;
object
->
stack
=
HeapAlloc
(
GetProcessHeap
(),
0
,
INITIAL_STACK_SIZE
*
sizeof
(
D3DXMATRIX
));
if
(
!
object
->
stack
)
{
HeapFree
(
GetProcessHeap
(),
0
,
object
);
*
ppstack
=
NULL
;
return
E_OUTOFMEMORY
;
}
object
->
current
=
0
;
object
->
stack_size
=
INITIAL_STACK_SIZE
;
D3DXMatrixIdentity
(
&
object
->
stack
[
0
]);
TRACE
(
"Created matrix stack %p
\n
"
,
object
);
*
ppstack
=
(
LPD3DXMATRIXSTACK
)
object
;
return
D3D_OK
;
}
/*************************************************************************
* D3DXVec2TransformCoordArray
*/
D3DXVECTOR2
*
WINAPI
D3DXVec2TransformCoordArray
(
D3DXVECTOR2
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR2
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_QueryInterface
(
ID3DXMatrixStack
*
iface
,
REFIID
riid
,
void
**
ppobj
)
{
UINT
i
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec2TransformCoord
(
(
D3DXVECTOR2
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR2
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
if
(
IsEqualGUID
(
riid
,
&
IID_IUnknown
)
||
IsEqualGUID
(
riid
,
&
IID_ID3DXMatrixStack
))
{
ID3DXMatrixStack_AddRef
(
iface
);
*
ppobj
=
This
;
return
S_OK
;
}
return
out
;
*
ppobj
=
NULL
;
ERR
(
"(%p)->(%s,%p),not found
\n
"
,
This
,
debugstr_guid
(
riid
),
ppobj
);
return
E_NOINTERFACE
;
}
/*************************************************************************
* D3DXVec2TransformNormalArray
*/
D3DXVECTOR2
*
WINAPI
D3DXVec2TransformNormalArray
(
D3DXVECTOR2
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR2
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
static
ULONG
WINAPI
ID3DXMatrixStackImpl_AddRef
(
ID3DXMatrixStack
*
iface
)
{
UINT
i
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
ULONG
ref
=
InterlockedIncrement
(
&
This
->
ref
);
TRACE
(
"(%p) : AddRef from %d
\n
"
,
This
,
ref
-
1
);
return
ref
;
}
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec2TransformNormal
(
(
D3DXVECTOR2
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR2
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
static
ULONG
WINAPI
ID3DXMatrixStackImpl_Release
(
ID3DXMatrixStack
*
iface
)
{
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
ULONG
ref
=
InterlockedDecrement
(
&
This
->
ref
);
if
(
!
ref
)
{
HeapFree
(
GetProcessHeap
(),
0
,
This
->
stack
);
HeapFree
(
GetProcessHeap
(),
0
,
This
);
}
return
out
;
TRACE
(
"(%p) : ReleaseRef to %d
\n
"
,
This
,
ref
);
return
ref
;
}
/*************************************************************************
* D3DXVec3ProjectArray
*
* Projects an array of vectors to the screen.
*/
D3DXVECTOR3
*
WINAPI
D3DXVec3ProjectArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DVIEWPORT9
*
viewport
,
CONST
D3DXMATRIX
*
projection
,
CONST
D3DXMATRIX
*
view
,
CONST
D3DXMATRIX
*
world
,
UINT
elements
)
static
D3DXMATRIX
*
WINAPI
ID3DXMatrixStackImpl_GetTop
(
ID3DXMatrixStack
*
iface
)
{
UINT
i
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec3Project
(
(
D3DXVECTOR3
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR3
*
)((
const
char
*
)
in
+
instride
*
i
),
viewport
,
projection
,
view
,
world
);
}
return
out
;
TRACE
(
"iface %p
\n
"
,
iface
);
return
&
This
->
stack
[
This
->
current
];
}
/*************************************************************************
* D3DXVec3TransformArray
*/
D3DXVECTOR4
*
WINAPI
D3DXVec3TransformArray
(
D3DXVECTOR4
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_LoadIdentity
(
ID3DXMatrixStack
*
iface
)
{
UINT
i
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
TRACE
(
"iface %p
\n
"
,
iface
);
D3DXMatrixIdentity
(
&
This
->
stack
[
This
->
current
]);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_LoadMatrix
(
ID3DXMatrixStack
*
iface
,
CONST
D3DXMATRIX
*
pm
)
{
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
if
(
!
pm
)
return
D3DERR_INVALIDCALL
;
This
->
stack
[
This
->
current
]
=
*
pm
;
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_MultMatrix
(
ID3DXMatrixStack
*
iface
,
CONST
D3DXMATRIX
*
pm
)
{
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
if
(
!
pm
)
return
D3DERR_INVALIDCALL
;
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
This
->
stack
[
This
->
current
],
pm
);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_MultMatrixLocal
(
ID3DXMatrixStack
*
iface
,
CONST
D3DXMATRIX
*
pm
)
{
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
if
(
!
pm
)
return
D3DERR_INVALIDCALL
;
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
pm
,
&
This
->
stack
[
This
->
current
]);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_Pop
(
ID3DXMatrixStack
*
iface
)
{
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
/* Popping the last element on the stack returns D3D_OK, but does nothing. */
if
(
!
This
->
current
)
return
D3D_OK
;
if
(
This
->
current
<=
This
->
stack_size
/
4
&&
This
->
stack_size
>=
INITIAL_STACK_SIZE
*
2
)
{
unsigned
int
new_size
;
D3DXMATRIX
*
new_stack
;
new_size
=
This
->
stack_size
/
2
;
new_stack
=
HeapReAlloc
(
GetProcessHeap
(),
0
,
This
->
stack
,
new_size
*
sizeof
(
D3DXMATRIX
));
if
(
new_stack
)
{
This
->
stack_size
=
new_size
;
This
->
stack
=
new_stack
;
}
}
--
This
->
current
;
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_Push
(
ID3DXMatrixStack
*
iface
)
{
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
if
(
This
->
current
==
This
->
stack_size
-
1
)
{
unsigned
int
new_size
;
D3DXMATRIX
*
new_stack
;
if
(
This
->
stack_size
>
UINT_MAX
/
2
)
return
E_OUTOFMEMORY
;
new_size
=
This
->
stack_size
*
2
;
new_stack
=
HeapReAlloc
(
GetProcessHeap
(),
0
,
This
->
stack
,
new_size
*
sizeof
(
D3DXMATRIX
));
if
(
!
new_stack
)
return
E_OUTOFMEMORY
;
This
->
stack_size
=
new_size
;
This
->
stack
=
new_stack
;
}
++
This
->
current
;
This
->
stack
[
This
->
current
]
=
This
->
stack
[
This
->
current
-
1
];
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_RotateAxis
(
ID3DXMatrixStack
*
iface
,
CONST
D3DXVECTOR3
*
pv
,
FLOAT
angle
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
if
(
!
pv
)
return
D3DERR_INVALIDCALL
;
D3DXMatrixRotationAxis
(
&
temp
,
pv
,
angle
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
This
->
stack
[
This
->
current
],
&
temp
);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_RotateAxisLocal
(
ID3DXMatrixStack
*
iface
,
CONST
D3DXVECTOR3
*
pv
,
FLOAT
angle
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
if
(
!
pv
)
return
D3DERR_INVALIDCALL
;
D3DXMatrixRotationAxis
(
&
temp
,
pv
,
angle
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
temp
,
&
This
->
stack
[
This
->
current
]);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRoll
(
ID3DXMatrixStack
*
iface
,
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
D3DXMatrixRotationYawPitchRoll
(
&
temp
,
x
,
y
,
z
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
This
->
stack
[
This
->
current
],
&
temp
);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRollLocal
(
ID3DXMatrixStack
*
iface
,
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
D3DXMatrixRotationYawPitchRoll
(
&
temp
,
x
,
y
,
z
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
temp
,
&
This
->
stack
[
This
->
current
]);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_Scale
(
ID3DXMatrixStack
*
iface
,
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
D3DXMatrixScaling
(
&
temp
,
x
,
y
,
z
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
This
->
stack
[
This
->
current
],
&
temp
);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_ScaleLocal
(
ID3DXMatrixStack
*
iface
,
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
D3DXMatrixScaling
(
&
temp
,
x
,
y
,
z
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
temp
,
&
This
->
stack
[
This
->
current
]);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_Translate
(
ID3DXMatrixStack
*
iface
,
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
D3DXMatrixTranslation
(
&
temp
,
x
,
y
,
z
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
This
->
stack
[
This
->
current
],
&
temp
);
return
D3D_OK
;
}
static
HRESULT
WINAPI
ID3DXMatrixStackImpl_TranslateLocal
(
ID3DXMatrixStack
*
iface
,
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
{
D3DXMATRIX
temp
;
ID3DXMatrixStackImpl
*
This
=
(
ID3DXMatrixStackImpl
*
)
iface
;
TRACE
(
"iface %p
\n
"
,
iface
);
D3DXMatrixTranslation
(
&
temp
,
x
,
y
,
z
);
D3DXMatrixMultiply
(
&
This
->
stack
[
This
->
current
],
&
temp
,
&
This
->
stack
[
This
->
current
]);
return
D3D_OK
;
}
static
const
ID3DXMatrixStackVtbl
ID3DXMatrixStack_Vtbl
=
{
ID3DXMatrixStackImpl_QueryInterface
,
ID3DXMatrixStackImpl_AddRef
,
ID3DXMatrixStackImpl_Release
,
ID3DXMatrixStackImpl_Pop
,
ID3DXMatrixStackImpl_Push
,
ID3DXMatrixStackImpl_LoadIdentity
,
ID3DXMatrixStackImpl_LoadMatrix
,
ID3DXMatrixStackImpl_MultMatrix
,
ID3DXMatrixStackImpl_MultMatrixLocal
,
ID3DXMatrixStackImpl_RotateAxis
,
ID3DXMatrixStackImpl_RotateAxisLocal
,
ID3DXMatrixStackImpl_RotateYawPitchRoll
,
ID3DXMatrixStackImpl_RotateYawPitchRollLocal
,
ID3DXMatrixStackImpl_Scale
,
ID3DXMatrixStackImpl_ScaleLocal
,
ID3DXMatrixStackImpl_Translate
,
ID3DXMatrixStackImpl_TranslateLocal
,
ID3DXMatrixStackImpl_GetTop
};
/*_________________D3DXPLANE________________*/
D3DXPLANE
*
WINAPI
D3DXPlaneFromPointNormal
(
D3DXPLANE
*
pout
,
CONST
D3DXVECTOR3
*
pvpoint
,
CONST
D3DXVECTOR3
*
pvnormal
)
{
pout
->
a
=
pvnormal
->
x
;
pout
->
b
=
pvnormal
->
y
;
pout
->
c
=
pvnormal
->
z
;
pout
->
d
=
-
D3DXVec3Dot
(
pvpoint
,
pvnormal
);
return
pout
;
}
D3DXPLANE
*
WINAPI
D3DXPlaneFromPoints
(
D3DXPLANE
*
pout
,
CONST
D3DXVECTOR3
*
pv1
,
CONST
D3DXVECTOR3
*
pv2
,
CONST
D3DXVECTOR3
*
pv3
)
{
D3DXVECTOR3
edge1
,
edge2
,
normal
,
Nnormal
;
edge1
.
x
=
0
.
0
f
;
edge1
.
y
=
0
.
0
f
;
edge1
.
z
=
0
.
0
f
;
edge2
.
x
=
0
.
0
f
;
edge2
.
y
=
0
.
0
f
;
edge2
.
z
=
0
.
0
f
;
D3DXVec3Subtract
(
&
edge1
,
pv2
,
pv1
);
D3DXVec3Subtract
(
&
edge2
,
pv3
,
pv1
);
D3DXVec3Cross
(
&
normal
,
&
edge1
,
&
edge2
);
D3DXVec3Normalize
(
&
Nnormal
,
&
normal
);
D3DXPlaneFromPointNormal
(
pout
,
pv1
,
&
Nnormal
);
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXPlaneIntersectLine
(
D3DXVECTOR3
*
pout
,
CONST
D3DXPLANE
*
pp
,
CONST
D3DXVECTOR3
*
pv1
,
CONST
D3DXVECTOR3
*
pv2
)
{
D3DXVECTOR3
direction
,
normal
;
FLOAT
dot
,
temp
;
normal
.
x
=
pp
->
a
;
normal
.
y
=
pp
->
b
;
normal
.
z
=
pp
->
c
;
direction
.
x
=
pv2
->
x
-
pv1
->
x
;
direction
.
y
=
pv2
->
y
-
pv1
->
y
;
direction
.
z
=
pv2
->
z
-
pv1
->
z
;
dot
=
D3DXVec3Dot
(
&
normal
,
&
direction
);
if
(
!
dot
)
return
NULL
;
temp
=
(
pp
->
d
+
D3DXVec3Dot
(
&
normal
,
pv1
)
)
/
dot
;
pout
->
x
=
pv1
->
x
-
temp
*
direction
.
x
;
pout
->
y
=
pv1
->
y
-
temp
*
direction
.
y
;
pout
->
z
=
pv1
->
z
-
temp
*
direction
.
z
;
return
pout
;
}
D3DXPLANE
*
WINAPI
D3DXPlaneNormalize
(
D3DXPLANE
*
pout
,
CONST
D3DXPLANE
*
pp
)
{
D3DXPLANE
out
;
FLOAT
norm
;
norm
=
sqrt
(
pp
->
a
*
pp
->
a
+
pp
->
b
*
pp
->
b
+
pp
->
c
*
pp
->
c
);
if
(
norm
)
{
out
.
a
=
pp
->
a
/
norm
;
out
.
b
=
pp
->
b
/
norm
;
out
.
c
=
pp
->
c
/
norm
;
out
.
d
=
pp
->
d
/
norm
;
}
else
{
out
.
a
=
0
.
0
f
;
out
.
b
=
0
.
0
f
;
out
.
c
=
0
.
0
f
;
out
.
d
=
0
.
0
f
;
}
*
pout
=
out
;
return
pout
;
}
D3DXPLANE
*
WINAPI
D3DXPlaneTransform
(
D3DXPLANE
*
pout
,
CONST
D3DXPLANE
*
pplane
,
CONST
D3DXMATRIX
*
pm
)
{
CONST
D3DXPLANE
plane
=
*
pplane
;
pout
->
a
=
pm
->
u
.
m
[
0
][
0
]
*
plane
.
a
+
pm
->
u
.
m
[
1
][
0
]
*
plane
.
b
+
pm
->
u
.
m
[
2
][
0
]
*
plane
.
c
+
pm
->
u
.
m
[
3
][
0
]
*
plane
.
d
;
pout
->
b
=
pm
->
u
.
m
[
0
][
1
]
*
plane
.
a
+
pm
->
u
.
m
[
1
][
1
]
*
plane
.
b
+
pm
->
u
.
m
[
2
][
1
]
*
plane
.
c
+
pm
->
u
.
m
[
3
][
1
]
*
plane
.
d
;
pout
->
c
=
pm
->
u
.
m
[
0
][
2
]
*
plane
.
a
+
pm
->
u
.
m
[
1
][
2
]
*
plane
.
b
+
pm
->
u
.
m
[
2
][
2
]
*
plane
.
c
+
pm
->
u
.
m
[
3
][
2
]
*
plane
.
d
;
pout
->
d
=
pm
->
u
.
m
[
0
][
3
]
*
plane
.
a
+
pm
->
u
.
m
[
1
][
3
]
*
plane
.
b
+
pm
->
u
.
m
[
2
][
3
]
*
plane
.
c
+
pm
->
u
.
m
[
3
][
3
]
*
plane
.
d
;
return
pout
;
}
D3DXPLANE
*
WINAPI
D3DXPlaneTransformArray
(
D3DXPLANE
*
out
,
UINT
outstride
,
CONST
D3DXPLANE
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXPlaneTransform
(
(
D3DXPLANE
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXPLANE
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
}
return
out
;
}
/*_________________D3DXQUATERNION________________*/
D3DXQUATERNION
*
WINAPI
D3DXQuaternionBaryCentric
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq1
,
CONST
D3DXQUATERNION
*
pq2
,
CONST
D3DXQUATERNION
*
pq3
,
FLOAT
f
,
FLOAT
g
)
{
D3DXQUATERNION
temp1
,
temp2
;
D3DXQuaternionSlerp
(
pout
,
D3DXQuaternionSlerp
(
&
temp1
,
pq1
,
pq2
,
f
+
g
),
D3DXQuaternionSlerp
(
&
temp2
,
pq1
,
pq3
,
f
+
g
),
g
/
(
f
+
g
));
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionExp
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq
)
{
FLOAT
norm
;
norm
=
sqrt
(
pq
->
x
*
pq
->
x
+
pq
->
y
*
pq
->
y
+
pq
->
z
*
pq
->
z
);
if
(
norm
)
{
pout
->
x
=
sin
(
norm
)
*
pq
->
x
/
norm
;
pout
->
y
=
sin
(
norm
)
*
pq
->
y
/
norm
;
pout
->
z
=
sin
(
norm
)
*
pq
->
z
/
norm
;
pout
->
w
=
cos
(
norm
);
}
else
{
pout
->
x
=
0
.
0
f
;
pout
->
y
=
0
.
0
f
;
pout
->
z
=
0
.
0
f
;
pout
->
w
=
1
.
0
f
;
}
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionInverse
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq
)
{
FLOAT
norm
;
norm
=
D3DXQuaternionLengthSq
(
pq
);
if
(
!
norm
)
{
pout
->
x
=
0
.
0
f
;
pout
->
y
=
0
.
0
f
;
pout
->
z
=
0
.
0
f
;
pout
->
w
=
0
.
0
f
;
}
else
{
pout
->
x
=
-
pq
->
x
/
norm
;
pout
->
y
=
-
pq
->
y
/
norm
;
pout
->
z
=
-
pq
->
z
/
norm
;
pout
->
w
=
pq
->
w
/
norm
;
}
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionLn
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq
)
{
FLOAT
norm
,
normvec
,
theta
;
norm
=
D3DXQuaternionLengthSq
(
pq
);
if
(
norm
>
1
.
0001
f
)
{
pout
->
x
=
pq
->
x
;
pout
->
y
=
pq
->
y
;
pout
->
z
=
pq
->
z
;
pout
->
w
=
0
.
0
f
;
}
else
if
(
norm
>
0
.
99999
f
)
{
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
.
0
f
;
}
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
);
}
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionMultiply
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq1
,
CONST
D3DXQUATERNION
*
pq2
)
{
D3DXQUATERNION
out
;
out
.
x
=
pq2
->
w
*
pq1
->
x
+
pq2
->
x
*
pq1
->
w
+
pq2
->
y
*
pq1
->
z
-
pq2
->
z
*
pq1
->
y
;
out
.
y
=
pq2
->
w
*
pq1
->
y
-
pq2
->
x
*
pq1
->
z
+
pq2
->
y
*
pq1
->
w
+
pq2
->
z
*
pq1
->
x
;
out
.
z
=
pq2
->
w
*
pq1
->
z
+
pq2
->
x
*
pq1
->
y
-
pq2
->
y
*
pq1
->
x
+
pq2
->
z
*
pq1
->
w
;
out
.
w
=
pq2
->
w
*
pq1
->
w
-
pq2
->
x
*
pq1
->
x
-
pq2
->
y
*
pq1
->
y
-
pq2
->
z
*
pq1
->
z
;
*
pout
=
out
;
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionNormalize
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq
)
{
D3DXQUATERNION
out
;
FLOAT
norm
;
norm
=
D3DXQuaternionLength
(
pq
);
if
(
!
norm
)
{
out
.
x
=
0
.
0
f
;
out
.
y
=
0
.
0
f
;
out
.
z
=
0
.
0
f
;
out
.
w
=
0
.
0
f
;
}
else
{
out
.
x
=
pq
->
x
/
norm
;
out
.
y
=
pq
->
y
/
norm
;
out
.
z
=
pq
->
z
/
norm
;
out
.
w
=
pq
->
w
/
norm
;
}
*
pout
=
out
;
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionRotationAxis
(
D3DXQUATERNION
*
pout
,
CONST
D3DXVECTOR3
*
pv
,
FLOAT
angle
)
{
D3DXVECTOR3
temp
;
D3DXVec3Normalize
(
&
temp
,
pv
);
pout
->
x
=
sin
(
angle
/
2
.
0
f
)
*
temp
.
x
;
pout
->
y
=
sin
(
angle
/
2
.
0
f
)
*
temp
.
y
;
pout
->
z
=
sin
(
angle
/
2
.
0
f
)
*
temp
.
z
;
pout
->
w
=
cos
(
angle
/
2
.
0
f
);
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionRotationMatrix
(
D3DXQUATERNION
*
pout
,
CONST
D3DXMATRIX
*
pm
)
{
int
i
,
maxi
;
FLOAT
maxdiag
,
S
,
trace
;
trace
=
pm
->
u
.
m
[
0
][
0
]
+
pm
->
u
.
m
[
1
][
1
]
+
pm
->
u
.
m
[
2
][
2
]
+
1
.
0
f
;
if
(
trace
>
1
.
0
f
)
{
pout
->
x
=
(
pm
->
u
.
m
[
1
][
2
]
-
pm
->
u
.
m
[
2
][
1
]
)
/
(
2
.
0
f
*
sqrt
(
trace
)
);
pout
->
y
=
(
pm
->
u
.
m
[
2
][
0
]
-
pm
->
u
.
m
[
0
][
2
]
)
/
(
2
.
0
f
*
sqrt
(
trace
)
);
pout
->
z
=
(
pm
->
u
.
m
[
0
][
1
]
-
pm
->
u
.
m
[
1
][
0
]
)
/
(
2
.
0
f
*
sqrt
(
trace
)
);
pout
->
w
=
sqrt
(
trace
)
/
2
.
0
f
;
return
pout
;
}
maxi
=
0
;
maxdiag
=
pm
->
u
.
m
[
0
][
0
];
for
(
i
=
1
;
i
<
3
;
i
++
)
{
if
(
pm
->
u
.
m
[
i
][
i
]
>
maxdiag
)
{
maxi
=
i
;
maxdiag
=
pm
->
u
.
m
[
i
][
i
];
}
}
switch
(
maxi
)
{
case
0
:
S
=
2
.
0
f
*
sqrt
(
1
.
0
f
+
pm
->
u
.
m
[
0
][
0
]
-
pm
->
u
.
m
[
1
][
1
]
-
pm
->
u
.
m
[
2
][
2
]);
pout
->
x
=
0
.
25
f
*
S
;
pout
->
y
=
(
pm
->
u
.
m
[
0
][
1
]
+
pm
->
u
.
m
[
1
][
0
]
)
/
S
;
pout
->
z
=
(
pm
->
u
.
m
[
0
][
2
]
+
pm
->
u
.
m
[
2
][
0
]
)
/
S
;
pout
->
w
=
(
pm
->
u
.
m
[
1
][
2
]
-
pm
->
u
.
m
[
2
][
1
]
)
/
S
;
break
;
case
1
:
S
=
2
.
0
f
*
sqrt
(
1
.
0
f
+
pm
->
u
.
m
[
1
][
1
]
-
pm
->
u
.
m
[
0
][
0
]
-
pm
->
u
.
m
[
2
][
2
]);
pout
->
x
=
(
pm
->
u
.
m
[
0
][
1
]
+
pm
->
u
.
m
[
1
][
0
]
)
/
S
;
pout
->
y
=
0
.
25
f
*
S
;
pout
->
z
=
(
pm
->
u
.
m
[
1
][
2
]
+
pm
->
u
.
m
[
2
][
1
]
)
/
S
;
pout
->
w
=
(
pm
->
u
.
m
[
2
][
0
]
-
pm
->
u
.
m
[
0
][
2
]
)
/
S
;
break
;
case
2
:
S
=
2
.
0
f
*
sqrt
(
1
.
0
f
+
pm
->
u
.
m
[
2
][
2
]
-
pm
->
u
.
m
[
0
][
0
]
-
pm
->
u
.
m
[
1
][
1
]);
pout
->
x
=
(
pm
->
u
.
m
[
0
][
2
]
+
pm
->
u
.
m
[
2
][
0
]
)
/
S
;
pout
->
y
=
(
pm
->
u
.
m
[
1
][
2
]
+
pm
->
u
.
m
[
2
][
1
]
)
/
S
;
pout
->
z
=
0
.
25
f
*
S
;
pout
->
w
=
(
pm
->
u
.
m
[
0
][
1
]
-
pm
->
u
.
m
[
1
][
0
]
)
/
S
;
break
;
}
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionRotationYawPitchRoll
(
D3DXQUATERNION
*
pout
,
FLOAT
yaw
,
FLOAT
pitch
,
FLOAT
roll
)
{
pout
->
x
=
sin
(
yaw
/
2
.
0
f
)
*
cos
(
pitch
/
2
.
0
f
)
*
sin
(
roll
/
2
.
0
f
)
+
cos
(
yaw
/
2
.
0
f
)
*
sin
(
pitch
/
2
.
0
f
)
*
cos
(
roll
/
2
.
0
f
);
pout
->
y
=
sin
(
yaw
/
2
.
0
f
)
*
cos
(
pitch
/
2
.
0
f
)
*
cos
(
roll
/
2
.
0
f
)
-
cos
(
yaw
/
2
.
0
f
)
*
sin
(
pitch
/
2
.
0
f
)
*
sin
(
roll
/
2
.
0
f
);
pout
->
z
=
cos
(
yaw
/
2
.
0
f
)
*
cos
(
pitch
/
2
.
0
f
)
*
sin
(
roll
/
2
.
0
f
)
-
sin
(
yaw
/
2
.
0
f
)
*
sin
(
pitch
/
2
.
0
f
)
*
cos
(
roll
/
2
.
0
f
);
pout
->
w
=
cos
(
yaw
/
2
.
0
f
)
*
cos
(
pitch
/
2
.
0
f
)
*
cos
(
roll
/
2
.
0
f
)
+
sin
(
yaw
/
2
.
0
f
)
*
sin
(
pitch
/
2
.
0
f
)
*
sin
(
roll
/
2
.
0
f
);
return
pout
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionSlerp
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq1
,
CONST
D3DXQUATERNION
*
pq2
,
FLOAT
t
)
{
FLOAT
dot
,
epsilon
,
temp
,
theta
,
u
;
epsilon
=
1
.
0
f
;
temp
=
1
.
0
f
-
t
;
u
=
t
;
dot
=
D3DXQuaternionDot
(
pq1
,
pq2
);
if
(
dot
<
0
.
0
f
)
{
epsilon
=
-
1
.
0
f
;
dot
=
-
dot
;
}
if
(
1
.
0
f
-
dot
>
0
.
001
f
)
{
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
;
}
D3DXQUATERNION
*
WINAPI
D3DXQuaternionSquad
(
D3DXQUATERNION
*
pout
,
CONST
D3DXQUATERNION
*
pq1
,
CONST
D3DXQUATERNION
*
pq2
,
CONST
D3DXQUATERNION
*
pq3
,
CONST
D3DXQUATERNION
*
pq4
,
FLOAT
t
)
{
D3DXQUATERNION
temp1
,
temp2
;
D3DXQuaternionSlerp
(
pout
,
D3DXQuaternionSlerp
(
&
temp1
,
pq1
,
pq4
,
t
),
D3DXQuaternionSlerp
(
&
temp2
,
pq2
,
pq3
,
t
),
2
.
0
f
*
t
*
(
1
.
0
f
-
t
));
return
pout
;
}
void
WINAPI
D3DXQuaternionToAxisAngle
(
CONST
D3DXQUATERNION
*
pq
,
D3DXVECTOR3
*
paxis
,
FLOAT
*
pangle
)
{
FLOAT
norm
;
*
pangle
=
0
.
0
f
;
norm
=
D3DXQuaternionLength
(
pq
);
if
(
norm
)
{
paxis
->
x
=
pq
->
x
/
norm
;
paxis
->
y
=
pq
->
y
/
norm
;
paxis
->
z
=
pq
->
z
/
norm
;
if
(
fabs
(
pq
->
w
)
<=
1
.
0
f
)
*
pangle
=
2
.
0
f
*
acos
(
pq
->
w
);
}
else
{
paxis
->
x
=
1
.
0
f
;
paxis
->
y
=
0
.
0
f
;
paxis
->
z
=
0
.
0
f
;
}
}
/*_________________D3DXVec2_____________________*/
D3DXVECTOR2
*
WINAPI
D3DXVec2BaryCentric
(
D3DXVECTOR2
*
pout
,
CONST
D3DXVECTOR2
*
pv1
,
CONST
D3DXVECTOR2
*
pv2
,
CONST
D3DXVECTOR2
*
pv3
,
FLOAT
f
,
FLOAT
g
)
{
pout
->
x
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
x
)
+
f
*
(
pv2
->
x
)
+
g
*
(
pv3
->
x
);
pout
->
y
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
y
)
+
f
*
(
pv2
->
y
)
+
g
*
(
pv3
->
y
);
return
pout
;
}
D3DXVECTOR2
*
WINAPI
D3DXVec2CatmullRom
(
D3DXVECTOR2
*
pout
,
CONST
D3DXVECTOR2
*
pv0
,
CONST
D3DXVECTOR2
*
pv1
,
CONST
D3DXVECTOR2
*
pv2
,
CONST
D3DXVECTOR2
*
pv3
,
FLOAT
s
)
{
pout
->
x
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
x
+
(
pv2
->
x
-
pv0
->
x
)
*
s
+
(
2
.
0
f
*
pv0
->
x
-
5
.
0
f
*
pv1
->
x
+
4
.
0
f
*
pv2
->
x
-
pv3
->
x
)
*
s
*
s
+
(
pv3
->
x
-
3
.
0
f
*
pv2
->
x
+
3
.
0
f
*
pv1
->
x
-
pv0
->
x
)
*
s
*
s
*
s
);
pout
->
y
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
y
+
(
pv2
->
y
-
pv0
->
y
)
*
s
+
(
2
.
0
f
*
pv0
->
y
-
5
.
0
f
*
pv1
->
y
+
4
.
0
f
*
pv2
->
y
-
pv3
->
y
)
*
s
*
s
+
(
pv3
->
y
-
3
.
0
f
*
pv2
->
y
+
3
.
0
f
*
pv1
->
y
-
pv0
->
y
)
*
s
*
s
*
s
);
return
pout
;
}
D3DXVECTOR2
*
WINAPI
D3DXVec2Hermite
(
D3DXVECTOR2
*
pout
,
CONST
D3DXVECTOR2
*
pv1
,
CONST
D3DXVECTOR2
*
pt1
,
CONST
D3DXVECTOR2
*
pv2
,
CONST
D3DXVECTOR2
*
pt2
,
FLOAT
s
)
{
FLOAT
h1
,
h2
,
h3
,
h4
;
h1
=
2
.
0
f
*
s
*
s
*
s
-
3
.
0
f
*
s
*
s
+
1
.
0
f
;
h2
=
s
*
s
*
s
-
2
.
0
f
*
s
*
s
+
s
;
h3
=
-
2
.
0
f
*
s
*
s
*
s
+
3
.
0
f
*
s
*
s
;
h4
=
s
*
s
*
s
-
s
*
s
;
pout
->
x
=
h1
*
(
pv1
->
x
)
+
h2
*
(
pt1
->
x
)
+
h3
*
(
pv2
->
x
)
+
h4
*
(
pt2
->
x
);
pout
->
y
=
h1
*
(
pv1
->
y
)
+
h2
*
(
pt1
->
y
)
+
h3
*
(
pv2
->
y
)
+
h4
*
(
pt2
->
y
);
return
pout
;
}
D3DXVECTOR2
*
WINAPI
D3DXVec2Normalize
(
D3DXVECTOR2
*
pout
,
CONST
D3DXVECTOR2
*
pv
)
{
D3DXVECTOR2
out
;
FLOAT
norm
;
norm
=
D3DXVec2Length
(
pv
);
if
(
!
norm
)
{
out
.
x
=
0
.
0
f
;
out
.
y
=
0
.
0
f
;
}
else
{
out
.
x
=
pv
->
x
/
norm
;
out
.
y
=
pv
->
y
/
norm
;
}
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec2Transform
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR2
*
pv
,
CONST
D3DXMATRIX
*
pm
)
{
pout
->
x
=
pm
->
u
.
m
[
0
][
0
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
0
]
*
pv
->
y
+
pm
->
u
.
m
[
3
][
0
];
pout
->
y
=
pm
->
u
.
m
[
0
][
1
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
1
]
*
pv
->
y
+
pm
->
u
.
m
[
3
][
1
];
pout
->
z
=
pm
->
u
.
m
[
0
][
2
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
2
]
*
pv
->
y
+
pm
->
u
.
m
[
3
][
2
];
pout
->
w
=
pm
->
u
.
m
[
0
][
3
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
3
]
*
pv
->
y
+
pm
->
u
.
m
[
3
][
3
];
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec2TransformArray
(
D3DXVECTOR4
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR2
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec2Transform
(
(
D3DXVECTOR4
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR2
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
}
return
out
;
}
D3DXVECTOR2
*
WINAPI
D3DXVec2TransformCoord
(
D3DXVECTOR2
*
pout
,
CONST
D3DXVECTOR2
*
pv
,
CONST
D3DXMATRIX
*
pm
)
{
FLOAT
norm
;
norm
=
pm
->
u
.
m
[
0
][
3
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
3
]
*
pv
->
y
+
pm
->
u
.
m
[
3
][
3
];
if
(
norm
)
{
CONST
D3DXVECTOR2
v
=
*
pv
;
pout
->
x
=
(
pm
->
u
.
m
[
0
][
0
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
0
]
*
v
.
y
+
pm
->
u
.
m
[
3
][
0
])
/
norm
;
pout
->
y
=
(
pm
->
u
.
m
[
0
][
1
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
1
]
*
v
.
y
+
pm
->
u
.
m
[
3
][
1
])
/
norm
;
}
else
{
pout
->
x
=
0
.
0
f
;
pout
->
y
=
0
.
0
f
;
}
return
pout
;
}
D3DXVECTOR2
*
WINAPI
D3DXVec2TransformCoordArray
(
D3DXVECTOR2
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR2
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec2TransformCoord
(
(
D3DXVECTOR2
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR2
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
}
return
out
;
}
D3DXVECTOR2
*
WINAPI
D3DXVec2TransformNormal
(
D3DXVECTOR2
*
pout
,
CONST
D3DXVECTOR2
*
pv
,
CONST
D3DXMATRIX
*
pm
)
{
CONST
D3DXVECTOR2
v
=
*
pv
;
pout
->
x
=
pm
->
u
.
m
[
0
][
0
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
0
]
*
v
.
y
;
pout
->
y
=
pm
->
u
.
m
[
0
][
1
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
1
]
*
v
.
y
;
return
pout
;
}
D3DXVECTOR2
*
WINAPI
D3DXVec2TransformNormalArray
(
D3DXVECTOR2
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR2
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec2TransformNormal
(
(
D3DXVECTOR2
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR2
*
)((
const
char
*
)
in
+
instride
*
i
),
matrix
);
}
return
out
;
}
/*_________________D3DXVec3_____________________*/
D3DXVECTOR3
*
WINAPI
D3DXVec3BaryCentric
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv1
,
CONST
D3DXVECTOR3
*
pv2
,
CONST
D3DXVECTOR3
*
pv3
,
FLOAT
f
,
FLOAT
g
)
{
pout
->
x
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
x
)
+
f
*
(
pv2
->
x
)
+
g
*
(
pv3
->
x
);
pout
->
y
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
y
)
+
f
*
(
pv2
->
y
)
+
g
*
(
pv3
->
y
);
pout
->
z
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
z
)
+
f
*
(
pv2
->
z
)
+
g
*
(
pv3
->
z
);
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3CatmullRom
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv0
,
CONST
D3DXVECTOR3
*
pv1
,
CONST
D3DXVECTOR3
*
pv2
,
CONST
D3DXVECTOR3
*
pv3
,
FLOAT
s
)
{
pout
->
x
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
x
+
(
pv2
->
x
-
pv0
->
x
)
*
s
+
(
2
.
0
f
*
pv0
->
x
-
5
.
0
f
*
pv1
->
x
+
4
.
0
f
*
pv2
->
x
-
pv3
->
x
)
*
s
*
s
+
(
pv3
->
x
-
3
.
0
f
*
pv2
->
x
+
3
.
0
f
*
pv1
->
x
-
pv0
->
x
)
*
s
*
s
*
s
);
pout
->
y
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
y
+
(
pv2
->
y
-
pv0
->
y
)
*
s
+
(
2
.
0
f
*
pv0
->
y
-
5
.
0
f
*
pv1
->
y
+
4
.
0
f
*
pv2
->
y
-
pv3
->
y
)
*
s
*
s
+
(
pv3
->
y
-
3
.
0
f
*
pv2
->
y
+
3
.
0
f
*
pv1
->
y
-
pv0
->
y
)
*
s
*
s
*
s
);
pout
->
z
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
z
+
(
pv2
->
z
-
pv0
->
z
)
*
s
+
(
2
.
0
f
*
pv0
->
z
-
5
.
0
f
*
pv1
->
z
+
4
.
0
f
*
pv2
->
z
-
pv3
->
z
)
*
s
*
s
+
(
pv3
->
z
-
3
.
0
f
*
pv2
->
z
+
3
.
0
f
*
pv1
->
z
-
pv0
->
z
)
*
s
*
s
*
s
);
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3Hermite
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv1
,
CONST
D3DXVECTOR3
*
pt1
,
CONST
D3DXVECTOR3
*
pv2
,
CONST
D3DXVECTOR3
*
pt2
,
FLOAT
s
)
{
FLOAT
h1
,
h2
,
h3
,
h4
;
h1
=
2
.
0
f
*
s
*
s
*
s
-
3
.
0
f
*
s
*
s
+
1
.
0
f
;
h2
=
s
*
s
*
s
-
2
.
0
f
*
s
*
s
+
s
;
h3
=
-
2
.
0
f
*
s
*
s
*
s
+
3
.
0
f
*
s
*
s
;
h4
=
s
*
s
*
s
-
s
*
s
;
pout
->
x
=
h1
*
(
pv1
->
x
)
+
h2
*
(
pt1
->
x
)
+
h3
*
(
pv2
->
x
)
+
h4
*
(
pt2
->
x
);
pout
->
y
=
h1
*
(
pv1
->
y
)
+
h2
*
(
pt1
->
y
)
+
h3
*
(
pv2
->
y
)
+
h4
*
(
pt2
->
y
);
pout
->
z
=
h1
*
(
pv1
->
z
)
+
h2
*
(
pt1
->
z
)
+
h3
*
(
pv2
->
z
)
+
h4
*
(
pt2
->
z
);
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3Normalize
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv
)
{
D3DXVECTOR3
out
;
FLOAT
norm
;
norm
=
D3DXVec3Length
(
pv
);
if
(
!
norm
)
{
out
.
x
=
0
.
0
f
;
out
.
y
=
0
.
0
f
;
out
.
z
=
0
.
0
f
;
}
else
{
out
.
x
=
pv
->
x
/
norm
;
out
.
y
=
pv
->
y
/
norm
;
out
.
z
=
pv
->
z
/
norm
;
}
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3Project
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv
,
CONST
D3DVIEWPORT9
*
pviewport
,
CONST
D3DXMATRIX
*
pprojection
,
CONST
D3DXMATRIX
*
pview
,
CONST
D3DXMATRIX
*
pworld
)
{
D3DXMATRIX
m
;
D3DXVECTOR3
out
;
D3DXMatrixMultiply
(
&
m
,
pworld
,
pview
);
D3DXMatrixMultiply
(
&
m
,
&
m
,
pprojection
);
D3DXVec3TransformCoord
(
&
out
,
pv
,
&
m
);
out
.
x
=
pviewport
->
X
+
(
1
.
0
f
+
out
.
x
)
*
pviewport
->
Width
/
2
.
0
f
;
out
.
y
=
pviewport
->
Y
+
(
1
.
0
f
-
out
.
y
)
*
pviewport
->
Height
/
2
.
0
f
;
out
.
z
=
pviewport
->
MinZ
+
out
.
z
*
(
pviewport
->
MaxZ
-
pviewport
->
MinZ
);
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3ProjectArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DVIEWPORT9
*
viewport
,
CONST
D3DXMATRIX
*
projection
,
CONST
D3DXMATRIX
*
view
,
CONST
D3DXMATRIX
*
world
,
UINT
elements
)
{
UINT
i
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec3Project
(
(
D3DXVECTOR3
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR3
*
)((
const
char
*
)
in
+
instride
*
i
),
viewport
,
projection
,
view
,
world
);
}
return
out
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec3Transform
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR3
*
pv
,
CONST
D3DXMATRIX
*
pm
)
{
pout
->
x
=
pm
->
u
.
m
[
0
][
0
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
0
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
0
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
0
];
pout
->
y
=
pm
->
u
.
m
[
0
][
1
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
1
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
1
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
1
];
pout
->
z
=
pm
->
u
.
m
[
0
][
2
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
2
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
2
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
2
];
pout
->
w
=
pm
->
u
.
m
[
0
][
3
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
3
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
3
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
3
];
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec3TransformArray
(
D3DXVECTOR4
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
for
(
i
=
0
;
i
<
elements
;
++
i
)
{
D3DXVec3Transform
(
(
D3DXVECTOR4
*
)((
char
*
)
out
+
outstride
*
i
),
(
CONST
D3DXVECTOR3
*
)((
const
char
*
)
in
+
instride
*
i
),
...
...
@@ -325,12 +1622,31 @@ D3DXVECTOR4* WINAPI D3DXVec3TransformArray(
return
out
;
}
/*************************************************************************
* D3DXVec3TransformCoordArray
*/
D3DXVECTOR3
*
WINAPI
D3DXVec3TransformCoordArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
D3DXVECTOR3
*
WINAPI
D3DXVec3TransformCoord
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv
,
CONST
D3DXMATRIX
*
pm
)
{
D3DXVECTOR3
out
;
FLOAT
norm
;
norm
=
pm
->
u
.
m
[
0
][
3
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
3
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
3
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
3
];
if
(
norm
)
{
CONST
D3DXVECTOR3
v
=
*
pv
;
out
.
x
=
(
pm
->
u
.
m
[
0
][
0
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
0
]
*
v
.
y
+
pm
->
u
.
m
[
2
][
0
]
*
v
.
z
+
pm
->
u
.
m
[
3
][
0
])
/
norm
;
out
.
y
=
(
pm
->
u
.
m
[
0
][
1
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
1
]
*
v
.
y
+
pm
->
u
.
m
[
2
][
1
]
*
v
.
z
+
pm
->
u
.
m
[
3
][
1
])
/
norm
;
out
.
z
=
(
pm
->
u
.
m
[
0
][
2
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
2
]
*
v
.
y
+
pm
->
u
.
m
[
2
][
2
]
*
v
.
z
+
pm
->
u
.
m
[
3
][
2
])
/
norm
;
}
else
{
out
.
x
=
0
.
0
f
;
out
.
y
=
0
.
0
f
;
out
.
z
=
0
.
0
f
;
}
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3TransformCoordArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
...
...
@@ -343,12 +1659,17 @@ D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray(
return
out
;
}
/*************************************************************************
* D3DXVec3TransformNormalArray
*/
D3DXVECTOR3
*
WINAPI
D3DXVec3TransformNormalArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
D3DXVECTOR3
*
WINAPI
D3DXVec3TransformNormal
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv
,
CONST
D3DXMATRIX
*
pm
)
{
CONST
D3DXVECTOR3
v
=
*
pv
;
pout
->
x
=
pm
->
u
.
m
[
0
][
0
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
0
]
*
v
.
y
+
pm
->
u
.
m
[
2
][
0
]
*
v
.
z
;
pout
->
y
=
pm
->
u
.
m
[
0
][
1
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
1
]
*
v
.
y
+
pm
->
u
.
m
[
2
][
1
]
*
v
.
z
;
pout
->
z
=
pm
->
u
.
m
[
0
][
2
]
*
v
.
x
+
pm
->
u
.
m
[
1
][
2
]
*
v
.
y
+
pm
->
u
.
m
[
2
][
2
]
*
v
.
z
;
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3TransformNormalArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
...
...
@@ -361,13 +1682,23 @@ D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray(
return
out
;
}
/*************************************************************************
* D3DXVec3UnprojectArray
*/
D3DXVECTOR3
*
WINAPI
D3DXVec3UnprojectArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DVIEWPORT9
*
viewport
,
CONST
D3DXMATRIX
*
projection
,
CONST
D3DXMATRIX
*
view
,
CONST
D3DXMATRIX
*
world
,
UINT
elements
)
D3DXVECTOR3
*
WINAPI
D3DXVec3Unproject
(
D3DXVECTOR3
*
pout
,
CONST
D3DXVECTOR3
*
pv
,
CONST
D3DVIEWPORT9
*
pviewport
,
CONST
D3DXMATRIX
*
pprojection
,
CONST
D3DXMATRIX
*
pview
,
CONST
D3DXMATRIX
*
pworld
)
{
D3DXMATRIX
m
;
D3DXVECTOR3
out
;
D3DXMatrixMultiply
(
&
m
,
pworld
,
pview
);
D3DXMatrixMultiply
(
&
m
,
&
m
,
pprojection
);
D3DXMatrixInverse
(
&
m
,
NULL
,
&
m
);
out
.
x
=
2
.
0
f
*
(
pv
->
x
-
pviewport
->
X
)
/
pviewport
->
Width
-
1
.
0
f
;
out
.
y
=
1
.
0
f
-
2
.
0
f
*
(
pv
->
y
-
pviewport
->
Y
)
/
pviewport
->
Height
;
out
.
z
=
(
pv
->
z
-
pviewport
->
MinZ
)
/
(
pviewport
->
MaxZ
-
pviewport
->
MinZ
);
D3DXVec3TransformCoord
(
&
out
,
&
out
,
&
m
);
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR3
*
WINAPI
D3DXVec3UnprojectArray
(
D3DXVECTOR3
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR3
*
in
,
UINT
instride
,
CONST
D3DVIEWPORT9
*
viewport
,
CONST
D3DXMATRIX
*
projection
,
CONST
D3DXMATRIX
*
view
,
CONST
D3DXMATRIX
*
world
,
UINT
elements
)
{
UINT
i
;
...
...
@@ -380,12 +1711,89 @@ D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray(
return
out
;
}
/*************************************************************************
* D3DXVec4TransformArray
*/
D3DXVECTOR4
*
WINAPI
D3DXVec4TransformArray
(
D3DXVECTOR4
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR4
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
/*_________________D3DXVec4_____________________*/
D3DXVECTOR4
*
WINAPI
D3DXVec4BaryCentric
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR4
*
pv1
,
CONST
D3DXVECTOR4
*
pv2
,
CONST
D3DXVECTOR4
*
pv3
,
FLOAT
f
,
FLOAT
g
)
{
pout
->
x
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
x
)
+
f
*
(
pv2
->
x
)
+
g
*
(
pv3
->
x
);
pout
->
y
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
y
)
+
f
*
(
pv2
->
y
)
+
g
*
(
pv3
->
y
);
pout
->
z
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
z
)
+
f
*
(
pv2
->
z
)
+
g
*
(
pv3
->
z
);
pout
->
w
=
(
1
.
0
f
-
f
-
g
)
*
(
pv1
->
w
)
+
f
*
(
pv2
->
w
)
+
g
*
(
pv3
->
w
);
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec4CatmullRom
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR4
*
pv0
,
CONST
D3DXVECTOR4
*
pv1
,
CONST
D3DXVECTOR4
*
pv2
,
CONST
D3DXVECTOR4
*
pv3
,
FLOAT
s
)
{
pout
->
x
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
x
+
(
pv2
->
x
-
pv0
->
x
)
*
s
+
(
2
.
0
f
*
pv0
->
x
-
5
.
0
f
*
pv1
->
x
+
4
.
0
f
*
pv2
->
x
-
pv3
->
x
)
*
s
*
s
+
(
pv3
->
x
-
3
.
0
f
*
pv2
->
x
+
3
.
0
f
*
pv1
->
x
-
pv0
->
x
)
*
s
*
s
*
s
);
pout
->
y
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
y
+
(
pv2
->
y
-
pv0
->
y
)
*
s
+
(
2
.
0
f
*
pv0
->
y
-
5
.
0
f
*
pv1
->
y
+
4
.
0
f
*
pv2
->
y
-
pv3
->
y
)
*
s
*
s
+
(
pv3
->
y
-
3
.
0
f
*
pv2
->
y
+
3
.
0
f
*
pv1
->
y
-
pv0
->
y
)
*
s
*
s
*
s
);
pout
->
z
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
z
+
(
pv2
->
z
-
pv0
->
z
)
*
s
+
(
2
.
0
f
*
pv0
->
z
-
5
.
0
f
*
pv1
->
z
+
4
.
0
f
*
pv2
->
z
-
pv3
->
z
)
*
s
*
s
+
(
pv3
->
z
-
3
.
0
f
*
pv2
->
z
+
3
.
0
f
*
pv1
->
z
-
pv0
->
z
)
*
s
*
s
*
s
);
pout
->
w
=
0
.
5
f
*
(
2
.
0
f
*
pv1
->
w
+
(
pv2
->
w
-
pv0
->
w
)
*
s
+
(
2
.
0
f
*
pv0
->
w
-
5
.
0
f
*
pv1
->
w
+
4
.
0
f
*
pv2
->
w
-
pv3
->
w
)
*
s
*
s
+
(
pv3
->
w
-
3
.
0
f
*
pv2
->
w
+
3
.
0
f
*
pv1
->
w
-
pv0
->
w
)
*
s
*
s
*
s
);
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec4Cross
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR4
*
pv1
,
CONST
D3DXVECTOR4
*
pv2
,
CONST
D3DXVECTOR4
*
pv3
)
{
D3DXVECTOR4
out
;
out
.
x
=
pv1
->
y
*
(
pv2
->
z
*
pv3
->
w
-
pv3
->
z
*
pv2
->
w
)
-
pv1
->
z
*
(
pv2
->
y
*
pv3
->
w
-
pv3
->
y
*
pv2
->
w
)
+
pv1
->
w
*
(
pv2
->
y
*
pv3
->
z
-
pv2
->
z
*
pv3
->
y
);
out
.
y
=
-
(
pv1
->
x
*
(
pv2
->
z
*
pv3
->
w
-
pv3
->
z
*
pv2
->
w
)
-
pv1
->
z
*
(
pv2
->
x
*
pv3
->
w
-
pv3
->
x
*
pv2
->
w
)
+
pv1
->
w
*
(
pv2
->
x
*
pv3
->
z
-
pv3
->
x
*
pv2
->
z
));
out
.
z
=
pv1
->
x
*
(
pv2
->
y
*
pv3
->
w
-
pv3
->
y
*
pv2
->
w
)
-
pv1
->
y
*
(
pv2
->
x
*
pv3
->
w
-
pv3
->
x
*
pv2
->
w
)
+
pv1
->
w
*
(
pv2
->
x
*
pv3
->
y
-
pv3
->
x
*
pv2
->
y
);
out
.
w
=
-
(
pv1
->
x
*
(
pv2
->
y
*
pv3
->
z
-
pv3
->
y
*
pv2
->
z
)
-
pv1
->
y
*
(
pv2
->
x
*
pv3
->
z
-
pv3
->
x
*
pv2
->
z
)
+
pv1
->
z
*
(
pv2
->
x
*
pv3
->
y
-
pv3
->
x
*
pv2
->
y
));
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec4Hermite
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR4
*
pv1
,
CONST
D3DXVECTOR4
*
pt1
,
CONST
D3DXVECTOR4
*
pv2
,
CONST
D3DXVECTOR4
*
pt2
,
FLOAT
s
)
{
FLOAT
h1
,
h2
,
h3
,
h4
;
h1
=
2
.
0
f
*
s
*
s
*
s
-
3
.
0
f
*
s
*
s
+
1
.
0
f
;
h2
=
s
*
s
*
s
-
2
.
0
f
*
s
*
s
+
s
;
h3
=
-
2
.
0
f
*
s
*
s
*
s
+
3
.
0
f
*
s
*
s
;
h4
=
s
*
s
*
s
-
s
*
s
;
pout
->
x
=
h1
*
(
pv1
->
x
)
+
h2
*
(
pt1
->
x
)
+
h3
*
(
pv2
->
x
)
+
h4
*
(
pt2
->
x
);
pout
->
y
=
h1
*
(
pv1
->
y
)
+
h2
*
(
pt1
->
y
)
+
h3
*
(
pv2
->
y
)
+
h4
*
(
pt2
->
y
);
pout
->
z
=
h1
*
(
pv1
->
z
)
+
h2
*
(
pt1
->
z
)
+
h3
*
(
pv2
->
z
)
+
h4
*
(
pt2
->
z
);
pout
->
w
=
h1
*
(
pv1
->
w
)
+
h2
*
(
pt1
->
w
)
+
h3
*
(
pv2
->
w
)
+
h4
*
(
pt2
->
w
);
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec4Normalize
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR4
*
pv
)
{
D3DXVECTOR4
out
;
FLOAT
norm
;
norm
=
D3DXVec4Length
(
pv
);
if
(
!
norm
)
{
out
.
x
=
0
.
0
f
;
out
.
y
=
0
.
0
f
;
out
.
z
=
0
.
0
f
;
out
.
w
=
0
.
0
f
;
}
else
{
out
.
x
=
pv
->
x
/
norm
;
out
.
y
=
pv
->
y
/
norm
;
out
.
z
=
pv
->
z
/
norm
;
out
.
w
=
pv
->
w
/
norm
;
}
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec4Transform
(
D3DXVECTOR4
*
pout
,
CONST
D3DXVECTOR4
*
pv
,
CONST
D3DXMATRIX
*
pm
)
{
D3DXVECTOR4
out
;
out
.
x
=
pm
->
u
.
m
[
0
][
0
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
0
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
0
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
0
]
*
pv
->
w
;
out
.
y
=
pm
->
u
.
m
[
0
][
1
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
1
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
1
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
1
]
*
pv
->
w
;
out
.
z
=
pm
->
u
.
m
[
0
][
2
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
2
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
2
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
2
]
*
pv
->
w
;
out
.
w
=
pm
->
u
.
m
[
0
][
3
]
*
pv
->
x
+
pm
->
u
.
m
[
1
][
3
]
*
pv
->
y
+
pm
->
u
.
m
[
2
][
3
]
*
pv
->
z
+
pm
->
u
.
m
[
3
][
3
]
*
pv
->
w
;
*
pout
=
out
;
return
pout
;
}
D3DXVECTOR4
*
WINAPI
D3DXVec4TransformArray
(
D3DXVECTOR4
*
out
,
UINT
outstride
,
CONST
D3DXVECTOR4
*
in
,
UINT
instride
,
CONST
D3DXMATRIX
*
matrix
,
UINT
elements
)
{
UINT
i
;
...
...
include/d3dx9math.h
View file @
d1c2d2a4
...
...
@@ -30,6 +30,8 @@
#define D3DXToRadian(degree) ((degree) * (D3DX_PI / 180.0f))
#define D3DXToDegree(radian) ((radian) * (180.0f / D3DX_PI))
typedef
struct
D3DXVECTOR2
{
#ifdef __cplusplus
...
...
@@ -266,6 +268,8 @@ extern "C" {
D3DXCOLOR
*
WINAPI
D3DXColorAdjustContrast
(
D3DXCOLOR
*
pout
,
CONST
D3DXCOLOR
*
pc
,
FLOAT
s
);
D3DXCOLOR
*
WINAPI
D3DXColorAdjustSaturation
(
D3DXCOLOR
*
pout
,
CONST
D3DXCOLOR
*
pc
,
FLOAT
s
);
FLOAT
WINAPI
D3DXFresnelTerm
(
FLOAT
costheta
,
FLOAT
refractionindex
);
D3DXMATRIX
*
WINAPI
D3DXMatrixAffineTransformation
(
D3DXMATRIX
*
pout
,
FLOAT
scaling
,
CONST
D3DXVECTOR3
*
rotationcenter
,
CONST
D3DXQUATERNION
*
rotation
,
CONST
D3DXVECTOR3
*
translation
);
D3DXMATRIX
*
WINAPI
D3DXMatrixAffineTransformation2D
(
D3DXMATRIX
*
pout
,
FLOAT
scaling
,
CONST
D3DXVECTOR2
*
protationcenter
,
FLOAT
rotation
,
CONST
D3DXVECTOR2
*
ptranslation
);
HRESULT
WINAPI
D3DXMatrixDecompose
(
D3DXVECTOR3
*
poutscale
,
D3DXQUATERNION
*
poutrotation
,
D3DXVECTOR3
*
pouttranslation
,
CONST
D3DXMATRIX
*
pm
);
...
...
@@ -358,6 +362,71 @@ D3DXVECTOR4* WINAPI D3DXVec4TransformArray(D3DXVECTOR4 *pout, UINT outstride, CO
}
#endif
typedef
interface
ID3DXMatrixStack
*
LPD3DXMATRIXSTACK
;
DEFINE_GUID
(
IID_ID3DXMatrixStack
,
0xc7885ba7
,
0xf990
,
0x4fe7
,
0x92
,
0x2d
,
0x85
,
0x15
,
0xe4
,
0x77
,
0xdd
,
0x85
);
#undef INTERFACE
#define INTERFACE ID3DXMatrixStack
DECLARE_INTERFACE_
(
ID3DXMatrixStack
,
IUnknown
)
{
STDMETHOD
(
QueryInterface
)(
THIS_
REFIID
riid
,
LPVOID
*
ppvObj
)
PURE
;
STDMETHOD_
(
ULONG
,
AddRef
)(
THIS
)
PURE
;
STDMETHOD_
(
ULONG
,
Release
)(
THIS
)
PURE
;
STDMETHOD
(
Pop
)(
THIS
)
PURE
;
STDMETHOD
(
Push
)(
THIS
)
PURE
;
STDMETHOD
(
LoadIdentity
)(
THIS
)
PURE
;
STDMETHOD
(
LoadMatrix
)(
THIS_
CONST
D3DXMATRIX
*
pM
)
PURE
;
STDMETHOD
(
MultMatrix
)(
THIS_
CONST
D3DXMATRIX
*
pM
)
PURE
;
STDMETHOD
(
MultMatrixLocal
)(
THIS_
CONST
D3DXMATRIX
*
pM
)
PURE
;
STDMETHOD
(
RotateAxis
)(
THIS_
CONST
D3DXVECTOR3
*
pV
,
FLOAT
Angle
)
PURE
;
STDMETHOD
(
RotateAxisLocal
)(
THIS_
CONST
D3DXVECTOR3
*
pV
,
FLOAT
Angle
)
PURE
;
STDMETHOD
(
RotateYawPitchRoll
)(
THIS_
FLOAT
Yaw
,
FLOAT
Pitch
,
FLOAT
Roll
)
PURE
;
STDMETHOD
(
RotateYawPitchRollLocal
)(
THIS_
FLOAT
Yaw
,
FLOAT
Pitch
,
FLOAT
Roll
)
PURE
;
STDMETHOD
(
Scale
)(
THIS_
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
PURE
;
STDMETHOD
(
ScaleLocal
)(
THIS_
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
PURE
;
STDMETHOD
(
Translate
)(
THIS_
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
PURE
;
STDMETHOD
(
TranslateLocal
)(
THIS_
FLOAT
x
,
FLOAT
y
,
FLOAT
z
)
PURE
;
STDMETHOD_
(
D3DXMATRIX
*
,
GetTop
)(
THIS
)
PURE
;
};
#undef INTERFACE
#if !defined(__cplusplus) || defined(CINTERFACE)
#define ID3DXMatrixStack_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define ID3DXMatrixStack_AddRef(p) (p)->lpVtbl->AddRef(p)
#define ID3DXMatrixStack_Release(p) (p)->lpVtbl->Release(p)
#define ID3DXMatrixStack_Pop(p) (p)->lpVtbl->Pop(p)
#define ID3DXMatrixStack_Push(p) (p)->lpVtbl->Push(p)
#define ID3DXMatrixStack_LoadIdentity(p) (p)->lpVtbl->LoadIdentity(p)
#define ID3DXMatrixStack_LoadMatrix(p,a) (p)->lpVtbl->LoadMatrix(p,a)
#define ID3DXMatrixStack_MultMatrix(p,a) (p)->lpVtbl->MultMatrix(p,a)
#define ID3DXMatrixStack_MultMatrixLocal(p,a) (p)->lpVtbl->MultMatrixLocal(p,a)
#define ID3DXMatrixStack_RotateAxis(p,a,b) (p)->lpVtbl->RotateAxis(p,a,b)
#define ID3DXMatrixStack_RotateAxisLocal(p,a,b) (p)->lpVtbl->RotateAxisLocal(p,a,b)
#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c) (p)->lpVtbl->RotateYawPitchRoll(p,a,b,c)
#define ID3DXMatrixStack_RotateYawPitchRollLocal(p,a,b,c) (p)->lpVtbl->RotateYawPitchRollLocal(p,a,b,c)
#define ID3DXMatrixStack_Scale(p,a,b,c) (p)->lpVtbl->Scale(p,a,b,c)
#define ID3DXMatrixStack_ScaleLocal(p,a,b,c) (p)->lpVtbl->ScaleLocal(p,a,b,c)
#define ID3DXMatrixStack_Translate(p,a,b,c) (p)->lpVtbl->Translate(p,a,b,c)
#define ID3DXMatrixStack_TranslateLocal(p,a,b,c) (p)->lpVtbl->TranslateLocal(p,a,b,c)
#define ID3DXMatrixStack_GetTop(p) (p)->lpVtbl->GetTop(p)
#endif
#ifdef __cplusplus
extern
"C"
{
#endif
HRESULT
WINAPI
D3DXCreateMatrixStack
(
DWORD
flags
,
LPD3DXMATRIXSTACK
*
ppstack
);
#ifdef __cplusplus
}
#endif
#include <d3dx9math.inl>
#endif
/* __D3DX9MATH_H__ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment