2 * Copyright 2007 David Adam
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(d3dx8
);
32 /*_________________D3DXQUATERNION________________*/
34 D3DXQUATERNION
* WINAPI
D3DXQuaternionNormalize(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
38 norm
= D3DXQuaternionLength(pq
);
48 pout
->x
= pq
->x
/ norm
;
49 pout
->y
= pq
->y
/ norm
;
50 pout
->z
= pq
->z
/ norm
;
51 pout
->w
= pq
->w
/ norm
;
55 /*_________________D3DXVec2_____________________*/
57 D3DXVECTOR2
* WINAPI
D3DXVec2BaryCentric(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pv3
, FLOAT f
, FLOAT g
)
59 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
60 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
64 D3DXVECTOR2
* WINAPI
D3DXVec2CatmullRom(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv0
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pv3
, FLOAT s
)
66 pout
->x
= 0.5f
* (2.0f
* pv1
->x
+ (pv2
->x
- pv0
->x
) *s
+ (2.0f
*pv0
->x
- 5.0f
* pv1
->x
+ 4.0f
* pv2
->x
- pv3
->x
) * s
* s
+ (pv3
->x
-3.0f
* pv2
->x
+ 3.0f
* pv1
->x
- pv0
->x
) * s
* s
* s
);
67 pout
->y
= 0.5f
* (2.0f
* pv1
->y
+ (pv2
->y
- pv0
->y
) *s
+ (2.0f
*pv0
->y
- 5.0f
* pv1
->y
+ 4.0f
* pv2
->y
- pv3
->y
) * s
* s
+ (pv3
->y
-3.0f
* pv2
->y
+ 3.0f
* pv1
->y
- pv0
->y
) * s
* s
* s
);
71 D3DXVECTOR2
* WINAPI
D3DXVec2Hermite(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pt1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pt2
, FLOAT s
)
75 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
76 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
77 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
78 h4
= s
* s
* s
- s
* s
;
80 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
81 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
85 D3DXVECTOR2
* WINAPI
D3DXVec2Normalize(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv
)
89 norm
= D3DXVec2Length(pv
);
97 pout
->x
= pv
->x
/ norm
;
98 pout
->y
= pv
->y
/ norm
;
103 /*_________________D3DXVec3_____________________*/
105 D3DXVECTOR3
* WINAPI
D3DXVec3BaryCentric(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
, FLOAT f
, FLOAT g
)
107 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
108 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
109 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
113 D3DXVECTOR3
* WINAPI
D3DXVec3CatmullRom( D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv0
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
, FLOAT s
)
115 pout
->x
= 0.5f
* (2.0f
* pv1
->x
+ (pv2
->x
- pv0
->x
) *s
+ (2.0f
*pv0
->x
- 5.0f
* pv1
->x
+ 4.0f
* pv2
->x
- pv3
->x
) * s
* s
+ (pv3
->x
-3.0f
* pv2
->x
+ 3.0f
* pv1
->x
- pv0
->x
) * s
* s
* s
);
116 pout
->y
= 0.5f
* (2.0f
* pv1
->y
+ (pv2
->y
- pv0
->y
) *s
+ (2.0f
*pv0
->y
- 5.0f
* pv1
->y
+ 4.0f
* pv2
->y
- pv3
->y
) * s
* s
+ (pv3
->y
-3.0f
* pv2
->y
+ 3.0f
* pv1
->y
- pv0
->y
) * s
* s
* s
);
117 pout
->z
= 0.5f
* (2.0f
* pv1
->z
+ (pv2
->z
- pv0
->z
) *s
+ (2.0f
*pv0
->z
- 5.0f
* pv1
->z
+ 4.0f
* pv2
->z
- pv3
->z
) * s
* s
+ (pv3
->z
-3.0f
* pv2
->z
+ 3.0f
* pv1
->z
- pv0
->z
) * s
* s
* s
);
121 D3DXVECTOR3
* WINAPI
D3DXVec3Hermite(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pt1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pt2
, FLOAT s
)
123 FLOAT h1
, h2
, h3
, h4
;
125 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
126 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
127 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
128 h4
= s
* s
* s
- s
* s
;
130 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
131 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
132 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
136 D3DXVECTOR3
* WINAPI
D3DXVec3Normalize(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
)
140 norm
= D3DXVec3Length(pv
);
149 pout
->x
= pv
->x
/ norm
;
150 pout
->y
= pv
->y
/ norm
;
151 pout
->z
= pv
->z
/ norm
;
156 /*_________________D3DXVec4_____________________*/
158 D3DXVECTOR4
* WINAPI
D3DXVec4BaryCentric(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
, FLOAT f
, FLOAT g
)
160 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
161 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
162 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
163 pout
->w
= (1.0f
-f
-g
) * (pv1
->w
) + f
* (pv2
->w
) + g
* (pv3
->w
);
167 D3DXVECTOR4
* WINAPI
D3DXVec4CatmullRom(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv0
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
, FLOAT s
)
169 pout
->x
= 0.5f
* (2.0f
* pv1
->x
+ (pv2
->x
- pv0
->x
) *s
+ (2.0f
*pv0
->x
- 5.0f
* pv1
->x
+ 4.0f
* pv2
->x
- pv3
->x
) * s
* s
+ (pv3
->x
-3.0f
* pv2
->x
+ 3.0f
* pv1
->x
- pv0
->x
) * s
* s
* s
);
170 pout
->y
= 0.5f
* (2.0f
* pv1
->y
+ (pv2
->y
- pv0
->y
) *s
+ (2.0f
*pv0
->y
- 5.0f
* pv1
->y
+ 4.0f
* pv2
->y
- pv3
->y
) * s
* s
+ (pv3
->y
-3.0f
* pv2
->y
+ 3.0f
* pv1
->y
- pv0
->y
) * s
* s
* s
);
171 pout
->z
= 0.5f
* (2.0f
* pv1
->z
+ (pv2
->z
- pv0
->z
) *s
+ (2.0f
*pv0
->z
- 5.0f
* pv1
->z
+ 4.0f
* pv2
->z
- pv3
->z
) * s
* s
+ (pv3
->z
-3.0f
* pv2
->z
+ 3.0f
* pv1
->z
- pv0
->z
) * s
* s
* s
);
172 pout
->w
= 0.5f
* (2.0f
* pv1
->w
+ (pv2
->w
- pv0
->w
) *s
+ (2.0f
*pv0
->w
- 5.0f
* pv1
->w
+ 4.0f
* pv2
->w
- pv3
->w
) * s
* s
+ (pv3
->w
-3.0f
* pv2
->w
+ 3.0f
* pv1
->w
- pv0
->w
) * s
* s
* s
);
176 D3DXVECTOR4
* WINAPI
D3DXVec4Hermite(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pt1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pt2
, FLOAT s
)
178 FLOAT h1
, h2
, h3
, h4
;
180 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
181 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
182 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
183 h4
= s
* s
* s
- s
* s
;
185 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
186 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
187 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
188 pout
->w
= h1
* (pv1
->w
) + h2
* (pt1
->w
) + h3
* (pv2
->w
) + h4
* (pt2
->w
);
192 D3DXVECTOR4
* WINAPI
D3DXVec4Normalize(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv
)
196 norm
= D3DXVec4Length(pv
);
206 pout
->x
= pv
->x
/ norm
;
207 pout
->y
= pv
->y
/ norm
;
208 pout
->z
= pv
->z
/ norm
;
209 pout
->w
= pv
->w
/ norm
;