|
ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
|
A 2D vector in space. More...
#include <geometry.h>
Public Types | |
| using | Real = std::conditional_t<std::is_floating_point_v<T>, T, float> |
| Type used for lengths and angles. Integer vectors use float so results are not truncated. | |
Public Member Functions | |
| Vec2 ()=default | |
| Default constructor for the Vec2 class. | |
| Vec2 (T x, T y) | |
| Constructor for the Vec2 class. | |
| Real | angle (const Vec2 &other) const |
| Get angle of two vectors. | |
| Real | angle () const |
| Calculate the angle of the vector. | |
| Real | distance (const Vec2 &other) const |
| Get distance between two vectors. | |
| Real | distance_to_segment (const Vec2 &start, const Vec2 &end) const |
| Get the distance from this point to the nearest point on a line segment. Useful for beams, lasers and swept hit checks. | |
| T | dot (const Vec2 &other) const |
| Calculate the dot product of two vectors. | |
| T | cross (const Vec2 &other) const |
| Calculate the cross product of two vectors. | |
| Real | magnitude () const |
| Calculate the magnitude of the vector. | |
| Vec2 | normalized () const |
| Get a vector with the same direction and a length of one. | |
| Vec2 | operator+ (const Vec2 &other) const |
| Addition operator for the Vec2 class. | |
| Vec2 | operator- (const Vec2 &other) const |
| Subtraction operator for the Vec2 class. | |
| Vec2 | operator* (const T scalar) const |
| Multiplication operator for the Vec2 class. | |
| Vec2 | operator/ (const T scalar) const |
| Division operator for the Vec2 class. | |
| Vec2 | operator% (const T scalar) const |
| Modulo the Vec2 object by a scalar. | |
| Vec2 & | operator+= (const Vec2 &other) |
| Addition assignment operator for the Vec2 class. | |
| Vec2 & | operator-= (const Vec2 &other) |
| Subtraction assignment operator for the Vec2 class. | |
| Vec2 & | operator*= (const T scalar) |
| Multiplication assignment operator for the Vec2 class. | |
| Vec2 & | operator/= (const T scalar) |
| Division assignment operator for the Vec2 class. | |
| Vec2 & | operator%= (const T scalar) |
| Modulo assignment operator for the Vec2 class. | |
| bool | operator== (const Vec2 &other) const =default |
| Equality operator for the Vec2 class. | |
Static Public Member Functions | |
| static Vec2 | from_angle (T angle, T length=T(1)) |
| Create a vector pointing at an angle. | |
Public Attributes | |
| T | x { 0 } |
| The x component of the vector. | |
| T | y { 0 } |
| The y component of the vector. | |
A 2D vector in space.
This class represents a 2D vector in space. It is used to represent points, directions, and sizes.
Definition at line 27 of file geometry.h.
| using asw::Vec2< T >::Real = std::conditional_t<std::is_floating_point_v<T>, T, float> |
Type used for lengths and angles. Integer vectors use float so results are not truncated.
Definition at line 31 of file geometry.h.
|
inline |
Constructor for the Vec2 class.
| x | The x component of the vector. |
| y | The y component of the vector. |
Definition at line 42 of file geometry.h.
Calculate the angle of the vector.
Definition at line 61 of file geometry.h.
Get angle of two vectors.
Definition at line 52 of file geometry.h.
Calculate the cross product of two vectors.
| other | The vector to cross with. |
Definition at line 129 of file geometry.h.
Get distance between two vectors.
Definition at line 86 of file geometry.h.
|
inline |
Get the distance from this point to the nearest point on a line segment. Useful for beams, lasers and swept hit checks.
| start | One end of the segment. |
| end | The other end of the segment. |
start if both ends are the same point. Definition at line 99 of file geometry.h.
Calculate the dot product of two vectors.
| other | The vector to dot with. |
Definition at line 119 of file geometry.h.
|
inlinestatic |
Create a vector pointing at an angle.
| angle | The angle in radians, clockwise from the positive x axis like the rest of asw. |
| length | The length of the vector. |
Definition at line 76 of file geometry.h.
Calculate the magnitude of the vector.
Definition at line 138 of file geometry.h.
Get a vector with the same direction and a length of one.
Definition at line 148 of file geometry.h.
Modulo the Vec2 object by a scalar.
| scalar | The scalar to modulo by |
Definition at line 204 of file geometry.h.
Modulo assignment operator for the Vec2 class.
| scalar | The scalar to modulo by. |
Definition at line 262 of file geometry.h.
Multiplication operator for the Vec2 class.
| scalar | The scalar to multiply by. |
Definition at line 184 of file geometry.h.
Multiplication assignment operator for the Vec2 class.
| scalar | The scalar to multiply by. |
Definition at line 238 of file geometry.h.
Addition operator for the Vec2 class.
| other | The vector to add. |
Definition at line 164 of file geometry.h.
Addition assignment operator for the Vec2 class.
| other | The vector to add. |
Definition at line 214 of file geometry.h.
Subtraction operator for the Vec2 class.
| other | The vector to subtract. |
Definition at line 174 of file geometry.h.
Subtraction assignment operator for the Vec2 class.
| other | The vector to subtract. |
Definition at line 226 of file geometry.h.
Division operator for the Vec2 class.
| scalar | The scalar to divide by. |
Definition at line 194 of file geometry.h.
Division assignment operator for the Vec2 class.
| scalar | The scalar to divide by. |
Definition at line 250 of file geometry.h.
Equality operator for the Vec2 class.
| other | The vector to compare. |
| T asw::Vec2< T >::x { 0 } |
The x component of the vector.
Definition at line 277 of file geometry.h.
| T asw::Vec2< T >::y { 0 } |
The y component of the vector.
Definition at line 280 of file geometry.h.