Subversion Repositories Games.Carmageddon

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "matrix4.h"
  2. #include "harness/trace.h"
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. #define A(x, y) A->m[x][y]
  7. #define B(x, y) B->m[x][y]
  8. #define C(x, y) C->m[x][y]
  9. #define M(x, y) mat->m[x][y]
  10.  
  11. #define BR_MAC2(a, b, c, d) ((a) * (b) + (c) * (d))
  12. #define BR_MAC3(a, b, c, d, e, f) ((a) * (b) + (c) * (d) + (e) * (f))
  13. #define BR_MAC4(a, b, c, d, e, f, g, h) ((a) * (b) + (c) * (d) + (e) * (f) + (g) * (h))
  14.  
  15. // IDA: void __cdecl BrMatrix4Copy(br_matrix4 *A, br_matrix4 *B)
  16. void BrMatrix4Copy(br_matrix4* A, br_matrix4* B) {
  17.     LOG_TRACE("(%p, %p)", A, B);
  18.  
  19.     A(0, 0) = B(0, 0);
  20.     A(0, 1) = B(0, 1);
  21.     A(0, 2) = B(0, 2);
  22.     A(0, 3) = B(0, 3);
  23.     A(1, 0) = B(1, 0);
  24.     A(1, 1) = B(1, 1);
  25.     A(1, 2) = B(1, 2);
  26.     A(1, 3) = B(1, 3);
  27.     A(2, 0) = B(2, 0);
  28.     A(2, 1) = B(2, 1);
  29.     A(2, 2) = B(2, 2);
  30.     A(2, 3) = B(2, 3);
  31.     A(3, 0) = B(3, 0);
  32.     A(3, 1) = B(3, 1);
  33.     A(3, 2) = B(3, 2);
  34.     A(3, 3) = B(3, 3);
  35. }
  36.  
  37. // IDA: void __cdecl BrMatrix4Mul(br_matrix4 *A, br_matrix4 *B, br_matrix4 *C)
  38. void BrMatrix4Mul(br_matrix4* A, br_matrix4* B, br_matrix4* C) {
  39.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  40.  
  41.     A(0, 0) = BR_MAC4(B(0, 0), C(0, 0), B(0, 1), C(1, 0), B(0, 2), C(2, 0), B(0, 3), C(3, 0));
  42.     A(0, 1) = BR_MAC4(B(0, 0), C(0, 1), B(0, 1), C(1, 1), B(0, 2), C(2, 1), B(0, 3), C(3, 1));
  43.     A(0, 2) = BR_MAC4(B(0, 0), C(0, 2), B(0, 1), C(1, 2), B(0, 2), C(2, 2), B(0, 3), C(3, 2));
  44.     A(0, 3) = BR_MAC4(B(0, 0), C(0, 3), B(0, 1), C(1, 3), B(0, 2), C(2, 3), B(0, 3), C(3, 3));
  45.     A(1, 0) = BR_MAC4(B(1, 0), C(0, 0), B(1, 1), C(1, 0), B(1, 2), C(2, 0), B(1, 3), C(3, 0));
  46.     A(1, 1) = BR_MAC4(B(1, 0), C(0, 1), B(1, 1), C(1, 1), B(1, 2), C(2, 1), B(1, 3), C(3, 1));
  47.     A(1, 2) = BR_MAC4(B(1, 0), C(0, 2), B(1, 1), C(1, 2), B(1, 2), C(2, 2), B(1, 3), C(3, 2));
  48.     A(1, 3) = BR_MAC4(B(1, 0), C(0, 3), B(1, 1), C(1, 3), B(1, 2), C(2, 3), B(1, 3), C(3, 3));
  49.     A(2, 0) = BR_MAC4(B(2, 0), C(0, 0), B(2, 1), C(1, 0), B(2, 2), C(2, 0), B(2, 3), C(3, 0));
  50.     A(2, 1) = BR_MAC4(B(2, 0), C(0, 1), B(2, 1), C(1, 1), B(2, 2), C(2, 1), B(2, 3), C(3, 1));
  51.     A(2, 2) = BR_MAC4(B(2, 0), C(0, 2), B(2, 1), C(1, 2), B(2, 2), C(2, 2), B(2, 3), C(3, 2));
  52.     A(2, 3) = BR_MAC4(B(2, 0), C(0, 3), B(2, 1), C(1, 3), B(2, 2), C(2, 3), B(2, 3), C(3, 3));
  53.     A(3, 0) = BR_MAC4(B(3, 0), C(0, 0), B(3, 1), C(1, 0), B(3, 2), C(2, 0), B(3, 3), C(3, 0));
  54.     A(3, 1) = BR_MAC4(B(3, 0), C(0, 1), B(3, 1), C(1, 1), B(3, 2), C(2, 1), B(3, 3), C(3, 1));
  55.     A(3, 2) = BR_MAC4(B(3, 0), C(0, 2), B(3, 1), C(1, 2), B(3, 2), C(2, 2), B(3, 3), C(3, 2));
  56.     A(3, 3) = BR_MAC4(B(3, 0), C(0, 3), B(3, 1), C(1, 3), B(3, 2), C(2, 3), B(3, 3), C(3, 3));
  57. }
  58.  
  59. // IDA: void __cdecl BrMatrix4Identity(br_matrix4 *mat)
  60. void BrMatrix4Identity(br_matrix4* mat) {
  61.     LOG_TRACE("(%p)", mat);
  62.  
  63.     M(0, 0) = BR_SCALAR(1.f);
  64.     M(0, 1) = BR_SCALAR(0.f);
  65.     M(0, 2) = BR_SCALAR(0.f);
  66.     M(0, 3) = BR_SCALAR(0.f);
  67.     M(1, 0) = BR_SCALAR(0.f);
  68.     M(1, 1) = BR_SCALAR(1.f);
  69.     M(1, 2) = BR_SCALAR(0.f);
  70.     M(1, 3) = BR_SCALAR(0.f);
  71.     M(2, 0) = BR_SCALAR(0.f);
  72.     M(2, 1) = BR_SCALAR(0.f);
  73.     M(2, 2) = BR_SCALAR(1.f);
  74.     M(2, 3) = BR_SCALAR(0.f);
  75.     M(3, 0) = BR_SCALAR(0.f);
  76.     M(3, 1) = BR_SCALAR(0.f);
  77.     M(3, 2) = BR_SCALAR(0.f);
  78.     M(3, 3) = BR_SCALAR(1.f);
  79. }
  80.  
  81. // IDA: void __cdecl BrMatrix4Scale(br_matrix4 *mat, br_scalar sx, br_scalar sy, br_scalar sz)
  82. void BrMatrix4Scale(br_matrix4* mat, br_scalar sx, br_scalar sy, br_scalar sz) {
  83.     LOG_TRACE("(%p, %f, %f, %f)", mat, sx, sy, sz);
  84.  
  85.     M(0, 0) = sx;
  86.     M(1, 1) = sy;
  87.     M(2, 2) = sz;
  88.     M(0, 1) = BR_SCALAR(0.f);
  89.     M(0, 2) = BR_SCALAR(0.f);
  90.     M(0, 3) = BR_SCALAR(0.f);
  91.     M(1, 0) = BR_SCALAR(0.f);
  92.     M(1, 2) = BR_SCALAR(0.f);
  93.     M(1, 3) = BR_SCALAR(0.f);
  94.     M(2, 0) = BR_SCALAR(0.f);
  95.     M(2, 1) = BR_SCALAR(0.f);
  96.     M(2, 3) = BR_SCALAR(0.f);
  97.     M(3, 0) = BR_SCALAR(0.f);
  98.     M(3, 1) = BR_SCALAR(0.f);
  99.     M(3, 2) = BR_SCALAR(0.f);
  100.     M(3, 3) = BR_SCALAR(1.f);
  101. }
  102.  
  103. // IDA: br_scalar __cdecl BrMatrix4Inverse(br_matrix4 *A, br_matrix4 *B)
  104. br_scalar BrMatrix4Inverse(br_matrix4* A, br_matrix4* B) {
  105.     int i;
  106.     int j;
  107.     br_scalar det;
  108.     br_scalar idet;
  109.     LOG_TRACE("(%p, %p)", A, B);
  110.  
  111.     BrMatrix4Adjoint(A, B);
  112.     det = BrMatrix4Determinant(B);
  113.  
  114.     if (fabs(det) < BR_SCALAR_EPSILON * 2)
  115.         return 0;
  116.  
  117.     idet = (br_scalar) 1.0 / det; // Pierre-Marie Baty -- added type cast
  118.     for (i = 0; i < 4; i++) {
  119.         for (j = 0; j < 4; j++) {
  120.             A(i, j) = A(i, j) * idet;
  121.         }
  122.     }
  123.  
  124.     return det;
  125. }
  126.  
  127. // IDA: br_scalar __cdecl Determinant3(br_scalar a1, br_scalar a2, br_scalar a3, br_scalar b1, br_scalar b2, br_scalar b3, br_scalar c1, br_scalar c2, br_scalar c3)
  128. br_scalar Determinant3(br_scalar a1, br_scalar a2, br_scalar a3, br_scalar b1, br_scalar b2, br_scalar b3, br_scalar c1, br_scalar c2, br_scalar c3) {
  129.     LOG_TRACE("(%f, %f, %f, %f, %f, %f, %f, %f, %f)", a1, a2, a3, b1, b2, b3, c1, c2, c3);
  130.  
  131.     return BR_MAC3(a1, BR_MAC2(b2, c3, -b3, c2),
  132.         -b1, BR_MAC2(a2, c3, -a3, c2),
  133.         c1, BR_MAC2(a2, b3, -a3, b2));
  134. }
  135.  
  136. // IDA: br_scalar __cdecl BrMatrix4Determinant(br_matrix4 *mat)
  137. br_scalar BrMatrix4Determinant(br_matrix4* mat) {
  138.     br_scalar a1;
  139.     br_scalar a2;
  140.     br_scalar a3;
  141.     br_scalar a4;
  142.     br_scalar b1;
  143.     br_scalar b2;
  144.     br_scalar b3;
  145.     br_scalar b4;
  146.     br_scalar c1;
  147.     br_scalar c2;
  148.     br_scalar c3;
  149.     br_scalar c4;
  150.     br_scalar d1;
  151.     br_scalar d2;
  152.     br_scalar d3;
  153.     br_scalar d4;
  154.     LOG_TRACE("(%p)", mat);
  155.  
  156.     a1 = M(0, 0);
  157.     b1 = M(0, 1);
  158.     c1 = M(0, 2);
  159.     d1 = M(0, 3);
  160.  
  161.     a2 = M(1, 0);
  162.     b2 = M(1, 1);
  163.     c2 = M(1, 2);
  164.     d2 = M(1, 3);
  165.  
  166.     a3 = M(2, 0);
  167.     b3 = M(2, 1);
  168.     c3 = M(2, 2);
  169.     d3 = M(2, 3);
  170.  
  171.     a4 = M(3, 0);
  172.     b4 = M(3, 1);
  173.     c4 = M(3, 2);
  174.     d4 = M(3, 3);
  175.  
  176.     return BR_MAC4(a1, Determinant3(b2, b3, b4, c2, c3, c4, d2, d3, d4),
  177.         -b1, Determinant3(a2, a3, a4, c2, c3, c4, d2, d3, d4),
  178.         c1, Determinant3(a2, a3, a4, b2, b3, b4, d2, d3, d4),
  179.         -d1, Determinant3(a2, a3, a4, b2, b3, b4, c2, c3, c4));
  180. }
  181.  
  182. // IDA: void __cdecl BrMatrix4Adjoint(br_matrix4 *A, br_matrix4 *B)
  183. void BrMatrix4Adjoint(br_matrix4* A, br_matrix4* B) {
  184.     br_scalar a1;
  185.     br_scalar a2;
  186.     br_scalar a3;
  187.     br_scalar a4;
  188.     br_scalar b1;
  189.     br_scalar b2;
  190.     br_scalar b3;
  191.     br_scalar b4;
  192.     br_scalar c1;
  193.     br_scalar c2;
  194.     br_scalar c3;
  195.     br_scalar c4;
  196.     br_scalar d1;
  197.     br_scalar d2;
  198.     br_scalar d3;
  199.     br_scalar d4;
  200.     LOG_TRACE("(%p, %p)", A, B);
  201.  
  202.     a1 = B(0, 0);
  203.     b1 = B(0, 1);
  204.     c1 = B(0, 2);
  205.     d1 = B(0, 3);
  206.  
  207.     a2 = B(1, 0);
  208.     b2 = B(1, 1);
  209.     c2 = B(1, 2);
  210.     d2 = B(1, 3);
  211.  
  212.     a3 = B(2, 0);
  213.     b3 = B(2, 1);
  214.     c3 = B(2, 2);
  215.     d3 = B(2, 3);
  216.  
  217.     a4 = B(3, 0);
  218.     b4 = B(3, 1);
  219.     c4 = B(3, 2);
  220.     d4 = B(3, 3);
  221.  
  222.     /* row column labeling reversed since we transpose rows & columns */
  223.  
  224.     A(0, 0) = Determinant3(b2, b3, b4, c2, c3, c4, d2, d3, d4);
  225.     A(1, 0) = -Determinant3(a2, a3, a4, c2, c3, c4, d2, d3, d4);
  226.     A(2, 0) = Determinant3(a2, a3, a4, b2, b3, b4, d2, d3, d4);
  227.     A(3, 0) = -Determinant3(a2, a3, a4, b2, b3, b4, c2, c3, c4);
  228.  
  229.     A(0, 1) = -Determinant3(b1, b3, b4, c1, c3, c4, d1, d3, d4);
  230.     A(1, 1) = Determinant3(a1, a3, a4, c1, c3, c4, d1, d3, d4);
  231.     A(2, 1) = -Determinant3(a1, a3, a4, b1, b3, b4, d1, d3, d4);
  232.     A(3, 1) = Determinant3(a1, a3, a4, b1, b3, b4, c1, c3, c4);
  233.  
  234.     A(0, 2) = Determinant3(b1, b2, b4, c1, c2, c4, d1, d2, d4);
  235.     A(1, 2) = -Determinant3(a1, a2, a4, c1, c2, c4, d1, d2, d4);
  236.     A(2, 2) = Determinant3(a1, a2, a4, b1, b2, b4, d1, d2, d4);
  237.     A(3, 2) = -Determinant3(a1, a2, a4, b1, b2, b4, c1, c2, c4);
  238.  
  239.     A(0, 3) = -Determinant3(b1, b2, b3, c1, c2, c3, d1, d2, d3);
  240.     A(1, 3) = Determinant3(a1, a2, a3, c1, c2, c3, d1, d2, d3);
  241.     A(2, 3) = -Determinant3(a1, a2, a3, b1, b2, b3, d1, d2, d3);
  242.     A(3, 3) = Determinant3(a1, a2, a3, b1, b2, b3, c1, c2, c3);
  243. }
  244.  
  245. // IDA: void __cdecl BrMatrix4Perspective(br_matrix4 *mat, br_angle field_of_view, br_scalar aspect, br_scalar hither, br_scalar yon)
  246. void BrMatrix4Perspective(br_matrix4* mat, br_angle field_of_view, br_scalar aspect, br_scalar hither, br_scalar yon) {
  247.     br_scalar scale;
  248.     LOG_TRACE("(%p, %d, %f, %f, %f)", mat, field_of_view, aspect, hither, yon);
  249.  
  250.     scale = BR_COS(field_of_view / 2) / BR_SIN(field_of_view / 2);
  251.  
  252.     M(0, 0) = scale / aspect;
  253.     M(1, 1) = scale;
  254.     M(2, 2) = (yon + hither) / (yon - hither);
  255.     M(3, 2) = BR_SCALAR(-2.f) * ((yon * hither) / (yon - hither));
  256.  
  257.     M(0, 1) = BR_SCALAR(0.f);
  258.     M(0, 2) = BR_SCALAR(0.f);
  259.     M(0, 3) = BR_SCALAR(0.f);
  260.     M(1, 0) = BR_SCALAR(0.f);
  261.     M(1, 2) = BR_SCALAR(0.f);
  262.     M(1, 3) = BR_SCALAR(0.f);
  263.     M(2, 0) = BR_SCALAR(0.f);
  264.     M(2, 1) = BR_SCALAR(0.f);
  265.     M(2, 3) = BR_SCALAR(-1.f);
  266.     M(3, 0) = BR_SCALAR(0.f);
  267.     M(3, 1) = BR_SCALAR(0.f);
  268.     M(3, 3) = BR_SCALAR(0.f);
  269. }
  270.  
  271. // IDA: void __cdecl BrMatrix4Apply(br_vector4 *A, br_vector4 *B, br_matrix4 *C)
  272. void BrMatrix4Apply(br_vector4* A, br_vector4* B, br_matrix4* C) {
  273.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  274.  
  275.     A->v[0] = BR_MAC4(B->v[0], C(0, 0), B->v[1], C(1, 0), B->v[2], C(2, 0), B->v[3], C(3, 0));
  276.     A->v[1] = BR_MAC4(B->v[0], C(0, 1), B->v[1], C(1, 1), B->v[2], C(2, 1), B->v[3], C(3, 1));
  277.     A->v[2] = BR_MAC4(B->v[0], C(0, 2), B->v[1], C(1, 2), B->v[2], C(2, 2), B->v[3], C(3, 2));
  278.     A->v[3] = BR_MAC4(B->v[0], C(0, 3), B->v[1], C(1, 3), B->v[2], C(2, 3), B->v[3], C(3, 3));
  279. }
  280.  
  281. // IDA: void __cdecl BrMatrix4ApplyP(br_vector4 *A, br_vector3 *B, br_matrix4 *C)
  282. void BrMatrix4ApplyP(br_vector4* A, br_vector3* B, br_matrix4* C) {
  283.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  284.  
  285.     A->v[0] = BR_MAC3(B->v[0], C(0, 0), B->v[1], C(1, 0), B->v[2], C(2, 0)) + C(3, 0);
  286.     A->v[1] = BR_MAC3(B->v[0], C(0, 1), B->v[1], C(1, 1), B->v[2], C(2, 1)) + C(3, 1);
  287.     A->v[2] = BR_MAC3(B->v[0], C(0, 2), B->v[1], C(1, 2), B->v[2], C(2, 2)) + C(3, 2);
  288.     A->v[3] = BR_MAC3(B->v[0], C(0, 3), B->v[1], C(1, 3), B->v[2], C(2, 3)) + C(3, 3);
  289. }
  290.  
  291. // IDA: void __cdecl BrMatrix4ApplyV(br_vector4 *A, br_vector3 *B, br_matrix4 *C)
  292. void BrMatrix4ApplyV(br_vector4* A, br_vector3* B, br_matrix4* C) {
  293.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  294.  
  295.     A->v[0] = BR_MAC3(B->v[0], C(0, 0), B->v[1], C(1, 0), B->v[2], C(2, 0));
  296.     A->v[1] = BR_MAC3(B->v[0], C(0, 1), B->v[1], C(1, 1), B->v[2], C(2, 1));
  297.     A->v[2] = BR_MAC3(B->v[0], C(0, 2), B->v[1], C(1, 2), B->v[2], C(2, 2));
  298.     A->v[3] = BR_MAC3(B->v[0], C(0, 3), B->v[1], C(1, 3), B->v[2], C(2, 3));
  299. }
  300.  
  301. // IDA: void __cdecl BrMatrix4TApply(br_vector4 *A, br_vector4 *B, br_matrix4 *C)
  302. void BrMatrix4TApply(br_vector4* A, br_vector4* B, br_matrix4* C) {
  303.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  304.  
  305.     A->v[0] = BR_MAC4(B->v[0], C(0, 0), B->v[1], C(0, 1), B->v[2], C(0, 2), B->v[3], C(0, 3));
  306.     A->v[1] = BR_MAC4(B->v[0], C(1, 0), B->v[1], C(1, 1), B->v[2], C(1, 2), B->v[3], C(1, 3));
  307.     A->v[2] = BR_MAC4(B->v[0], C(2, 0), B->v[1], C(2, 1), B->v[2], C(2, 2), B->v[3], C(2, 3));
  308.     A->v[3] = BR_MAC4(B->v[0], C(3, 0), B->v[1], C(3, 1), B->v[2], C(3, 2), B->v[3], C(3, 3));
  309. }
  310.  
  311. // IDA: void __cdecl BrMatrix4TApplyP(br_vector4 *A, br_vector3 *B, br_matrix4 *C)
  312. void BrMatrix4TApplyP(br_vector4* A, br_vector3* B, br_matrix4* C) {
  313.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  314.  
  315.     A->v[0] = BR_MAC3(B->v[0], C(0, 0), B->v[1], C(0, 1), B->v[2], C(0, 2)) + C(0, 3);
  316.     A->v[1] = BR_MAC3(B->v[0], C(1, 0), B->v[1], C(1, 1), B->v[2], C(1, 2)) + C(1, 3);
  317.     A->v[2] = BR_MAC3(B->v[0], C(2, 0), B->v[1], C(2, 1), B->v[2], C(2, 2)) + C(2, 3);
  318.     A->v[3] = BR_MAC3(B->v[0], C(3, 0), B->v[1], C(3, 1), B->v[2], C(3, 2)) + C(3, 3);
  319. }
  320.  
  321. // IDA: void __cdecl BrMatrix4TApplyV(br_vector4 *A, br_vector3 *B, br_matrix4 *C)
  322. void BrMatrix4TApplyV(br_vector4* A, br_vector3* B, br_matrix4* C) {
  323.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  324.  
  325.     A->v[0] = BR_MAC3(B->v[0], C(0, 0), B->v[1], C(0, 1), B->v[2], C(0, 2));
  326.     A->v[1] = BR_MAC3(B->v[0], C(1, 0), B->v[1], C(1, 1), B->v[2], C(1, 2));
  327.     A->v[2] = BR_MAC3(B->v[0], C(2, 0), B->v[1], C(2, 1), B->v[2], C(2, 2));
  328.     A->v[3] = BR_MAC3(B->v[0], C(3, 0), B->v[1], C(3, 1), B->v[2], C(3, 2));
  329. }
  330.  
  331. // IDA: void __cdecl BrMatrix4Copy34(br_matrix4 *A, br_matrix34 *B)
  332. void BrMatrix4Copy34(br_matrix4* A, br_matrix34* B) {
  333.     LOG_TRACE("(%p, %p)", A, B);
  334.  
  335.     A(0, 0) = B(0, 0);
  336.     A(0, 1) = B(0, 1);
  337.     A(0, 2) = B(0, 2);
  338.     A(0, 3) = BR_SCALAR(0.f);
  339.     A(1, 0) = B(1, 0);
  340.     A(1, 1) = B(1, 1);
  341.     A(1, 2) = B(1, 2);
  342.     A(1, 3) = BR_SCALAR(0.f);
  343.     A(2, 0) = B(2, 0);
  344.     A(2, 1) = B(2, 1);
  345.     A(2, 2) = B(2, 2);
  346.     A(2, 3) = BR_SCALAR(0.f);
  347.     A(3, 0) = B(3, 0);
  348.     A(3, 1) = B(3, 1);
  349.     A(3, 2) = B(3, 2);
  350.     A(3, 3) = BR_SCALAR(1.f);
  351. }
  352.  
  353. // IDA: void __cdecl BrMatrix4Mul34(br_matrix4 *A, br_matrix34 *B, br_matrix4 *C)
  354. void BrMatrix4Mul34(br_matrix4* A, br_matrix34* B, br_matrix4* C) {
  355.     LOG_TRACE("(%p, %p, %p)", A, B, C);
  356.  
  357.     A(0, 0) = BR_MAC3(B(0, 0), C(0, 0), B(0, 1), C(1, 0), B(0, 2), C(2, 0));
  358.     A(0, 1) = BR_MAC3(B(0, 0), C(0, 1), B(0, 1), C(1, 1), B(0, 2), C(2, 1));
  359.     A(0, 2) = BR_MAC3(B(0, 0), C(0, 2), B(0, 1), C(1, 2), B(0, 2), C(2, 2));
  360.     A(0, 3) = BR_MAC3(B(0, 0), C(0, 3), B(0, 1), C(1, 3), B(0, 2), C(2, 3));
  361.     A(1, 0) = BR_MAC3(B(1, 0), C(0, 0), B(1, 1), C(1, 0), B(1, 2), C(2, 0));
  362.     A(1, 1) = BR_MAC3(B(1, 0), C(0, 1), B(1, 1), C(1, 1), B(1, 2), C(2, 1));
  363.     A(1, 2) = BR_MAC3(B(1, 0), C(0, 2), B(1, 1), C(1, 2), B(1, 2), C(2, 2));
  364.     A(1, 3) = BR_MAC3(B(1, 0), C(0, 3), B(1, 1), C(1, 3), B(1, 2), C(2, 3));
  365.     A(2, 0) = BR_MAC3(B(2, 0), C(0, 0), B(2, 1), C(1, 0), B(2, 2), C(2, 0));
  366.     A(2, 1) = BR_MAC3(B(2, 0), C(0, 1), B(2, 1), C(1, 1), B(2, 2), C(2, 1));
  367.     A(2, 2) = BR_MAC3(B(2, 0), C(0, 2), B(2, 1), C(1, 2), B(2, 2), C(2, 2));
  368.     A(2, 3) = BR_MAC3(B(2, 0), C(0, 3), B(2, 1), C(1, 3), B(2, 2), C(2, 3));
  369.     A(3, 0) = BR_MAC3(B(3, 0), C(0, 0), B(3, 1), C(1, 0), B(3, 2), C(2, 0)) + C(3, 0);
  370.     A(3, 1) = BR_MAC3(B(3, 0), C(0, 1), B(3, 1), C(1, 1), B(3, 2), C(2, 1)) + C(3, 1);
  371.     A(3, 2) = BR_MAC3(B(3, 0), C(0, 2), B(3, 1), C(1, 2), B(3, 2), C(2, 2)) + C(3, 2);
  372.     A(3, 3) = BR_MAC3(B(3, 0), C(0, 3), B(3, 1), C(1, 3), B(3, 2), C(2, 3)) + C(3, 3);
  373. }
  374.  
  375. // IDA: void __cdecl BrMatrix4Pre34(br_matrix4 *A, br_matrix34 *B)
  376. void BrMatrix4Pre34(br_matrix4* A, br_matrix34* B) {
  377.     br_matrix4 C;
  378.     LOG_TRACE("(%p, %p)", A, B);
  379.  
  380.     memcpy(&C, A, sizeof(*A));
  381.     BrMatrix4Mul34(A, B, &C);
  382. }
  383.  
  384. // IDA: void __cdecl BrMatrix4ShearZ(br_matrix4 *mat, br_scalar sx, br_scalar sy)
  385. void BrMatrix4ShearZ(br_matrix4* mat, br_scalar sx, br_scalar sy) {
  386.     LOG_TRACE("(%p, %f, %f)", mat, sx, sy);
  387.  
  388.     M(0, 0) = BR_SCALAR(1.f);
  389.     M(0, 1) = BR_SCALAR(0.f);
  390.     M(0, 2) = BR_SCALAR(0.f);
  391.     M(0, 3) = BR_SCALAR(0.f);
  392.     M(1, 0) = BR_SCALAR(0.f);
  393.     M(1, 1) = BR_SCALAR(1.f);
  394.     M(1, 2) = BR_SCALAR(0.f);
  395.     M(1, 3) = BR_SCALAR(0.f);
  396.     M(2, 0) = sx;
  397.     M(2, 1) = sy;
  398.     M(2, 2) = BR_SCALAR(1.f);
  399.     M(2, 3) = BR_SCALAR(0.f);
  400.     M(3, 0) = BR_SCALAR(0.f);
  401.     M(3, 1) = BR_SCALAR(0.f);
  402.     M(3, 2) = BR_SCALAR(0.f);
  403.     M(3, 3) = BR_SCALAR(1.f);
  404. }
  405.