258 topRight = topRight_;
259 bottomLeft = bottomLeft_;
278 const PxVec3 angular = topLeft * s.angular + topRight * s.linear;
286 const PxVec3 top = topLeft * s.top + topRight * s.bottom;
294 const PxVec3 top = topLeft * s.top + topRight * s.bottom;
303 const PxMat33 newTopLeft = topLeft * s;
304 const PxMat33 newTopRight = topRight * s;
305 const PxMat33 newBottomLeft = bottomLeft * s;
307 return SpatialMatrix(newTopLeft, newTopRight, newBottomLeft);
312 const PxMat33 newTopLeft = topLeft - s.topLeft;
313 const PxMat33 newTopRight = topRight - s.topRight;
314 const PxMat33 newBottomLeft = bottomLeft - s.bottomLeft;
316 return SpatialMatrix(newTopLeft, newTopRight, newBottomLeft);
321 const PxMat33 newTopLeft = topLeft + s.topLeft;
322 const PxMat33 newTopRight = topRight + s.topRight;
323 const PxMat33 newBottomLeft = bottomLeft + s.bottomLeft;
325 return SpatialMatrix(newTopLeft, newTopRight, newBottomLeft);
330 const PxMat33 newTopLeft = -topLeft;
331 const PxMat33 newTopRight = -topRight;
332 const PxMat33 newBottomLeft = -bottomLeft;
334 return SpatialMatrix(newTopLeft, newTopRight, newBottomLeft);
339 topLeft += s.topLeft;
340 topRight += s.topRight;
341 bottomLeft += s.bottomLeft;
346 const PxMat33 sBottomRight = s.topLeft.getTranspose();
349 const PxMat33 newTopLeft = topLeft * s.topLeft + topRight * s.bottomLeft;
350 const PxMat33 newTopRight = topLeft * s.topRight + topRight * sBottomRight;
351 const PxMat33 newBottomLeft = bottomLeft * s.topLeft + bottomRight * s.bottomLeft;
353 return SpatialMatrix(newTopLeft, newTopRight, newBottomLeft);
359 const PxVec3 tLeftC0 = Is.angular * stI.angular.x;
360 const PxVec3 tLeftC1 = Is.angular * stI.angular.y;
361 const PxVec3 tLeftC2 = Is.angular * stI.angular.z;
363 const PxMat33 topLeft(tLeftC0, tLeftC1, tLeftC2);
366 const PxVec3 tRightC0 = Is.angular * stI.linear.x;
367 const PxVec3 tRightC1 = Is.angular * stI.linear.y;
368 const PxVec3 tRightC2 = Is.angular * stI.linear.z;
369 const PxMat33 topRight(tRightC0, tRightC1, tRightC2);
372 const PxVec3 bLeftC0 = Is.linear * stI.angular.x;
373 const PxVec3 bLeftC1 = Is.linear * stI.angular.y;
374 const PxVec3 bLeftC2 = Is.linear * stI.angular.z;
375 const PxMat33 bottomLeft(bLeftC0, bLeftC1, bLeftC2);
383 const PxVec3 tLeftC0 = Is.top * stI.top.x;
384 const PxVec3 tLeftC1 = Is.top * stI.top.y;
385 const PxVec3 tLeftC2 = Is.top * stI.top.z;
387 const PxMat33 topLeft(tLeftC0, tLeftC1, tLeftC2);
390 const PxVec3 tRightC0 = Is.top * stI.bottom.x;
391 const PxVec3 tRightC1 = Is.top * stI.bottom.y;
392 const PxVec3 tRightC2 = Is.top * stI.bottom.z;
393 const PxMat33 topRight(tRightC0, tRightC1, tRightC2);
396 const PxVec3 bLeftC0 = Is.bottom * stI.top.x;
397 const PxVec3 bLeftC1 = Is.bottom * stI.top.y;
398 const PxVec3 bLeftC2 = Is.bottom * stI.top.z;
399 const PxMat33 bottomLeft(bLeftC0, bLeftC1, bLeftC2);
404 template <
typename SpatialVector>
407 const PxMat33 topLeft(columns[0].top, columns[1].top, columns[2].top);
408 const PxMat33 bottomLeft(columns[0].bottom, columns[1].bottom, columns[2].bottom);
409 const PxMat33 topRight(columns[3].top, columns[4].top, columns[5].top);
421 return SpatialMatrix(newTopLeft, newTopRight, newBottomLeft);
442 const PxReal eps = 0.00001f;
443 const float x =
PxAbs(1.f - matrix.column0.x);
444 const float y =
PxAbs(1.f - matrix.column1.y);
445 const float z =
PxAbs(1.f - matrix.column2.z);
446 const bool identity = ((x < eps) &&
PxAbs(matrix.column0.y - 0.f) < eps &&
PxAbs(matrix.column0.z - 0.f) < eps) &&
447 (
PxAbs(matrix.column1.x - 0.f) < eps && (y < eps) &&
PxAbs(matrix.column1.z - 0.f) < eps) &&
448 (
PxAbs(matrix.column2.x - 0.f) < eps &&
PxAbs(matrix.column2.y - 0.f) < eps && (z < eps));
455 const PxReal eps = 0.0001f;
456 for (PxU32 i = 0; i < 3; ++i)
458 for (PxU32 j = 0; j < 3; ++j)
460 if (
PxAbs(matrix[i][j]) > eps)
470 const bool topLeftIsIdentity = isIdentity(topLeft);
472 const bool topRightIsZero = isZero(topRight);
474 const bool bottomLeftIsZero = isZero(bottomLeft);
476 return topLeftIsIdentity && topRightIsZero && bottomLeftIsZero;
481 const PxReal eps = 0.00001f;
482 for (PxU32 i = 0; i < 3; ++i)
484 for (PxU32 j = 0; j < 3; ++j)
486 const PxReal t = s0[i][j] - s1[i][j];
497 const bool topLeftEqual = isEqual(topLeft, s.topLeft);
498 const bool topRightEqual = isEqual(topRight, s.topRight);
499 const bool bottomLeftEqual = isEqual(bottomLeft, s.bottomLeft);
501 return topLeftEqual && topRightEqual && bottomLeftEqual;
506 const PxVec3 v0 = in[1].cross(in[2]);
507 const PxVec3 v1 = in[2].cross(in[0]);
508 const PxVec3 v2 = in[0].cross(in[1]);
510 const PxReal det = v0.
dot(in[0]);
514 const PxReal recipDet = 1.0f / det;
517 PxVec3(v0.y, v1.y, v1.z) * recipDet,
518 PxVec3(v0.z, v1.z, v2.z) * recipDet);
529 const Vec3V v0 = V3Cross(in.col1, in.col2);
530 const Vec3V v1 = V3Cross(in.col2, in.col0);
531 const Vec3V v2 = V3Cross(in.col0, in.col1);
533 const FloatV det = V3Dot(v0, in.col0);
535 const FloatV recipDet = FRecip(det);
537 if (!FAllEq(det, FZero()))
539 return Mat33V(V3Scale(v0, recipDet),
540 V3Scale(V3Merge(V3GetY(v0), V3GetY(v1), V3GetZ(v1)), recipDet),
541 V3Scale(V3Merge(V3GetZ(v0), V3GetZ(v1), V3GetZ(v2)), recipDet));
545 return Mat33V(V3UnitX(), V3UnitY(), V3UnitZ());
553 PxMat33 aa = bottomLeft, ll = topRight, la = topLeft;
556 ll = (ll + ll.getTranspose())*0.5f;
558 const PxMat33 AAInv = invertSym33(aa);
561 const PxMat33 S = ll + z * la.getTranspose();
563 const PxMat33 LL = invertSym33(S);
566 const PxMat33 AA = AAInv + z.getTranspose() * LA;
575 aos::V3StoreU(src.col0, dest.column0);
576 aos::V3StoreU(src.col1, dest.column1);
577 aos::V3StoreU(src.col2, dest.column2);
583 Mat33V aa = M33Load(bottomLeft), ll = M33Load(topRight), la = M33Load(topLeft);
585 aa = M33Scale(M33Add(aa, M33Trnsps(aa)), FHalf());
586 ll = M33Scale(M33Add(ll, M33Trnsps(ll)), FHalf());
588 const Mat33V AAInv = invertSym33(aa);
590 const Mat33V z = M33MulM33(M33Neg(la), AAInv);
591 const Mat33V S = M33Add(ll, M33MulM33(z, M33Trnsps(la)));
593 const Mat33V LL = invertSym33(S);
595 const Mat33V LA = M33MulM33(LL, z);
596 const Mat33V AA = M33Add(AAInv, M33MulM33(M33Trnsps(z), LA));
598 M33Store(M33Trnsps(LA), result.topLeft);
599 M33Store(AA, result.topRight);
600 M33Store(LL, result.bottomLeft);
608 const PxMat33 lComp0 = blInverse * (-bottomRight);
609 const PxMat33 lComp1 = topLeft * lComp0 + topRight;
613 const PxMat33 newTopLeft = lComp0 * newBottomLeft;
616 const PxMat33 rComp0 = trInverse * (-topLeft);
617 const PxMat33 rComp1 = bottomLeft + bottomRight * rComp0;
621 return SpatialMatrix(newTopLeft, newTopRight, newBottomLeft);
799 constructColumn(column[0], spatialMatrix.topLeft.column0, spatialMatrix.bottomLeft.column0);
800 constructColumn(column[1], spatialMatrix.topLeft.column1, spatialMatrix.bottomLeft.column1);
801 constructColumn(column[2], spatialMatrix.topLeft.column2, spatialMatrix.bottomLeft.column2);
803 const PxMat33 bottomRight = spatialMatrix.getBottomRight();
804 constructColumn(column[3], spatialMatrix.topRight.column0, bottomRight.column0);
805 constructColumn(column[4], spatialMatrix.topRight.column1, bottomRight.column1);
806 constructColumn(column[5], spatialMatrix.topRight.column2, bottomRight.column2);
809 void constructColumn(
const PxU32 ind,
const PxReal*
const values)
811 for (PxU32 i = 0; i < 6; ++i)
813 column[ind][i] = values[i];
817 void constructColumn(PxReal* dest,
const PxVec3& top,
const PxVec3& bottom)
831 for (PxU32 i = 0; i < 6; ++i)
833 for (PxU32 j = 0; j < 6; ++j)
835 temp.column[i][j] = column[j][i];
845 st[0] = s.angular.x; st[1] = s.angular.y; st[2] = s.angular.z;
846 st[3] = s.linear.x; st[4] = s.linear.y; st[5] = s.linear.z;
849 for (PxU32 i = 0; i < 6; i++)
852 for (PxU32 j = 0; j < 6; ++j)
854 result[i] += tempMatrix.column[i][j] * st[j];
860 temp.angular.x = result[0]; temp.angular.y = result[1]; temp.angular.z = result[2];
861 temp.linear.x = result[3]; temp.linear.y = result[4]; temp.linear.z = result[5];
869 st[0] = s.top.x; st[1] = s.top.y; st[2] = s.top.z;
870 st[3] = s.bottom.x; st[4] = s.bottom.y; st[5] = s.bottom.z;
873 for (PxU32 i = 0; i < 6; ++i)
876 for (PxU32 j = 0; j < 6; ++j)
878 result[i] += column[j][i] * st[j];
883 temp.top.x = result[0]; temp.top.y = result[1]; temp.top.z = result[2];
884 temp.bottom.x = result[3]; temp.bottom.y = result[4]; temp.bottom.z = result[5];
891 for (PxU32 i = 0; i < 3; ++i)
893 PxReal* result = temp.column[i];
895 const PxReal* input = s.column[i];
897 for (PxU32 j = 0; j < 6; ++j)
900 for (PxU32 k = 0; k < 6; ++k)
902 result[j] += column[k][j] * input[k];
914 st[0] = s.angular.x; st[1] = s.angular.y; st[2] = s.angular.z;
915 st[3] = s.linear.x; st[4] = s.linear.y; st[5] = s.linear.z;
918 for (PxU32 i = 0; i < 6; ++i)
921 for (PxU32 j = 0; j < 6; j++)
923 result[i] += column[i][j] * st[j];
928 temp.angular.x = result[0]; temp.angular.y = result[1]; temp.angular.z = result[2];
929 temp.linear.x = result[3]; temp.linear.y = result[4]; temp.linear.z = result[5];
936 const PxReal eps = 0.00001f;
937 for (PxU32 i = 0; i < 6; ++i)
939 temp[0] = m[i].top.x; temp[1] = m[i].top.y; temp[2] = m[i].top.z;
940 temp[3] = m[i].bottom.x; temp[4] = m[i].bottom.y; temp[5] = m[i].bottom.z;
942 for (PxU32 j = 0; j < 6; ++j)
944 const PxReal dif = column[i][j] - temp[j];
945 if (
PxAbs(dif) > eps)