Cone.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #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 CLASS_TYPE = CollisionShapeType::CONE;
  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 > EPSILON);
  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 * PI);
  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. out.m_length *= transform.getScale();
  86. return out;
  87. }
  88. private:
  89. Vec4 m_origin
  90. #if ANKI_ENABLE_ASSERTIONS
  91. = Vec4(MAX_F32)
  92. #endif
  93. ;
  94. Vec4 m_dir
  95. #if ANKI_ENABLE_ASSERTIONS
  96. = Vec4(MAX_F32)
  97. #endif
  98. ;
  99. F32 m_length
  100. #if ANKI_ENABLE_ASSERTIONS
  101. = -1.0f
  102. #endif
  103. ;
  104. F32 m_angle
  105. #if ANKI_ENABLE_ASSERTIONS
  106. = -1.0f
  107. #endif
  108. ;
  109. void check() const
  110. {
  111. ANKI_ASSERT(m_origin.w() == 0.0f);
  112. ANKI_ASSERT(m_dir.w() == 0.0f);
  113. ANKI_ASSERT(m_length > 0.0f);
  114. ANKI_ASSERT(m_angle > 0.0f && m_angle < 2.0f * PI);
  115. }
  116. };
  117. /// @}
  118. } // end namespace anki