1 #ifndef RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
2 #define RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
4 #ifndef RAYLIB_CPP_NO_MATH
8 #include "./raylib.hpp"
9 #include "./raymath.hpp"
10 #include "./raylib-cpp-utils.hpp"
24 GETTERSETTER(
float, X, x)
25 GETTERSETTER(
float, Y, y)
47 return !(*
this == other);
50 #ifndef RAYLIB_CPP_NO_MATH
55 return Vector2Add(*
this, vector2);
62 return Vector2Add(*
this, vector2);
69 set(Vector2Add(*
this, vector2));
78 return Vector2Subtract(*
this, vector2);
85 return Vector2Subtract(*
this, vector2);
92 set(Vector2Subtract(*
this, vector2));
101 return Vector2Negate(*
this);
108 return Vector2Negate(*
this);
115 return Vector2Multiply(*
this, vector2);
122 return Vector2Multiply(*
this, vector2);
129 set(Vector2Multiply(*
this, vector2));
138 return Vector2Scale(*
this, scale);
145 return Vector2Scale(*
this, scale);
152 set(Vector2Scale(*
this, scale));
161 return Vector2Divide(*
this, vector2);
168 return Vector2Divide(*
this, vector2);
175 set(Vector2Divide(*
this, vector2));
184 return ::Vector2{x / div, y / div};
208 return Vector2Length(*
this);
215 return Vector2LengthSqr(*
this);
222 return Vector2Normalize(*
this);
229 return Vector2DotProduct(*
this, vector2);
235 inline float Angle(const ::Vector2& vector2)
const {
236 return Vector2Angle(*
this, vector2);
242 inline float Distance(const ::Vector2& vector2)
const {
243 return Vector2Distance(*
this, vector2);
249 inline Vector2 Lerp(const ::Vector2& vector2,
float amount)
const {
250 return Vector2Lerp(*
this, vector2, amount);
257 return Vector2Reflect(*
this, normal);
264 return Vector2Rotate(*
this, degrees);
271 return Vector2MoveTowards(*
this, target, maxDistance);
278 return Vector2Zero();
289 inline void DrawPixel(::
Color color = {0, 0, 0, 255})
const {
290 ::DrawPixelV(*
this, color);
293 inline void DrawLine(::Vector2 endPos, ::Color color = {0, 0, 0, 255})
const {
294 ::DrawLineV(*
this, endPos, color);
297 inline void DrawLine(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255})
const {
298 ::DrawLineEx(*
this, endPos, thick, color);
301 inline void DrawLineBezier(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255})
const {
302 ::DrawLineBezier(*
this, endPos, thick, color);
312 ::
Color color = {0, 0, 0, 255})
const {
320 ::DrawCircleV(*
this, radius, color);
323 inline void DrawRectangle(::Vector2 size, ::Color color = {0, 0, 0, 255})
const {
324 ::DrawRectangleV(*
this, size, color);
327 inline void DrawPoly(
int sides,
float radius,
float rotation, ::Color color = {0, 0, 0, 255})
const {
328 ::DrawPoly(*
this, sides, radius, rotation, color);
335 return ::CheckCollisionCircles(*
this, radius1, center2, radius2);
342 return ::CheckCollisionCircleRec(*
this, radius, rec);
349 return ::CheckCollisionPointRec(*
this, rec);
356 return ::CheckCollisionPointCircle(*
this, center, radius);
363 return ::CheckCollisionPointTriangle(*
this, p1, p2, p3);
372 ::
Vector2 *collisionPoint)
const {
373 return ::CheckCollisionLines(*
this, endPos1, startPos2, endPos2, collisionPoint);
380 return ::CheckCollisionPointLine(*
this, p1, p2, threshold);
384 void set(const ::Vector2& vec) {
bool CheckCollision(::Vector2 p1, ::Vector2 p2, ::Vector2 p3) const
Check if point is inside a triangle.
Vector2 MoveTowards(const ::Vector2 &target, float maxDistance) const
Move Vector towards target.
bool CheckCollisionPointLine(::Vector2 p1, ::Vector2 p2, int threshold=1)
Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels...
Vector2 Subtract(const ::Vector2 &vector2) const
Subtract two vectors (v1 - v2)
Vector2 operator*(const float scale) const
Scale vector (multiply by value)
bool CheckCollision(::Rectangle rec) const
Check if point is inside rectangle.
Vector2 & operator*=(const float scale)
Scale vector (multiply by value)
Vector2 Lerp(const ::Vector2 &vector2, float amount) const
Calculate linear interpolation between two vectors.
float Length() const
Calculate vector length.
float DotProduct(const ::Vector2 &vector2) const
Calculate two vectors dot product.
Vector2 Rotate(float degrees) const
Rotate Vector by float in Degrees.
float LengthSqr() const
Calculate vector square length.
Vector2 & operator*=(const ::Vector2 &vector2)
Multiply vector by vector.
Vector2 & operator-=(const ::Vector2 &vector2)
Add two vectors (v1 + v2)
float Distance(const ::Vector2 &vector2) const
Calculate distance between two vectors.
bool CheckCollision(::Vector2 center, float radius) const
Check if point is inside circle.
Vector2 Divide(const ::Vector2 &vector2) const
Divide vector by vector.
bool CheckCollisionCircle(float radius, ::Rectangle rec) const
Check collision between circle and rectangle.
static Vector2 Zero()
Vector with components value 0.0f.
void DrawCircle(float radius, ::Color color={0, 0, 0, 255}) const
Draw a color-filled circle (Vector version)
bool CheckCollisionCircle(float radius1, ::Vector2 center2, float radius2) const
Check collision between two circles.
Vector2 Reflect(const ::Vector2 &normal) const
Calculate reflected vector to normal.
Vector2 & operator/=(const float div)
Divide vector by value.
Vector2 Multiply(const ::Vector2 &vector2) const
Multiply vector by vector.
Vector2 operator+(const ::Vector2 &vector2) const
Add two vectors (v1 + v2)
Vector2 operator/(const ::Vector2 &vector2) const
Divide vector by vector.
bool operator==(const ::Vector2 &other)
Determine whether or not the vectors are equal.
Vector2 & operator/=(const ::Vector2 &vector2)
Divide vector by vector.
Vector2 Negate() const
Negate vector.
Vector2 Scale(const float scale) const
Scale vector (multiply by value)
Vector2 Add(const ::Vector2 &vector2) const
Add two vectors (v1 + v2)
Vector2 operator*(const ::Vector2 &vector2) const
Multiply vector by vector.
Vector2 operator/(const float div) const
Divide vector by value.
Vector2 & operator+=(const ::Vector2 &vector2)
Add two vectors (v1 + v2)
bool CheckCollisionLines(::Vector2 endPos1, ::Vector2 startPos2, ::Vector2 endPos2, ::Vector2 *collisionPoint) const
Check the collision between two lines defined by two points each, returns collision point by referenc...
static Vector2 One()
Vector with components value 1.0f.
bool operator!=(const ::Vector2 &other)
Determines if the vectors are not equal.
Vector2 Normalize() const
Normalize provided vector.
Vector2 operator-() const
Negate vector.
Vector2 operator-(const ::Vector2 &vector2) const
Subtract two vectors (v1 - v2)
float Angle(const ::Vector2 &vector2) const
Calculate angle from two vectors in X-axis.
void DrawLineBezierQuad(::Vector2 endPos, ::Vector2 controlPos, float thick, ::Color color={0, 0, 0, 255}) const
Draw line using quadratic bezier curves with a control point.
Vector2 Divide(const float div) const
Divide vector by value.
All raylib-cpp classes and functions appear in the raylib namespace.