diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Geometry/Ray2D.h |
Diffstat (limited to 'Runtime/Geometry/Ray2D.h')
-rw-r--r-- | Runtime/Geometry/Ray2D.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Runtime/Geometry/Ray2D.h b/Runtime/Geometry/Ray2D.h new file mode 100644 index 0000000..7adff8e --- /dev/null +++ b/Runtime/Geometry/Ray2D.h @@ -0,0 +1,32 @@ +#ifndef RAY2D_H +#define RAY2D_H + +#include "Runtime/Math/Vector2.h" + + +// -------------------------------------------------------------------------- + + +class Ray2D +{ +#if UNITY_FLASH //flash needs to be able to set these fields +public: +#endif + Vector2f m_Origin; + Vector2f m_Direction; // Direction is always normalized + +public: + Ray2D () {} + Ray2D (const Vector2f& origin, const Vector2f& direction) { m_Origin = origin; SetDirection (direction); } + + const Vector2f& GetOrigin ()const { return m_Origin; } + void SetOrigin (const Vector2f& origin) { m_Origin = origin; } + + const Vector2f& GetDirection () const { return m_Direction; } + void SetDirection (const Vector2f& direction) { AssertIf (!IsNormalized (direction)); m_Direction = direction; } + void SetApproxDirection (const Vector2f& direction) { m_Direction = NormalizeFast (direction); } + + Vector2f GetPoint (const float scale) const { return m_Origin + (scale * m_Direction); } +}; + +#endif |