| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <AnKi/Collision/Common.h>
- #include <AnKi/Math.h>
- namespace anki {
- /// @addtogroup collision
- /// @{
- /// Line segment. Line from a point to a point. P0 = origin and P1 = direction + origin
- class LineSegment
- {
- public:
- static constexpr CollisionShapeType kClassType = CollisionShapeType::kLineSegment;
- /// Will not initialize any memory, nothing.
- LineSegment()
- {
- }
- LineSegment(const Vec4& origin, const Vec4& direction)
- : m_origin(origin)
- , m_dir(direction)
- {
- check();
- }
- LineSegment(const LineSegment& b)
- {
- operator=(b);
- }
- LineSegment& operator=(const LineSegment& b)
- {
- b.check();
- m_origin = b.m_origin;
- m_dir = b.m_dir;
- return *this;
- }
- const Vec4& getOrigin() const
- {
- check();
- return m_origin;
- }
- void setOrigin(const Vec4& origin)
- {
- m_origin = origin;
- }
- const Vec4& getDirection() const
- {
- check();
- return m_dir;
- }
- void setDirection(const Vec4& dir)
- {
- m_dir = dir;
- }
- LineSegment getTransformed(const Transform& trf) const
- {
- check();
- LineSegment out;
- out.m_origin = trf.transform(m_origin);
- out.m_dir = Vec4(trf.getRotation() * (m_dir * trf.getScale()), 0.0f);
- return out;
- }
- private:
- Vec4 m_origin ///< P0
- #if ANKI_ASSERTIONS_ENABLED
- = Vec4(kMaxF32)
- #endif
- ;
- Vec4 m_dir ///< P1 = origin+dir so dir = P1-origin
- #if ANKI_ASSERTIONS_ENABLED
- = Vec4(kMaxF32)
- #endif
- ;
- void check() const
- {
- ANKI_ASSERT(m_origin.w != 0.0f && m_dir.w != 0.0f);
- }
- };
- /// @}
- } // end namespace anki
|