ConvexHullShape.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Collision/ConvexHullShape.h>
  6. #include <AnKi/Util/Functions.h>
  7. namespace anki {
  8. ConvexHullShape ConvexHullShape::getTransformed(const Transform& trf) const
  9. {
  10. check();
  11. ConvexHullShape out = *this;
  12. out.m_trf = m_trf.combineTransformations(trf);
  13. out.m_invTrf = m_trf.invert();
  14. out.m_trfIdentity = false;
  15. return out;
  16. }
  17. void ConvexHullShape::setTransform(const Transform& trf)
  18. {
  19. m_trf = trf;
  20. m_invTrf = m_trf.invert();
  21. m_trfIdentity = false;
  22. }
  23. Vec4 ConvexHullShape::computeSupport(const Vec4& dir) const
  24. {
  25. check();
  26. F32 m = kMinF32;
  27. U index = 0;
  28. const Vec4 d = (m_trfIdentity) ? dir : (m_invTrf.getRotation() * dir).xyz0();
  29. const Vec4* points = m_points;
  30. const Vec4* end = m_points + m_pointCount;
  31. U i = 0;
  32. for(; points != end; ++points, ++i)
  33. {
  34. const F32 dot = points->dot(d);
  35. if(dot > m)
  36. {
  37. m = dot;
  38. index = i;
  39. }
  40. }
  41. return (m_trfIdentity) ? m_points[index] : m_trf.transform(m_points[index]);
  42. }
  43. } // end namespace anki