mPlaneTransformer.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "math/mPlaneTransformer.h"
  23. #include "math/mMathFn.h"
  24. void PlaneTransformer::set(const MatrixF& xform, const Point3F& scale)
  25. {
  26. mTransform = xform;
  27. mScale = scale;
  28. MatrixF scaleMat(true);
  29. F32* m = scaleMat;
  30. m[MatrixF::idx(0, 0)] = scale.x;
  31. m[MatrixF::idx(1, 1)] = scale.y;
  32. m[MatrixF::idx(2, 2)] = scale.z;
  33. mTransposeInverse = xform;
  34. mTransposeInverse.mul(scaleMat);
  35. mTransposeInverse.transpose();
  36. mTransposeInverse.inverse();
  37. }
  38. void PlaneTransformer::transform(const PlaneF& plane, PlaneF& result)
  39. {
  40. Point3F point = plane;
  41. point *= -plane.d;
  42. point.convolve(mScale);
  43. mTransform.mulP(point);
  44. Point3F normal = plane;
  45. mTransposeInverse.mulV(normal);
  46. result.set(point, normal);
  47. // mTransformPlane(mTransform, mScale, plane, &result);
  48. }
  49. void PlaneTransformer::setIdentity()
  50. {
  51. static struct MakeIdentity
  52. {
  53. PlaneTransformer transformer;
  54. MakeIdentity()
  55. {
  56. MatrixF defMat(true);
  57. Point3F defScale(1.0f, 1.0f, 1.0f);
  58. transformer.set(defMat, defScale);
  59. }
  60. } sMakeIdentity;
  61. *this = sMakeIdentity.transformer;
  62. }