Cone.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #pragma once
  6. #include <AnKi/Collision/Common.h>
  7. namespace anki {
  8. /// @addtogroup collision
  9. /// @{
  10. /// Cone collision shape.
  11. class Cone
  12. {
  13. public:
  14. static constexpr CollisionShapeType kClassType = CollisionShapeType::kCone;
  15. /// Will not initialize any memory, nothing.
  16. Cone()
  17. {
  18. }
  19. Cone(const Vec4& origin, const Vec4& dir, F32 length, F32 angle)
  20. : m_origin(origin)
  21. , m_dir(dir)
  22. , m_length(length)
  23. , m_angle(angle)
  24. {
  25. check();
  26. }
  27. /// Copy.
  28. Cone(const Cone& b)
  29. {
  30. operator=(b);
  31. }
  32. /// Copy.
  33. Cone& operator=(const Cone& b)
  34. {
  35. b.check();
  36. m_origin = b.m_origin;
  37. m_dir = b.m_dir;
  38. m_length = b.m_length;
  39. m_angle = b.m_angle;
  40. return *this;
  41. }
  42. void setOrigin(const Vec4& origin)
  43. {
  44. m_origin = origin;
  45. }
  46. const Vec4& getOrigin() const
  47. {
  48. check();
  49. return m_origin;
  50. }
  51. void setDirection(const Vec4& dir)
  52. {
  53. m_dir = dir;
  54. }
  55. const Vec4& getDirection() const
  56. {
  57. check();
  58. return m_dir;
  59. }
  60. void setLength(F32 len)
  61. {
  62. ANKI_ASSERT(len > kEpsilonf);
  63. m_length = len;
  64. }
  65. F32 getLength() const
  66. {
  67. check();
  68. return m_length;
  69. }
  70. void setAngle(F32 ang)
  71. {
  72. ANKI_ASSERT(ang > 0.0f && ang < 2.0f * kPi);
  73. m_angle = ang;
  74. }
  75. F32 getAngle() const
  76. {
  77. check();
  78. return m_angle;
  79. }
  80. Cone getTransformed(const Transform& transform) const
  81. {
  82. Cone out;
  83. out.m_origin = transform.transform(m_origin);
  84. out.m_dir = (transform.getRotation() * m_dir.xyz0).xyz0;
  85. ANKI_ASSERT(transform.hasUniformScale());
  86. out.m_length *= transform.getScale().x;
  87. return out;
  88. }
  89. private:
  90. Vec4 m_origin
  91. #if ANKI_ASSERTIONS_ENABLED
  92. = Vec4(kMaxF32)
  93. #endif
  94. ;
  95. Vec4 m_dir
  96. #if ANKI_ASSERTIONS_ENABLED
  97. = Vec4(kMaxF32)
  98. #endif
  99. ;
  100. F32 m_length
  101. #if ANKI_ASSERTIONS_ENABLED
  102. = -1.0f
  103. #endif
  104. ;
  105. F32 m_angle
  106. #if ANKI_ASSERTIONS_ENABLED
  107. = -1.0f
  108. #endif
  109. ;
  110. void check() const
  111. {
  112. ANKI_ASSERT(m_origin.w == 0.0f);
  113. ANKI_ASSERT(m_dir.w == 0.0f);
  114. ANKI_ASSERT(m_length > 0.0f);
  115. ANKI_ASSERT(m_angle > 0.0f && m_angle < 2.0f * kPi);
  116. }
  117. };
  118. /// @}
  119. } // end namespace anki