ConvexHullShape.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2009-2021, 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. {
  9. ConvexHullShape ConvexHullShape::getTransformed(const Transform& trf) const
  10. {
  11. check();
  12. ConvexHullShape out = *this;
  13. out.m_trf = m_trf.combineTransformations(trf);
  14. out.m_invTrf = m_trf.getInverse();
  15. out.m_trfIdentity = false;
  16. return out;
  17. }
  18. void ConvexHullShape::setTransform(const Transform& trf)
  19. {
  20. m_trf = trf;
  21. m_invTrf = m_trf.getInverse();
  22. m_trfIdentity = false;
  23. }
  24. Vec4 ConvexHullShape::computeSupport(const Vec4& dir) const
  25. {
  26. check();
  27. F32 m = MIN_F32;
  28. U index = 0;
  29. const Vec4 d = (m_trfIdentity) ? dir : (m_invTrf.getRotation() * dir).xyz0();
  30. const Vec4* points = m_points;
  31. const Vec4* end = m_points + m_pointCount;
  32. U i = 0;
  33. for(; points != end; ++points, ++i)
  34. {
  35. const F32 dot = points->dot(d);
  36. if(dot > m)
  37. {
  38. m = dot;
  39. index = i;
  40. }
  41. }
  42. return (m_trfIdentity) ? m_points[index] : m_trf.transform(m_points[index]);
  43. }
  44. } // end namespace anki