1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "Prerequisites/BsPrerequisitesUtil.h" |
6 | #include "Math/BsVector2.h" |
7 | |
8 | namespace bs |
9 | { |
10 | /** @addtogroup Math |
11 | * @{ |
12 | */ |
13 | |
14 | /** A line in 2D space represented with an origin and direction. */ |
15 | class BS_UTILITY_EXPORT Line2 |
16 | { |
17 | public: |
18 | Line2() = default; |
19 | |
20 | Line2(const Vector2& origin, const Vector2& direction) |
21 | :mOrigin(origin), mDirection(direction) |
22 | { } |
23 | |
24 | void setOrigin(const Vector2& origin) { mOrigin = origin; } |
25 | const Vector2& getOrigin(void) const { return mOrigin; } |
26 | |
27 | void setDirection(const Vector2& dir) { mDirection = dir; } |
28 | const Vector2& getDirection(void) const {return mDirection;} |
29 | |
30 | /** Gets the position of a point t units along the line. */ |
31 | Vector2 getPoint(float t) const |
32 | { |
33 | return Vector2(mOrigin + (mDirection * t)); |
34 | } |
35 | |
36 | /** Gets the position of a point t units along the line. */ |
37 | Vector2 operator*(float t) const |
38 | { |
39 | return getPoint(t); |
40 | } |
41 | |
42 | /** Line/Line intersection, returns boolean result and distance to intersection point. */ |
43 | std::pair<bool, float> intersects(const Line2& line) const; |
44 | |
45 | protected: |
46 | Vector2 mOrigin = Vector2::ZERO; |
47 | Vector2 mDirection = Vector2::UNIT_X; |
48 | }; |
49 | |
50 | /** @} */ |
51 | } |
52 | |