166 m.MAT4_XX = MAT4_XX * b.MAT4_XX + MAT4_XY * b.MAT4_YX + MAT4_XZ * b.MAT4_ZX + MAT4_XW * b.MAT4_WX;
167 m.MAT4_XY = MAT4_XX * b.MAT4_XY + MAT4_XY * b.MAT4_YY + MAT4_XZ * b.MAT4_ZY + MAT4_XW * b.MAT4_WY;
168 m.MAT4_XZ = MAT4_XX * b.MAT4_XZ + MAT4_XY * b.MAT4_YZ + MAT4_XZ * b.MAT4_ZZ + MAT4_XW * b.MAT4_WZ;
169 m.MAT4_XW = MAT4_XX * b.MAT4_XW + MAT4_XY * b.MAT4_YW + MAT4_XZ * b.MAT4_ZW + MAT4_XW * b.MAT4_WW;
170 m.MAT4_YX = MAT4_YX * b.MAT4_XX + MAT4_YY * b.MAT4_YX + MAT4_YZ * b.MAT4_ZX + MAT4_YW * b.MAT4_WX;
171 m.MAT4_YY = MAT4_YX * b.MAT4_XY + MAT4_YY * b.MAT4_YY + MAT4_YZ * b.MAT4_ZY + MAT4_YW * b.MAT4_WY;
172 m.MAT4_YZ = MAT4_YX * b.MAT4_XZ + MAT4_YY * b.MAT4_YZ + MAT4_YZ * b.MAT4_ZZ + MAT4_YW * b.MAT4_WZ;
173 m.MAT4_YW = MAT4_YX * b.MAT4_XW + MAT4_YY * b.MAT4_YW + MAT4_YZ * b.MAT4_ZW + MAT4_YW * b.MAT4_WW;
174 m.MAT4_ZX = MAT4_ZX * b.MAT4_XX + MAT4_ZY * b.MAT4_YX + MAT4_ZZ * b.MAT4_ZX + MAT4_ZW * b.MAT4_WX;
175 m.MAT4_ZY = MAT4_ZX * b.MAT4_XY + MAT4_ZY * b.MAT4_YY + MAT4_ZZ * b.MAT4_ZY + MAT4_ZW * b.MAT4_WY;
176 m.MAT4_ZZ = MAT4_ZX * b.MAT4_XZ + MAT4_ZY * b.MAT4_YZ + MAT4_ZZ * b.MAT4_ZZ + MAT4_ZW * b.MAT4_WZ;
177 m.MAT4_ZW = MAT4_ZX * b.MAT4_XW + MAT4_ZY * b.MAT4_YW + MAT4_ZZ * b.MAT4_ZW + MAT4_ZW * b.MAT4_WW;
178 m.MAT4_WX = MAT4_WX * b.MAT4_XX + MAT4_WY * b.MAT4_YX + MAT4_WZ * b.MAT4_ZX + MAT4_WW * b.MAT4_WX;
179 m.MAT4_WY = MAT4_WX * b.MAT4_XY + MAT4_WY * b.MAT4_YY + MAT4_WZ * b.MAT4_ZY + MAT4_WW * b.MAT4_WY;
180 m.MAT4_WZ = MAT4_WX * b.MAT4_XZ + MAT4_WY * b.MAT4_YZ + MAT4_WZ * b.MAT4_ZZ + MAT4_WW * b.MAT4_WZ;
181 m.MAT4_WW = MAT4_WX * b.MAT4_XW + MAT4_WY * b.MAT4_YW + MAT4_WZ * b.MAT4_ZW + MAT4_WW * b.MAT4_WW;
187 v.x = MAT4_XX * b.x + MAT4_XY * b.y + MAT4_XZ * b.z + MAT4_XW * b.w;
188 v.y = MAT4_YX * b.x + MAT4_YY * b.y + MAT4_YZ * b.z + MAT4_YW * b.w;
189 v.z = MAT4_ZX * b.x + MAT4_ZY * b.y + MAT4_ZZ * b.z + MAT4_ZW * b.w;
190 v.w = MAT4_WX * b.x + MAT4_WY * b.y + MAT4_WZ * b.z + MAT4_WW * b.w;
234 const T* Pointer()
const {
306 T radians = degrees * 3.14159f / 180.0f;
307 T s = std::sin(radians);
308 T c = std::cos(radians);
332 T radians = degrees * 3.14159f / 180.0f;
333 T s = std::sin(radians);
334 T c = std::cos(radians);
357 T radians = degrees * 3.14159f / 180.0f;
358 T s = std::sin(radians);
359 T c = std::cos(radians);
385 inv.MAT4_XX = m.MAT4_YY * m.MAT4_ZZ * m.MAT4_WW -
386 m.MAT4_YY * m.MAT4_ZW * m.MAT4_WZ -
387 m.MAT4_ZY * m.MAT4_YZ * m.MAT4_WW +
388 m.MAT4_ZY * m.MAT4_YW * m.MAT4_WZ +
389 m.MAT4_WY * m.MAT4_YZ * m.MAT4_ZW -
390 m.MAT4_WY * m.MAT4_YW * m.MAT4_ZZ;
392 inv.MAT4_YX = -m.MAT4_YX * m.MAT4_ZZ * m.MAT4_WW +
393 m.MAT4_YX * m.MAT4_ZW * m.MAT4_WZ +
394 m.MAT4_ZX * m.MAT4_YZ * m.MAT4_WW -
395 m.MAT4_ZX * m.MAT4_YW * m.MAT4_WZ -
396 m.MAT4_WX * m.MAT4_YZ * m.MAT4_ZW +
397 m.MAT4_WX * m.MAT4_YW * m.MAT4_ZZ;
399 inv.MAT4_ZX = m.MAT4_YX * m.MAT4_ZY * m.MAT4_WW -
400 m.MAT4_YX * m.MAT4_ZW * m.MAT4_WY -
401 m.MAT4_ZX * m.MAT4_YY * m.MAT4_WW +
402 m.MAT4_ZX * m.MAT4_YW * m.MAT4_WY +
403 m.MAT4_WX * m.MAT4_YY * m.MAT4_ZW -
404 m.MAT4_WX * m.MAT4_YW * m.MAT4_ZY;
406 inv.MAT4_WX = -m.MAT4_YX * m.MAT4_ZY * m.MAT4_WZ +
407 m.MAT4_YX * m.MAT4_ZZ * m.MAT4_WY +
408 m.MAT4_ZX * m.MAT4_YY * m.MAT4_WZ -
409 m.MAT4_ZX * m.MAT4_YZ * m.MAT4_WY -
410 m.MAT4_WX * m.MAT4_YY * m.MAT4_ZZ +
411 m.MAT4_WX * m.MAT4_YZ * m.MAT4_ZY;
413 inv.MAT4_XY = -m.MAT4_XY * m.MAT4_ZZ * m.MAT4_WW +
414 m.MAT4_XY * m.MAT4_ZW * m.MAT4_WZ +
415 m.MAT4_ZY * m.MAT4_XZ * m.MAT4_WW -
416 m.MAT4_ZY * m.MAT4_XW * m.MAT4_WZ -
417 m.MAT4_WY * m.MAT4_XZ * m.MAT4_ZW +
418 m.MAT4_WY * m.MAT4_XW * m.MAT4_ZZ;
420 inv.MAT4_YY = m.MAT4_XX * m.MAT4_ZZ * m.MAT4_WW -
421 m.MAT4_XX * m.MAT4_ZW * m.MAT4_WZ -
422 m.MAT4_ZX * m.MAT4_XZ * m.MAT4_WW +
423 m.MAT4_ZX * m.MAT4_XW * m.MAT4_WZ +
424 m.MAT4_WX * m.MAT4_XZ * m.MAT4_ZW -
425 m.MAT4_WX * m.MAT4_XW * m.MAT4_ZZ;
427 inv.MAT4_ZY = -m.MAT4_XX * m.MAT4_ZY * m.MAT4_WW +
428 m.MAT4_XX * m.MAT4_ZW * m.MAT4_WY +
429 m.MAT4_ZX * m.MAT4_XY * m.MAT4_WW -
430 m.MAT4_ZX * m.MAT4_XW * m.MAT4_WY -
431 m.MAT4_WX * m.MAT4_XY * m.MAT4_ZW +
432 m.MAT4_WX * m.MAT4_XW * m.MAT4_ZY;
434 inv.MAT4_WY = m.MAT4_XX * m.MAT4_ZY * m.MAT4_WZ -
435 m.MAT4_XX * m.MAT4_ZZ * m.MAT4_WY -
436 m.MAT4_ZX * m.MAT4_XY * m.MAT4_WZ +
437 m.MAT4_ZX * m.MAT4_XZ * m.MAT4_WY +
438 m.MAT4_WX * m.MAT4_XY * m.MAT4_ZZ -
439 m.MAT4_WX * m.MAT4_XZ * m.MAT4_ZY;
441 inv.MAT4_XZ = m.MAT4_XY * m.MAT4_YZ * m.MAT4_WW -
442 m.MAT4_XY * m.MAT4_YW * m.MAT4_WZ -
443 m.MAT4_YY * m.MAT4_XZ * m.MAT4_WW +
444 m.MAT4_YY * m.MAT4_XW * m.MAT4_WZ +
445 m.MAT4_WY * m.MAT4_XZ * m.MAT4_YW -
446 m.MAT4_WY * m.MAT4_XW * m.MAT4_YZ;
448 inv.MAT4_YZ = -m.MAT4_XX * m.MAT4_YZ * m.MAT4_WW +
449 m.MAT4_XX * m.MAT4_YW * m.MAT4_WZ +
450 m.MAT4_YX * m.MAT4_XZ * m.MAT4_WW -
451 m.MAT4_YX * m.MAT4_XW * m.MAT4_WZ -
452 m.MAT4_WX * m.MAT4_XZ * m.MAT4_YW +
453 m.MAT4_WX * m.MAT4_XW * m.MAT4_YZ;
455 inv.MAT4_ZZ = m.MAT4_XX * m.MAT4_YY * m.MAT4_WW -
456 m.MAT4_XX * m.MAT4_YW * m.MAT4_WY -
457 m.MAT4_YX * m.MAT4_XY * m.MAT4_WW +
458 m.MAT4_YX * m.MAT4_XW * m.MAT4_WY +
459 m.MAT4_WX * m.MAT4_XY * m.MAT4_YW -
460 m.MAT4_WX * m.MAT4_XW * m.MAT4_YY;
462 inv.MAT4_WZ = -m.MAT4_XX * m.MAT4_YY * m.MAT4_WZ +
463 m.MAT4_XX * m.MAT4_YZ * m.MAT4_WY +
464 m.MAT4_YX * m.MAT4_XY * m.MAT4_WZ -
465 m.MAT4_YX * m.MAT4_XZ * m.MAT4_WY -
466 m.MAT4_WX * m.MAT4_XY * m.MAT4_YZ +
467 m.MAT4_WX * m.MAT4_XZ * m.MAT4_YY;
469 inv.MAT4_XW = -m.MAT4_XY * m.MAT4_YZ * m.MAT4_ZW +
470 m.MAT4_XY * m.MAT4_YW * m.MAT4_ZZ +
471 m.MAT4_YY * m.MAT4_XZ * m.MAT4_ZW -
472 m.MAT4_YY * m.MAT4_XW * m.MAT4_ZZ -
473 m.MAT4_ZY * m.MAT4_XZ * m.MAT4_YW +
474 m.MAT4_ZY * m.MAT4_XW * m.MAT4_YZ;
476 inv.MAT4_YW = m.MAT4_XX * m.MAT4_YZ * m.MAT4_ZW -
477 m.MAT4_XX * m.MAT4_YW * m.MAT4_ZZ -
478 m.MAT4_YX * m.MAT4_XZ * m.MAT4_ZW +
479 m.MAT4_YX * m.MAT4_XW * m.MAT4_ZZ +
480 m.MAT4_ZX * m.MAT4_XZ * m.MAT4_YW -
481 m.MAT4_ZX * m.MAT4_XW * m.MAT4_YZ;
483 inv.MAT4_ZW = -m.MAT4_XX * m.MAT4_YY * m.MAT4_ZW +
484 m.MAT4_XX * m.MAT4_YW * m.MAT4_ZY +
485 m.MAT4_YX * m.MAT4_XY * m.MAT4_ZW -
486 m.MAT4_YX * m.MAT4_XW * m.MAT4_ZY -
487 m.MAT4_ZX * m.MAT4_XY * m.MAT4_YW +
488 m.MAT4_ZX * m.MAT4_XW * m.MAT4_YY;
490 inv.MAT4_WW = m.MAT4_XX * m.MAT4_YY * m.MAT4_ZZ -
491 m.MAT4_XX * m.MAT4_YZ * m.MAT4_ZY -
492 m.MAT4_YX * m.MAT4_XY * m.MAT4_ZZ +
493 m.MAT4_YX * m.MAT4_XZ * m.MAT4_ZY +
494 m.MAT4_ZX * m.MAT4_XY * m.MAT4_YZ -
495 m.MAT4_ZX * m.MAT4_XZ * m.MAT4_YY;
497 det = m.MAT4_XX * inv.MAT4_XX + m.MAT4_XY * inv.MAT4_YX + m.MAT4_XZ * inv.MAT4_ZX + m.MAT4_XW * inv.MAT4_WX;
506 invOut.MAT4_XX = inv.MAT4_XX * det;
507 invOut.MAT4_XY = inv.MAT4_XY * det;
508 invOut.MAT4_XZ = inv.MAT4_XZ * det;
509 invOut.MAT4_XW = inv.MAT4_XW * det;
511 invOut.MAT4_YX = inv.MAT4_YX * det;
512 invOut.MAT4_YY = inv.MAT4_YY * det;
513 invOut.MAT4_YZ = inv.MAT4_YZ * det;
514 invOut.MAT4_YW = inv.MAT4_YW * det;
516 invOut.MAT4_ZX = inv.MAT4_ZX * det;
517 invOut.MAT4_ZY = inv.MAT4_ZY * det;
518 invOut.MAT4_ZZ = inv.MAT4_ZZ * det;
519 invOut.MAT4_ZW = inv.MAT4_ZW * det;
521 invOut.MAT4_WX = inv.MAT4_WX * det;
522 invOut.MAT4_WY = inv.MAT4_WY * det;
523 invOut.MAT4_WZ = inv.MAT4_WZ * det;
524 invOut.MAT4_WW = inv.MAT4_WW * det;
529 static Matrix4<T> Frustum(T tLeft, T tRight, T tBottom, T tTop, T tNear, T tFar) {
530 T a = 2 * tNear / (tRight - tLeft);
531 T b = 2 * tNear / (tTop - tBottom);
532 T c = (tRight + tLeft) / (tRight - tLeft);
533 T d = (tTop + tBottom) / (tTop - tBottom);
534 T e = -(tFar + tNear) / (tFar - tNear);
535 T f = -2 * tFar * tNear / (tFar - tNear);
556 static Matrix4<T> Perspective(T fovy, T aspect, T tNear, T tFar) {
559 T radians = (T) (fovy * 0.008726644f);
560 T deltaZ = (T) (tFar - tNear);
562 T h = 1.0f / tan(radians);
564 T a = -tNear / deltaZ;
565 T b = (tNear * tFar) / deltaZ;
577 static Matrix4<T> Ortho(T xMin, T xMax, T yMin, T yMax, T zMin, T zMax) {
580 T xDiff = xMax - xMin;
581 T yDiff = yMax - yMin;
582 T zDiff = zMax - zMin;
584 m.MAT4_XX = 2.0f / xDiff;
585 m.MAT4_YY = 2.0f / yDiff;
586 m.MAT4_ZZ = -2.0f / zDiff;
588 m.MAT4_WX = -(xMax + xMin) / xDiff;
589 m.MAT4_WY = -(yMax + yMin) / yDiff;
590 m.MAT4_WZ = -(zMax + zMin) / zDiff;