5 #include "Bullet3Common/shared/b3Quat.h"
9 #include "Bullet3Common/b3Matrix3x3.h"
11 #define b3Mat3x3 b3Matrix3x3
12 #define b3Mat3x3ConstArg const b3Matrix3x3&
14 inline b3Mat3x3 b3QuatGetRotationMatrix(b3QuatConstArg quat)
16 return b3Mat3x3(quat);
19 inline b3Mat3x3 b3AbsoluteMat3x3(b3Mat3x3ConstArg mat)
21 return mat.absolute();
24 #define b3GetRow(m, row) m.getRow(row)
26 __inline b3Float4 mtMul3(b3Float4ConstArg a, b3Mat3x3ConstArg b)
38 #define b3Mat3x3ConstArg const b3Mat3x3
39 #define b3GetRow(m, row) (m.m_row[row])
41 inline b3Mat3x3 b3QuatGetRotationMatrix(b3Quat quat)
43 b3Float4 quat2 = (b3Float4)(quat.x * quat.x, quat.y * quat.y, quat.z * quat.z, 0.f);
46 out.m_row[0].x = 1 - 2 * quat2.y - 2 * quat2.z;
47 out.m_row[0].y = 2 * quat.x * quat.y - 2 * quat.w * quat.z;
48 out.m_row[0].z = 2 * quat.x * quat.z + 2 * quat.w * quat.y;
51 out.m_row[1].x = 2 * quat.x * quat.y + 2 * quat.w * quat.z;
52 out.m_row[1].y = 1 - 2 * quat2.x - 2 * quat2.z;
53 out.m_row[1].z = 2 * quat.y * quat.z - 2 * quat.w * quat.x;
56 out.m_row[2].x = 2 * quat.x * quat.z - 2 * quat.w * quat.y;
57 out.m_row[2].y = 2 * quat.y * quat.z + 2 * quat.w * quat.x;
58 out.m_row[2].z = 1 - 2 * quat2.x - 2 * quat2.y;
64 inline b3Mat3x3 b3AbsoluteMat3x3(b3Mat3x3ConstArg matIn)
67 out.m_row[0] = fabs(matIn.m_row[0]);
68 out.m_row[1] = fabs(matIn.m_row[1]);
69 out.m_row[2] = fabs(matIn.m_row[2]);
73 __inline b3Mat3x3 mtZero();
75 __inline b3Mat3x3 mtIdentity();
77 __inline b3Mat3x3 mtTranspose(b3Mat3x3 m);
79 __inline b3Mat3x3 mtMul(b3Mat3x3 a, b3Mat3x3 b);
81 __inline b3Float4 mtMul1(b3Mat3x3 a, b3Float4 b);
83 __inline b3Float4 mtMul3(b3Float4 a, b3Mat3x3 b);
85 __inline b3Mat3x3 mtZero()
88 m.m_row[0] = (b3Float4)(0.f);
89 m.m_row[1] = (b3Float4)(0.f);
90 m.m_row[2] = (b3Float4)(0.f);
94 __inline b3Mat3x3 mtIdentity()
97 m.m_row[0] = (b3Float4)(1, 0, 0, 0);
98 m.m_row[1] = (b3Float4)(0, 1, 0, 0);
99 m.m_row[2] = (b3Float4)(0, 0, 1, 0);
103 __inline b3Mat3x3 mtTranspose(b3Mat3x3 m)
106 out.m_row[0] = (b3Float4)(m.m_row[0].x, m.m_row[1].x, m.m_row[2].x, 0.f);
107 out.m_row[1] = (b3Float4)(m.m_row[0].y, m.m_row[1].y, m.m_row[2].y, 0.f);
108 out.m_row[2] = (b3Float4)(m.m_row[0].z, m.m_row[1].z, m.m_row[2].z, 0.f);
112 __inline b3Mat3x3 mtMul(b3Mat3x3 a, b3Mat3x3 b)
115 transB = mtTranspose(b);
117 // why this doesn't run when 0ing in the for{}
121 for (int i = 0; i < 3; i++)
123 // a.m_row[i].w = 0.f;
124 ans.m_row[i].x = b3Dot3F4(a.m_row[i], transB.m_row[0]);
125 ans.m_row[i].y = b3Dot3F4(a.m_row[i], transB.m_row[1]);
126 ans.m_row[i].z = b3Dot3F4(a.m_row[i], transB.m_row[2]);
127 ans.m_row[i].w = 0.f;
132 __inline b3Float4 mtMul1(b3Mat3x3 a, b3Float4 b)
135 ans.x = b3Dot3F4(a.m_row[0], b);
136 ans.y = b3Dot3F4(a.m_row[1], b);
137 ans.z = b3Dot3F4(a.m_row[2], b);
142 __inline b3Float4 mtMul3(b3Float4 a, b3Mat3x3 b)
144 b3Float4 colx = b3MakeFloat4(b.m_row[0].x, b.m_row[1].x, b.m_row[2].x, 0);
145 b3Float4 coly = b3MakeFloat4(b.m_row[0].y, b.m_row[1].y, b.m_row[2].y, 0);
146 b3Float4 colz = b3MakeFloat4(b.m_row[0].z, b.m_row[1].z, b.m_row[2].z, 0);
149 ans.x = b3Dot3F4(a, colx);
150 ans.y = b3Dot3F4(a, coly);
151 ans.z = b3Dot3F4(a, colz);