1 /***********************************************************************\ 2 * d3dx10math.d * 3 * * 4 * Windows API header module * 5 * * 6 * Placed into public domain * 7 \***********************************************************************/ 8 module win32.directx.d3dx10math; 9 version(Windows): 10 11 version(Tango) { 12 import tango.math.Math; 13 alias sqrt sqrtf; 14 } else { 15 import std.c.math; 16 } 17 18 private import win32.windows; 19 private import win32.directx.d3dx10; 20 21 struct D3DVECTOR { 22 float x; 23 float y; 24 float z; 25 } 26 27 struct D3DMATRIX { 28 union { 29 struct { 30 float _11, _12, _13, _14; 31 float _21, _22, _23, _24; 32 float _31, _32, _33, _34; 33 float _41, _42, _43, _44; 34 } 35 float[4][4] m; 36 } 37 } 38 39 const D3DX_PI = 3.14159265358979323846; 40 const D3DX_1BYPI = 1.0 / D3DX_PI; 41 42 float D3DXToRadian(float degree) { 43 return degree * (D3DX_PI / 180.0); 44 } 45 46 float D3DXToDegree(float radian) { 47 return radian * (180.0 / D3DX_PI); 48 } 49 50 const D3DX_16F_DIG = 3; 51 const D3DX_16F_EPSILON = 4.8875809e-4f; 52 const D3DX_16F_MANT_DIG = 11; 53 const D3DX_16F_MAX = 6.550400e+004; 54 const D3DX_16F_MAX_10_EXP = 4; 55 const D3DX_16F_MAX_EXP = 15; 56 const D3DX_16F_MIN = 6.1035156e-5f; 57 const D3DX_16F_MIN_10_EXP = -4; 58 const D3DX_16F_MIN_EXP = -14; 59 const D3DX_16F_RADIX = 2; 60 const D3DX_16F_ROUNDS = 1; 61 const D3DX_16F_SIGN_MASK = 0x8000; 62 const D3DX_16F_EXP_MASK = 0x7C00; 63 const D3DX_16F_FRAC_MASK = 0x03FF; 64 65 struct D3DXFLOAT16 { 66 //TODO 67 protected: 68 WORD value; 69 } 70 71 struct D3DXVECTOR2 { 72 //TODO 73 float x, y; 74 } 75 76 struct D3DXVECTOR2_16F { 77 //TODO 78 D3DXFLOAT16 x, y; 79 } 80 81 struct D3DXVECTOR3 { 82 //TODO 83 float x, y, z; 84 } 85 86 struct D3DXVECTOR3_16F { 87 //TODO 88 D3DXFLOAT16 x, y, z; 89 } 90 91 struct D3DXVECTOR4 { 92 //TODO 93 float x, y, z, w; 94 } 95 96 struct D3DXVECTOR4_16F { 97 //TODO 98 D3DXFLOAT16 x, y, z, w; 99 } 100 101 struct D3DXMATRIX { 102 //TODO 103 union { 104 struct { 105 float _11, _12, _13, _14; 106 float _21, _22, _23, _24; 107 float _31, _32, _33, _34; 108 float _41, _42, _43, _44; 109 } 110 float[4][4] m; 111 } 112 } 113 114 //TODO struct _D3DXMATRIXA16 : D3DXMATRIX 115 116 struct D3DXQUATERNION { 117 //TODO 118 float x, y, z, w; 119 } 120 121 struct D3DXPLANE { 122 //TODO 123 float a, b, c, d; 124 } 125 126 struct D3DXCOLOR { 127 //TODO 128 float r, g, b, a; 129 } 130 131 extern(Windows) { 132 D3DXFLOAT16* D3DXFloat32To16Array(D3DXFLOAT16* pOut, float* pIn, UINT n); 133 float* D3DXFloat16To32Array(float* pOut, D3DXFLOAT16* pIn, UINT n); 134 } 135 136 float D3DXVec2Length(D3DXVECTOR2* pV) { 137 debug(D3DX10_DEBUG) { 138 if (pV is null) return 0.0; 139 } 140 return sqrtf((pV.x * pV.x) + (pV.y * pV.y)); 141 } 142 143 float D3DXVec2LengthSq(D3DXVECTOR2* pV) { 144 debug(D3DX10_DEBUG) { 145 if (pV is null) return 0.0; 146 } 147 return (pV.x * pV.x) + (pV.y * pV.y); 148 } 149 150 float D3DXVec2Dot(D3DXVECTOR2* pV1, D3DXVECTOR2* pV2) { 151 debug(D3DX10_DEBUG) { 152 if ((pV1 is null) || (pV2 is null)) return 0.0; 153 } 154 return (pV1.x * pV2.x) + (pV1.y * pV2.y); 155 } 156 157 float D3DXVec2CCW(D3DXVECTOR2* pV1, D3DXVECTOR2* pV2) { 158 debug(D3DX10_DEBUG) { 159 if ((pV1 is null) || (pV2 is null)) return 0.0; 160 } 161 return (pV1.x * pV2.y) + (pV1.y * pV2.x); 162 } 163 164 D3DXVECTOR2* D3DXVec2Add(D3DXVECTOR2* pOut, D3DXVECTOR2* pV1, D3DXVECTOR2* pV2) { 165 debug(D3DX10_DEBUG) { 166 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 167 } 168 pOut.x = pV1.x + pV2.x; 169 pOut.y = pV1.y + pV2.y; 170 return pOut; 171 } 172 173 D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2* pOut, D3DXVECTOR2* pV1, D3DXVECTOR2* pV2) { 174 debug(D3DX10_DEBUG) { 175 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 176 } 177 pOut.x = pV1.x - pV2.x; 178 pOut.y = pV1.y - pV2.y; 179 return pOut; 180 } 181 182 D3DXVECTOR2* D3DXVec2Minimize(D3DXVECTOR2* pOut, D3DXVECTOR2* pV1, D3DXVECTOR2* pV2) { 183 debug(D3DX10_DEBUG) { 184 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 185 } 186 pOut.x = pV1.x < pV2.x ? pV1.x : pV2.x; 187 pOut.y = pV1.y < pV2.y ? pV1.y : pV2.y; 188 return pOut; 189 } 190 191 D3DXVECTOR2* D3DXVec2Maximize(D3DXVECTOR2* pOut, D3DXVECTOR2* pV1, D3DXVECTOR2* pV2) { 192 debug(D3DX10_DEBUG) { 193 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 194 } 195 pOut.x = pV1.x > pV2.x ? pV1.x : pV2.x; 196 pOut.y = pV1.y > pV2.y ? pV1.y : pV2.y; 197 return pOut; 198 } 199 200 D3DXVECTOR2* D3DXVec2Scale(D3DXVECTOR2* pOut, D3DXVECTOR2* pV, float s) { 201 debug(D3DX10_DEBUG) { 202 if ((pOut is null) || (pV is null)) return null; 203 } 204 pOut.x = pV.x * s; 205 pOut.y = pV.y * s; 206 return pOut; 207 } 208 209 D3DXVECTOR2* D3DXVec2Lerp(D3DXVECTOR2* pOut, D3DXVECTOR2* pV1, D3DXVECTOR2* pV2, float s) { 210 debug(D3DX10_DEBUG) { 211 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 212 } 213 pOut.x = pV1.x + s * (pV2.x - pV1.x); 214 pOut.y = pV1.y + s * (pV2.y - pV1.y); 215 return pOut; 216 } 217 218 extern(Windows) { 219 D3DXVECTOR2* D3DXVec2Normalize(D3DXVECTOR2* pOut, D3DXVECTOR2* pV); 220 D3DXVECTOR2* D3DXVec2Hermite(D3DXVECTOR2* pOut, D3DXVECTOR2* pV1, D3DXVECTOR2* pT1, D3DXVECTOR2* pV2, D3DXVECTOR2* pT2, float s); 221 D3DXVECTOR2* D3DXVec2CatmullRom(D3DXVECTOR2* pOut, D3DXVECTOR2* pV0, D3DXVECTOR2* pV1, D3DXVECTOR2* pV2, D3DXVECTOR2* pV3, float s); 222 D3DXVECTOR2* D3DXVec2BaryCentric(D3DXVECTOR2* pOut, D3DXVECTOR2* pV1, D3DXVECTOR2* pV2, D3DXVECTOR2* pV3, float f, float g); 223 D3DXVECTOR4* D3DXVec2Transform(D3DXVECTOR4* pOut, D3DXVECTOR2* pV, D3DXMATRIX* pM); 224 D3DXVECTOR2* D3DXVec2TransformCoord(D3DXVECTOR2* pOut, D3DXVECTOR2* pV, D3DXMATRIX* pM); 225 D3DXVECTOR2* D3DXVec2TransformNormal(D3DXVECTOR2* pOut, D3DXVECTOR2* pV, D3DXMATRIX* pM); 226 D3DXVECTOR4* D3DXVec2TransformArray(D3DXVECTOR4* pOut, UINT OutStride, D3DXVECTOR2* pV, UINT VStride, D3DXMATRIX* pM, UINT n); 227 D3DXVECTOR2* D3DXVec2TransformCoordArray(D3DXVECTOR2* pOut, UINT OutStride, D3DXVECTOR2* pV, UINT VStride, D3DXMATRIX* pM, UINT n); 228 D3DXVECTOR2* D3DXVec2TransformNormalArray(D3DXVECTOR2* pOut, UINT OutStride, D3DXVECTOR2* pV, UINT VStride, D3DXMATRIX* pM, UINT n); 229 } 230 231 float D3DXVec3Length(D3DXVECTOR3* pV) { 232 debug(D3DX10_DEBUG) { 233 if (pV is null) return 0.0; 234 } 235 return sqrtf((pV.x * pV.x) + (pV.y * pV.y) + (pV.z * pV.z)); 236 } 237 238 float D3DXVec3LengthSq(D3DXVECTOR3* pV) { 239 debug(D3DX10_DEBUG) { 240 if (pV is null) return 0.0; 241 } 242 return (pV.x * pV.x) + (pV.y * pV.y) + (pV.z * pV.z); 243 } 244 245 float D3DXVec3Dot(D3DXVECTOR3* pV1, D3DXVECTOR3* pV2) { 246 debug(D3DX10_DEBUG) { 247 if ((pV1 is null) || (pV2 is null)) return 0.0; 248 } 249 return (pV1.x * pV2.x) + (pV1.y * pV2.y) + (pV1.z * pV2.z); 250 } 251 252 D3DXVECTOR3* D3DXVec3Cross(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2) { 253 debug(D3DX10_DEBUG) { 254 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return 0.0; 255 } 256 D3DXVECTOR3 v; 257 v.x = (pV1.y * pV2.z) - (pV1.z * pV2.y); 258 v.y = (pV1.z * pV2.x) - (pV1.x * pV2.z); 259 v.z = (pV1.x * pV2.y) - (pV1.y * pV2.x); 260 *pOut = v; 261 return pOut; 262 } 263 264 D3DXVECTOR3* D3DXVec3Add(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2) { 265 debug(D3DX10_DEBUG) { 266 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 267 } 268 pOut.x = pV1.x + pV2.x; 269 pOut.y = pV1.y + pV2.y; 270 pOut.z = pV1.z + pV2.z; 271 return pOut; 272 } 273 274 D3DXVECTOR3* D3DXVec3Subtract(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2) { 275 debug(D3DX10_DEBUG) { 276 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 277 } 278 pOut.x = pV1.x - pV2.x; 279 pOut.y = pV1.y - pV2.y; 280 pOut.z = pV1.z - pV2.z; 281 return pOut; 282 } 283 284 D3DXVECTOR3* D3DXVec3Minimize(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2) { 285 debug(D3DX10_DEBUG) { 286 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 287 } 288 pOut.x = pV1.x < pV2.x ? pV1.x : pV2.x; 289 pOut.y = pV1.y < pV2.y ? pV1.y : pV2.y; 290 pOut.z = pV1.z < pV2.z ? pV1.z : pV2.z; 291 return pOut; 292 } 293 294 D3DXVECTOR3* D3DXVec3Maximize(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2) { 295 debug(D3DX10_DEBUG) { 296 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 297 } 298 pOut.x = pV1.x > pV2.x ? pV1.x : pV2.x; 299 pOut.y = pV1.y > pV2.y ? pV1.y : pV2.y; 300 pOut.z = pV1.z > pV2.z ? pV1.z : pV2.z; 301 return pOut; 302 } 303 304 D3DXVECTOR3* D3DXVec3Scale(D3DXVECTOR3* pOut, D3DXVECTOR3* pV, float s) { 305 debug(D3DX10_DEBUG) { 306 if ((pOut is null) || (pV is null)) return null; 307 } 308 pOut.x = pV.x * s; 309 pOut.y = pV.y * s; 310 pOut.z = pV.z * s; 311 return pOut; 312 } 313 314 D3DXVECTOR3* D3DXVec3Lerp(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2, float s) { 315 debug(D3DX10_DEBUG) { 316 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 317 } 318 pOut.x = pV1.x + s * (pV2.x - pV1.x); 319 pOut.y = pV1.y + s * (pV2.y - pV1.y); 320 pOut.z = pV1.z + s * (pV2.z - pV1.z); 321 return pOut; 322 } 323 324 extern(Windows) { 325 D3DXVECTOR3* D3DXVec3Normalize(D3DXVECTOR3* pOut, D3DXVECTOR3* pV); 326 D3DXVECTOR3* D3DXVec3Hermite(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pT1, D3DXVECTOR3* pV2, D3DXVECTOR3* pT2, FLOAT s); 327 D3DXVECTOR3* D3DXVec3CatmullRom(D3DXVECTOR3* pOut, D3DXVECTOR3* pV0, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2, D3DXVECTOR3* pV3, FLOAT s); 328 D3DXVECTOR3* D3DXVec3BaryCentric(D3DXVECTOR3* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2, D3DXVECTOR3* pV3, FLOAT f, FLOAT g); 329 D3DXVECTOR4* D3DXVec3Transform(D3DXVECTOR4* pOut, D3DXVECTOR3* pV, D3DXMATRIX* pM); 330 D3DXVECTOR3* D3DXVec3TransformCoord(D3DXVECTOR3* pOut, D3DXVECTOR3* pV, D3DXMATRIX* pM); 331 D3DXVECTOR3* D3DXVec3TransformNormal(D3DXVECTOR3* pOut, D3DXVECTOR3* pV, D3DXMATRIX* pM); 332 D3DXVECTOR4* D3DXVec3TransformArray(D3DXVECTOR4* pOut, UINT OutStride, D3DXVECTOR3* pV, UINT VStride, D3DXMATRIX* pM, UINT n); 333 D3DXVECTOR3* D3DXVec3TransformCoordArray(D3DXVECTOR3* pOut, UINT OutStride, D3DXVECTOR3* pV, UINT VStride, D3DXMATRIX* pM, UINT n); 334 D3DXVECTOR3* D3DXVec3TransformNormalArray(D3DXVECTOR3* pOut, UINT OutStride, D3DXVECTOR3* pV, UINT VStride, D3DXMATRIX* pM, UINT n); 335 D3DXVECTOR3* D3DXVec3Project(D3DXVECTOR3* pOut, D3DXVECTOR3* pV, D3D10_VIEWPORT* pViewport, D3DXMATRIX* pProjection, D3DXMATRIX* pView, D3DXMATRIX* pWorld); 336 D3DXVECTOR3* D3DXVec3Unproject(D3DXVECTOR3* pOut, D3DXVECTOR3* pV, D3D10_VIEWPORT* pViewport, D3DXMATRIX* pProjection, D3DXMATRIX* pView, D3DXMATRIX* pWorld); 337 D3DXVECTOR3* D3DXVec3ProjectArray(D3DXVECTOR3* pOut, UINT OutStride,D3DXVECTOR3* pV, UINT VStride,D3D10_VIEWPORT* pViewport, D3DXMATRIX* pProjection, D3DXMATRIX* pView, D3DXMATRIX* pWorld, UINT n); 338 D3DXVECTOR3* D3DXVec3UnprojectArray(D3DXVECTOR3* pOut, UINT OutStride, D3DXVECTOR3* pV, UINT VStride, D3D10_VIEWPORT* pViewport, D3DXMATRIX* pProjection, D3DXMATRIX* pView, D3DXMATRIX* pWorld, UINT n); 339 } 340 341 float D3DXVec4Length(D3DXVECTOR4* pV) { 342 debug(D3DX10_DEBUG) { 343 if (pV is null) return 0.0; 344 } 345 return sqrtf((pV.x * pV.x) + (pV.y * pV.y) + (pV.z * pV.z) + (pV.w * pV.w)); 346 } 347 348 float D3DXVec4LengthSq(D3DXVECTOR4* pV) { 349 debug(D3DX10_DEBUG) { 350 if (pV is null) return 0.0; 351 } 352 return (pV.x * pV.x) + (pV.y * pV.y) + (pV.z * pV.z) + (pV.w * pV.w); 353 } 354 355 float D3DXVec4Dot(D3DXVECTOR4* pV1, D3DXVECTOR4* pV2) { 356 debug(D3DX10_DEBUG) { 357 if ((pV1 is null) || (pV2 is null)) return 0.0; 358 } 359 return (pV1.x * pV2.x) + (pV1.y * pV2.y) + (pV1.z * pV2.z) + (pV1.w * pV2.w); 360 } 361 362 D3DXVECTOR4* D3DXVec4Add(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2) { 363 debug(D3DX10_DEBUG) { 364 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 365 } 366 pOut.x = pV1.x + pV2.x; 367 pOut.y = pV1.y + pV2.y; 368 pOut.z = pV1.z + pV2.z; 369 pOut.w = pV1.w + pV2.w; 370 return pOut; 371 } 372 373 D3DXVECTOR4* D3DXVec4Subtract(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2) { 374 debug(D3DX10_DEBUG) { 375 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 376 } 377 pOut.x = pV1.x - pV2.x; 378 pOut.y = pV1.y - pV2.y; 379 pOut.z = pV1.z - pV2.z; 380 pOut.w = pV1.w - pV2.w; 381 return pOut; 382 } 383 384 D3DXVECTOR4* D3DXVec4Minimize(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2) { 385 debug(D3DX10_DEBUG) { 386 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 387 } 388 pOut.x = pV1.x < pV2.x ? pV1.x : pV2.x; 389 pOut.y = pV1.y < pV2.y ? pV1.y : pV2.y; 390 pOut.z = pV1.z < pV2.z ? pV1.z : pV2.z; 391 pOut.w = pV1.w < pV2.w ? pV1.w : pV2.w; 392 return pOut; 393 } 394 395 D3DXVECTOR4* D3DXVec4Maximize(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2) { 396 debug(D3DX10_DEBUG) { 397 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 398 } 399 pOut.x = pV1.x > pV2.x ? pV1.x : pV2.x; 400 pOut.y = pV1.y > pV2.y ? pV1.y : pV2.y; 401 pOut.z = pV1.z > pV2.z ? pV1.z : pV2.z; 402 pOut.w = pV1.w > pV2.w ? pV1.w : pV2.w; 403 return pOut; 404 } 405 406 D3DXVECTOR4* D3DXVec4Scale(D3DXVECTOR4* pOut, D3DXVECTOR4* pV, float s) { 407 debug(D3DX10_DEBUG) { 408 if ((pOut is null) || (pV is null)) return null; 409 } 410 pOut.x = pV.x * s; 411 pOut.y = pV.y * s; 412 pOut.z = pV.z * s; 413 pOut.w = pV.w * s; 414 return pOut; 415 } 416 417 D3DXVECTOR4* D3DXVec4Lerp(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2, float s) { 418 debug(D3DX10_DEBUG) { 419 if ((pOut is null) || (pV1 is null) || (pV2 is null)) return null; 420 } 421 pOut.x = pV1.x + s * (pV2.x - pV1.x); 422 pOut.y = pV1.y + s * (pV2.y - pV1.y); 423 pOut.z = pV1.z + s * (pV2.z - pV1.z); 424 pOut.w = pV1.w + s * (pV2.w - pV1.w); 425 return pOut; 426 } 427 428 extern(Windows) { 429 D3DXVECTOR4* D3DXVec4Cross(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2, D3DXVECTOR4* pV3); 430 D3DXVECTOR4* D3DXVec4Normalize(D3DXVECTOR4* pOut, D3DXVECTOR4* pV); 431 D3DXVECTOR4* D3DXVec4Hermite(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pT1, D3DXVECTOR4* pV2, D3DXVECTOR4* pT2, FLOAT s); 432 D3DXVECTOR4* D3DXVec4CatmullRom(D3DXVECTOR4* pOut, D3DXVECTOR4* pV0, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2, D3DXVECTOR4* pV3, FLOAT s); 433 D3DXVECTOR4* D3DXVec4BaryCentric(D3DXVECTOR4* pOut, D3DXVECTOR4* pV1, D3DXVECTOR4* pV2, D3DXVECTOR4* pV3, FLOAT f, FLOAT g); 434 D3DXVECTOR4* D3DXVec4Transform(D3DXVECTOR4* pOut, D3DXVECTOR4* pV, D3DXMATRIX* pM); 435 D3DXVECTOR4* D3DXVec4TransformArray(D3DXVECTOR4* pOut, UINT OutStride, D3DXVECTOR4* pV, UINT VStride, D3DXMATRIX* pM, UINT n); 436 } 437 438 D3DXMATRIX* D3DXMatrixIdentity(D3DXMATRIX *pOut) { 439 debug(D3DX10_DEBUG) { 440 if (pOut is null) return NULL; 441 } 442 pOut.m[0][1] = pOut.m[0][2] = pOut.m[0][3] = 443 pOut.m[1][0] = pOut.m[1][2] = pOut.m[1][3] = 444 pOut.m[2][0] = pOut.m[2][1] = pOut.m[2][3] = 445 pOut.m[3][0] = pOut.m[3][1] = pOut.m[3][2] = 0.0; 446 pOut.m[0][0] = pOut.m[1][1] = pOut.m[2][2] = pOut.m[3][3] = 1.0; 447 return pOut; 448 } 449 450 451 BOOL D3DXMatrixIsIdentity(D3DXMATRIX *pM) { 452 debug(D3DX10_DEBUG) { 453 if(pM is null) return FALSE; 454 } 455 return (pM.m[0][0] == 1.0f) && (pM.m[0][1] == 0.0f) && (pM.m[0][2] == 0.0f) && (pM.m[0][3] == 0.0f) && 456 (pM.m[1][0] == 0.0f) && (pM.m[1][1] == 1.0f) && (pM.m[1][2] == 0.0f) && (pM.m[1][3] == 0.0f) && 457 (pM.m[2][0] == 0.0f) && (pM.m[2][1] == 0.0f) && (pM.m[2][2] == 1.0f) && (pM.m[2][3] == 0.0f) && 458 (pM.m[3][0] == 0.0f) && (pM.m[3][1] == 0.0f) && (pM.m[3][2] == 0.0f) && (pM.m[3][3] == 1.0f); 459 } 460 461 extern(Windows) { 462 FLOAT D3DXMatrixDeterminant(D3DXMATRIX* pM); 463 HRESULT D3DXMatrixDecompose(D3DXVECTOR3* pOutScale, D3DXQUATERNION* pOutRotation, D3DXVECTOR3* pOutTranslation, D3DXMATRIX* pM); 464 D3DXMATRIX* D3DXMatrixTranspose(D3DXMATRIX* pOut, D3DXMATRIX* pM); 465 D3DXMATRIX* D3DXMatrixMultiply(D3DXMATRIX* pOut, D3DXMATRIX* pM1, D3DXMATRIX* pM2); 466 D3DXMATRIX* D3DXMatrixMultiplyTranspose(D3DXMATRIX* pOut, D3DXMATRIX* pM1, D3DXMATRIX* pM2); 467 D3DXMATRIX* D3DXMatrixInverse(D3DXMATRIX* pOut, FLOAT* pDeterminant, D3DXMATRIX* pM); 468 D3DXMATRIX* D3DXMatrixScaling(D3DXMATRIX* pOut, FLOAT sx, FLOAT sy, FLOAT sz); 469 D3DXMATRIX* D3DXMatrixTranslation(D3DXMATRIX* pOut, FLOAT x, FLOAT y, FLOAT z); 470 D3DXMATRIX* D3DXMatrixRotationX(D3DXMATRIX* pOut, FLOAT Angle); 471 D3DXMATRIX* D3DXMatrixRotationY(D3DXMATRIX* pOut, FLOAT Angle); 472 D3DXMATRIX* D3DXMatrixRotationZ(D3DXMATRIX* pOut, FLOAT Angle); 473 D3DXMATRIX* D3DXMatrixRotationAxis(D3DXMATRIX* pOut, D3DXVECTOR3* pV, FLOAT Angle); 474 D3DXMATRIX* D3DXMatrixRotationQuaternion(D3DXMATRIX* pOut, D3DXQUATERNION* pQ); 475 D3DXMATRIX* D3DXMatrixRotationYawPitchRoll(D3DXMATRIX* pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll); 476 D3DXMATRIX* D3DXMatrixTransformation(D3DXMATRIX* pOut, D3DXVECTOR3* pScalingCenter, D3DXQUATERNION* pScalingRotation, D3DXVECTOR3* pScaling, D3DXVECTOR3* pRotationCenter, D3DXQUATERNION* pRotation, D3DXVECTOR3* pTranslation); 477 D3DXMATRIX* D3DXMatrixTransformation2D(D3DXMATRIX* pOut, D3DXVECTOR2* pScalingCenter, FLOAT ScalingRotation, D3DXVECTOR2* pScaling, D3DXVECTOR2* pRotationCenter, FLOAT Rotation, D3DXVECTOR2* pTranslation); 478 D3DXMATRIX* D3DXMatrixAffineTransformation(D3DXMATRIX* pOut, FLOAT Scaling, D3DXVECTOR3* pRotationCenter, D3DXQUATERNION* pRotation, D3DXVECTOR3* pTranslation); 479 D3DXMATRIX* D3DXMatrixAffineTransformation2D(D3DXMATRIX* pOut, FLOAT Scaling, D3DXVECTOR2* pRotationCenter, FLOAT Rotation, D3DXVECTOR2* pTranslation); 480 D3DXMATRIX* D3DXMatrixLookAtRH(D3DXMATRIX* pOut, D3DXVECTOR3* pEye, D3DXVECTOR3* pAt, D3DXVECTOR3* pUp); 481 D3DXMATRIX* D3DXMatrixLookAtLH(D3DXMATRIX* pOut, D3DXVECTOR3* pEye, D3DXVECTOR3* pAt, D3DXVECTOR3* pUp); 482 D3DXMATRIX* D3DXMatrixPerspectiveRH(D3DXMATRIX* pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf); 483 D3DXMATRIX* D3DXMatrixPerspectiveLH(D3DXMATRIX* pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf); 484 D3DXMATRIX* D3DXMatrixPerspectiveFovRH(D3DXMATRIX* pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf); 485 D3DXMATRIX* D3DXMatrixPerspectiveFovLH(D3DXMATRIX* pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf); 486 D3DXMATRIX* D3DXMatrixPerspectiveOffCenterRH(D3DXMATRIX* pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf); 487 D3DXMATRIX* D3DXMatrixPerspectiveOffCenterLH(D3DXMATRIX* pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf); 488 D3DXMATRIX* D3DXMatrixOrthoRH(D3DXMATRIX* pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf); 489 D3DXMATRIX* D3DXMatrixOrthoLH(D3DXMATRIX* pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf); 490 D3DXMATRIX* D3DXMatrixOrthoOffCenterRH(D3DXMATRIX* pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf); 491 D3DXMATRIX* D3DXMatrixOrthoOffCenterLH(D3DXMATRIX* pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf); 492 D3DXMATRIX* D3DXMatrixShadow(D3DXMATRIX* pOut, D3DXVECTOR4* pLight, D3DXPLANE* pPlane); 493 D3DXMATRIX* D3DXMatrixReflect(D3DXMATRIX* pOut, D3DXPLANE* pPlane); 494 } 495 496 float D3DXQuaternionLength(D3DXQUATERNION *pQ) { 497 debug(D3DX10_DEBUG) { 498 if (pQ is null) return 0.0f; 499 } 500 return sqrtf((pQ.x * pQ.x) + (pQ.y * pQ.y) + (pQ.z * pQ.z) + (pQ.w * pQ.w)); 501 } 502 503 float D3DXQuaternionLengthSq(D3DXQUATERNION *pQ) { 504 debug(D3DX10_DEBUG) { 505 if(pQ is null) return 0.0f; 506 } 507 return (pQ.x * pQ.x) + (pQ.y * pQ.y) + (pQ.z * pQ.z) + (pQ.w * pQ.w); 508 } 509 510 float D3DXQuaternionDot(D3DXQUATERNION *pQ1, D3DXQUATERNION *pQ2) { 511 debug(D3DX10_DEBUG) { 512 if((pQ1 is null) || (pQ2 is null)) return 0.0f; 513 } 514 return (pQ1.x * pQ2.x) + (pQ1.y * pQ2.y) + (pQ1.z * pQ2.z) + (pQ1.w * pQ2.w); 515 } 516 517 D3DXQUATERNION* D3DXQuaternionIdentity(D3DXQUATERNION *pOut) { 518 debug(D3DX10_DEBUG) { 519 if(pOut is null) return null; 520 } 521 pOut.x = pOut.y = pOut.z = 0.0f; 522 pOut.w = 1.0f; 523 return pOut; 524 } 525 526 bool D3DXQuaternionIsIdentity(D3DXQUATERNION *pQ) { 527 debug(D3DX10_DEBUG) { 528 if(pQ is null) return false; 529 } 530 return (pQ.x == 0.0f) && (pQ.y == 0.0f) && (pQ.z == 0.0f) && (pQ.w == 1.0f); 531 } 532 533 D3DXQUATERNION* D3DXQuaternionConjugate(D3DXQUATERNION *pOut, D3DXQUATERNION *pQ) { 534 debug(D3DX10_DEBUG) { 535 if((pOut is null) || (pQis is null)) return null; 536 } 537 pOut.x = -pQ.x; 538 pOut.y = -pQ.y; 539 pOut.z = -pQ.z; 540 pOut.w = pQ.w; 541 return pOut; 542 } 543 544 extern(Windows) { 545 void D3DXQuaternionToAxisAngle(D3DXQUATERNION* pQ, D3DXVECTOR3* pAxis, FLOAT* pAngle); 546 D3DXQUATERNION* D3DXQuaternionRotationMatrix(D3DXQUATERNION* pOut, D3DXMATRIX* pM); 547 D3DXQUATERNION* D3DXQuaternionRotationAxis(D3DXQUATERNION* pOut, D3DXVECTOR3* pV, FLOAT Angle); 548 D3DXQUATERNION* D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION* pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll); 549 D3DXQUATERNION* D3DXQuaternionMultiply(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ1, D3DXQUATERNION* pQ2); 550 D3DXQUATERNION* D3DXQuaternionNormalize(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ); 551 D3DXQUATERNION* D3DXQuaternionInverse(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ); 552 D3DXQUATERNION* D3DXQuaternionLn(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ); 553 D3DXQUATERNION* D3DXQuaternionExp(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ); 554 D3DXQUATERNION* D3DXQuaternionSlerp(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ1, D3DXQUATERNION* pQ2, FLOAT t); 555 D3DXQUATERNION* D3DXQuaternionSquad(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ1, D3DXQUATERNION* pA, D3DXQUATERNION* pB, D3DXQUATERNION* pC, FLOAT t); 556 void D3DXQuaternionSquadSetup(D3DXQUATERNION* pAOut, D3DXQUATERNION* pBOut, D3DXQUATERNION* pCOut, D3DXQUATERNION* pQ0, D3DXQUATERNION* pQ1, D3DXQUATERNION* pQ2, D3DXQUATERNION* pQ3); 557 D3DXQUATERNION* D3DXQuaternionBaryCentric(D3DXQUATERNION* pOut, D3DXQUATERNION* pQ1, D3DXQUATERNION* pQ2, D3DXQUATERNION* pQ3, FLOAT f, FLOAT g); 558 } 559 560 float D3DXPlaneDot(D3DXPLANE *pP, D3DXVECTOR4 *pV) { 561 debug(D3DX10_DEBUG) { 562 if((pP is null) || (pV is null)) return 0.0f; 563 } 564 return (pP.a * pV.x) + (pP.b * pV.y) + (pP.c * pV.z) + (pP.d * pV.w); 565 } 566 567 float D3DXPlaneDotCoord(D3DXPLANE *pP, D3DXVECTOR3 *pV) { 568 debug(D3DX10_DEBUG) { 569 if((pP is null) || (pV is null)) return 0.0f; 570 } 571 return (pP.a * pV.x) + (pP.b * pV.y) + (pP.c * pV.z) + pP.d; 572 } 573 574 float D3DXPlaneDotNormal(D3DXPLANE *pP, D3DXVECTOR3 *pV) { 575 debug(D3DX10_DEBUG) { 576 if((pP is null) || (pV is null)) return 0.0f; 577 } 578 return (pP.a * pV.x) + (pP.b * pV.y) + (pP.c * pV.z); 579 } 580 581 D3DXPLANE* D3DXPlaneScale(D3DXPLANE *pOut, D3DXPLANE *pP, float s) { 582 debug(D3DX10_DEBUG) { 583 if((pOut is null) || (pP is null)) return null; 584 } 585 pOut.a = pP.a * s; 586 pOut.b = pP.b * s; 587 pOut.c = pP.c * s; 588 pOut.d = pP.d * s; 589 return pOut; 590 } 591 592 extern(Windows) { 593 D3DXPLANE* D3DXPlaneNormalize(D3DXPLANE* pOut, D3DXPLANE* pP); 594 D3DXVECTOR3* D3DXPlaneIntersectLine(D3DXVECTOR3* pOut, D3DXPLANE* pP, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2); 595 D3DXPLANE* D3DXPlaneFromPointNormal(D3DXPLANE* pOut, D3DXVECTOR3* pPoint, D3DXVECTOR3* pNormal); 596 D3DXPLANE* D3DXPlaneFromPoints(D3DXPLANE* pOut, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2, D3DXVECTOR3* pV3); 597 D3DXPLANE* D3DXPlaneTransform(D3DXPLANE* pOut, D3DXPLANE* pP, D3DXMATRIX* pM); 598 D3DXPLANE* D3DXPlaneTransformArray(D3DXPLANE* pOut, UINT OutStride, D3DXPLANE* pP, UINT PStride, D3DXMATRIX* pM, UINT n); 599 } 600 601 D3DXCOLOR* D3DXColorNegative(D3DXCOLOR* pOut, D3DXCOLOR* pC) { 602 debug(D3DX10_DEBUG) { 603 if((pOut is null) || (pC is null)) return null; 604 } 605 pOut.r = 1.0f - pC.r; 606 pOut.g = 1.0f - pC.g; 607 pOut.b = 1.0f - pC.b; 608 pOut.a = pC.a; 609 return pOut; 610 } 611 612 D3DXCOLOR* D3DXColorAdd(D3DXCOLOR* pOut, D3DXCOLOR* pC1, D3DXCOLOR* pC2) { 613 debug(D3DX10_DEBUG) { 614 if((pOut is null) || (pC1 is null) || (pC2 is null)) return null; 615 } 616 pOut.r = pC1.r + pC2.r; 617 pOut.g = pC1.g + pC2.g; 618 pOut.b = pC1.b + pC2.b; 619 pOut.a = pC1.a + pC2.a; 620 return pOut; 621 } 622 623 D3DXCOLOR* D3DXColorSubtract(D3DXCOLOR* pOut, D3DXCOLOR* pC1, D3DXCOLOR* pC2) { 624 debug(D3DX10_DEBUG) { 625 if((pOut is null) || (pC1 is null) || (pC2 is null)) return null; 626 } 627 pOut.r = pC1.r - pC2.r; 628 pOut.g = pC1.g - pC2.g; 629 pOut.b = pC1.b - pC2.b; 630 pOut.a = pC1.a - pC2.a; 631 return pOut; 632 } 633 634 D3DXCOLOR* D3DXColorScale(D3DXCOLOR* pOut, D3DXCOLOR* pC, float s) { 635 debug(D3DX10_DEBUG) { 636 if((pOut is null) || (pC is null)) return null; 637 } 638 pOut.r = pC.r * s; 639 pOut.g = pC.g * s; 640 pOut.b = pC.b * s; 641 pOut.a = pC.a * s; 642 return pOut; 643 } 644 645 D3DXCOLOR* D3DXColorModulate(D3DXCOLOR* pOut, D3DXCOLOR* pC1, D3DXCOLOR* pC2) { 646 debug(D3DX10_DEBUG) { 647 if((pOut is null) || (pC1 is null) || (pC2 is null)) return null; 648 } 649 pOut.r = pC1.r * pC2.r; 650 pOut.g = pC1.g * pC2.g; 651 pOut.b = pC1.b * pC2.b; 652 pOut.a = pC1.a * pC2.a; 653 return pOut; 654 } 655 656 D3DXCOLOR* D3DXColorLerp(D3DXCOLOR* pOut, D3DXCOLOR* pC1, D3DXCOLOR* pC2, float s) { 657 debug(D3DX10_DEBUG) { 658 if((pOut is null) || (pC1 is null) || (pC2 is null)) return null; 659 } 660 pOut.r = pC1.r + s * (pC2.r - pC1.r); 661 pOut.g = pC1.g + s * (pC2.g - pC1.g); 662 pOut.b = pC1.b + s * (pC2.b - pC1.b); 663 pOut.a = pC1.a + s * (pC2.a - pC1.a); 664 return pOut; 665 } 666 667 extern(Windows) { 668 D3DXCOLOR* D3DXColorAdjustSaturation(D3DXCOLOR* pOut, D3DXCOLOR* pC, float s); 669 D3DXCOLOR* D3DXColorAdjustContrast(D3DXCOLOR* pOut, D3DXCOLOR* pC, float c); 670 FLOAT D3DXFresnelTerm(float CosTheta, float RefractionIndex); 671 } 672 673 extern (C) const GUID IID_ID3DXMatrixStack = {0xc7885ba7, 0xf990, 0x4fe7, [0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85]}; 674 675 interface ID3DXMatrixStack : IUnknown { 676 extern(Windows) : 677 HRESULT Pop(); 678 HRESULT Push(); 679 HRESULT LoadIdentity(); 680 HRESULT LoadMatrix(D3DXMATRIX* pM ); 681 HRESULT MultMatrix(D3DXMATRIX* pM ); 682 HRESULT MultMatrixLocal(D3DXMATRIX* pM ); 683 HRESULT RotateAxis(D3DXVECTOR3* pV, float Angle); 684 HRESULT RotateAxisLocal(D3DXVECTOR3* pV, float Angle); 685 HRESULT RotateYawPitchRoll(float Yaw, float Pitch, float Roll); 686 HRESULT RotateYawPitchRollLocal(float Yaw, float Pitch, float Roll); 687 HRESULT Scale(float x, float y, float z); 688 HRESULT ScaleLocal(float x, float y, float z); 689 HRESULT Translate(float x, float y, float z ); 690 HRESULT TranslateLocal(float x, float y, float z); 691 D3DXMATRIX* GetTop(); 692 } 693 694 //TODO extern(Windows) HRESULT D3DXCreateMatrixStack(UINT Flags, D3DXMATRIXSTACK* ppStack); 695 696 const D3DXSH_MINORDER = 2; 697 const D3DXSH_MAXORDER = 6; 698 699 extern(Windows) { 700 float* D3DXSHEvalDirection(float* pOut, UINT Order, D3DXVECTOR3* pDir); 701 float* D3DXSHRotate(float* pOut, UINT Order, D3DXMATRIX* pMatrix, float* pIn); 702 float* D3DXSHRotateZ(float* pOut, UINT Order, float Angle, float* pIn); 703 float* D3DXSHAdd(float* pOut, UINT Order, float* pA, float* pB); 704 float* D3DXSHScale(float* pOut, UINT Order, float* pIn, float Scale); 705 float D3DXSHDot(UINT Order, float* pA, float* pB); 706 float* D3DXSHMultiply2(float* pOut, float* pF, float* pG); 707 float* D3DXSHMultiply3(float* pOut, float* pF, float* pG); 708 float* D3DXSHMultiply4(float* pOut, float* pF, float* pG); 709 float* D3DXSHMultiply5(float* pOut, float* pF, float* pG); 710 float* D3DXSHMultiply6(float* pOut, float* pF, float* pG); 711 HRESULT D3DXSHEvalDirectionalLight(UINT Order, D3DXVECTOR3* pDir, float RIntensity, float GIntensity, float BIntensity, float* pROut, float* pGOut, float* pBOut); 712 HRESULT D3DXSHEvalSphericalLight(UINT Order, D3DXVECTOR3* pPos, float Radius, float RIntensity, float GIntensity, float BIntensity, float* pROut, float* pGOut, float* pBOut); 713 HRESULT D3DXSHEvalConeLight(UINT Order, D3DXVECTOR3* pDir, float Radius, float RIntensity, float GIntensity, float BIntensity, float* pROut, float* pGOut, float* pBOut); 714 HRESULT D3DXSHEvalHemisphereLight(UINT Order, D3DXVECTOR3* pDir, D3DXCOLOR Top, D3DXCOLOR Bottom, float* pROut, float* pGOut, float* pBOut); 715 BOOL D3DXIntersectTri(D3DXVECTOR3* p0, D3DXVECTOR3* p1, D3DXVECTOR3* p2, D3DXVECTOR3* pRayPos, D3DXVECTOR3* pRayDir, float* pU, float* pV, float* pDist); 716 BOOL D3DXSphereBoundProbe(D3DXVECTOR3* pCenter, float Radius, D3DXVECTOR3* pRayPosition, D3DXVECTOR3* pRayDirection); 717 BOOL D3DXBoxBoundProbe(D3DXVECTOR3* pMin, D3DXVECTOR3* pMax, D3DXVECTOR3* pRayPosition, D3DXVECTOR3* pRayDirection); 718 HRESULT D3DXComputeBoundingSphere(D3DXVECTOR3* pFirstPosition, DWORD NumVertices, DWORD dwStride, D3DXVECTOR3* pCenter, float* pRadius); 719 HRESULT D3DXComputeBoundingBox(D3DXVECTOR3* pFirstPosition, DWORD NumVertices, DWORD dwStride, D3DXVECTOR3* pMin, D3DXVECTOR3* pMax); 720 } 721 722 enum D3DX_CPU_OPTIMIZATION { 723 D3DX_NOT_OPTIMIZED = 0, 724 D3DX_3DNOW_OPTIMIZED, 725 D3DX_SSE2_OPTIMIZED, 726 D3DX_SSE_OPTIMIZED 727 } 728 729 extern(Windows) D3DX_CPU_OPTIMIZATION D3DXCpuOptimizations(bool Enable);