Cone.h 2.1 KB

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