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"
26 GETTERSETTER(
float, X, x)
27 GETTERSETTER(
float, Y, y)
49 return !(*
this == other);
52 #ifndef RAYLIB_CPP_NO_MATH
57 return Vector2Add(*
this, vector2);
64 return Vector2Add(*
this, vector2);
71 set(Vector2Add(*
this, vector2));
80 return Vector2Subtract(*
this, vector2);
87 return Vector2Subtract(*
this, vector2);
94 set(Vector2Subtract(*
this, vector2));
103 return Vector2Negate(*
this);
110 return Vector2Negate(*
this);
117 return Vector2Multiply(*
this, vector2);
124 return Vector2Multiply(*
this, vector2);
131 set(Vector2Multiply(*
this, vector2));
140 return Vector2Scale(*
this, scale);
147 return Vector2Scale(*
this, scale);
154 set(Vector2Scale(*
this, scale));
163 return Vector2Divide(*
this, vector2);
170 return Vector2Divide(*
this, vector2);
177 set(Vector2Divide(*
this, vector2));
186 return ::Vector2{x / div, y / div};
210 return Vector2Length(*
this);
217 return Vector2LengthSqr(*
this);
224 return Vector2Normalize(*
this);
231 return Vector2DotProduct(*
this, vector2);
237 inline float Angle(const ::Vector2& vector2)
const {
238 return Vector2Angle(*
this, vector2);
244 inline float Distance(const ::Vector2& vector2)
const {
245 return Vector2Distance(*
this, vector2);
251 inline Vector2 Lerp(const ::Vector2& vector2,
float amount)
const {
252 return Vector2Lerp(*
this, vector2, amount);
259 return Vector2Reflect(*
this, normal);
266 return Vector2Rotate(*
this, degrees);
273 return Vector2MoveTowards(*
this, target, maxDistance);
280 return Vector2Zero();
291 inline Vector2& DrawPixel(::
Color color = {0, 0, 0, 255}) {
292 ::DrawPixelV(*
this, color);
296 inline Vector2& DrawLine(::Vector2 endPos, ::Color color = {0, 0, 0, 255}) {
297 ::DrawLineV(*
this, endPos, color);
301 inline Vector2& DrawLine(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255}) {
302 ::DrawLineEx(*
this, endPos, thick, color);
306 inline Vector2& DrawLineBezier(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255}) {
307 ::DrawLineBezier(*
this, endPos, thick, color);
318 ::
Color color = {0, 0, 0, 255}) {
327 ::DrawCircleV(*
this, radius, color);
331 inline Vector2& DrawRectangle(::Vector2 size, ::Color color = {0, 0, 0, 255}) {
332 ::DrawRectangleV(*
this, size, color);
336 inline Vector2& DrawPoly(
int sides,
float radius,
float rotation, ::Color color = {0, 0, 0, 255}) {
337 ::DrawPoly(*
this, sides, radius, rotation, color);
345 return ::CheckCollisionCircles(*
this, radius1, center2, radius2);
352 return ::CheckCollisionCircleRec(*
this, radius, rec);
359 return ::CheckCollisionPointRec(*
this, rec);
366 return ::CheckCollisionPointCircle(*
this, center, radius);
373 return ::CheckCollisionPointTriangle(*
this, p1, p2, p3);
382 ::
Vector2 *collisionPoint)
const {
383 return ::CheckCollisionLines(*
this, endPos1, startPos2, endPos2, collisionPoint);
390 return ::CheckCollisionPointLine(*
this, p1, p2, threshold);
394 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)
Vector2 & DrawCircle(float radius, ::Color color={0, 0, 0, 255})
Draw a color-filled circle (Vector version)
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.
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 & DrawLineBezierQuad(::Vector2 endPos, ::Vector2 controlPos, float thick, ::Color color={0, 0, 0, 255})
Draw line using quadratic bezier curves with a control point.
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.
Vector2 Divide(const float div) const
Divide vector by value.
All raylib-cpp classes and functions appear in the raylib namespace.