1#ifndef RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
2#define RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
4#ifndef RAYLIB_CPP_NO_MATH
10#include "./raylib-cpp-utils.hpp"
11#include "./raylib.hpp"
12#include "./raymath.hpp"
13#include "./raylib-cpp-utils.hpp"
14#include "./RadiansDegrees.hpp"
22 Vector2(const ::Vector2& vec) : ::Vector2{vec.x, vec.y} {}
24 Vector2(
float x,
float y) : ::Vector2{x, y} {}
25 Vector2(
float x) : ::Vector2{x, 0} {}
28 GETTERSETTER(
float, X, x)
29 GETTERSETTER(
float, Y, y)
42 bool operator==(const ::Vector2& other)
const {
return x == other.x && y == other.y; }
47 bool operator!=(const ::Vector2& other)
const {
return !(*
this == other); }
49 [[nodiscard]] std::string ToString()
const {
return TextFormat(
"Vector2(%f, %f)", x, y); }
51 operator std::string()
const {
return ToString(); }
53#ifndef RAYLIB_CPP_NO_MATH
57 Vector2 Add(const ::Vector2& vector2)
const {
return Vector2Add(*
this, vector2); }
62 Vector2 operator+(const ::Vector2& vector2)
const {
return Vector2Add(*
this, vector2); }
68 set(Vector2Add(*
this, vector2));
77 return Vector2AddValue(*
this, value);
84 return Vector2AddValue(*
this, value);
91 set(Vector2AddValue(*
this, value));
99 [[nodiscard]]
Vector2 Subtract(const ::Vector2& vector2)
const {
return Vector2Subtract(*
this, vector2); }
104 Vector2 operator-(const ::Vector2& vector2)
const {
return Vector2Subtract(*
this, vector2); }
110 set(Vector2Subtract(*
this, vector2));
119 return Vector2SubtractValue(*
this, value);
126 return Vector2SubtractValue(*
this, value);
133 set(Vector2SubtractValue(*
this, value));
151 [[nodiscard]]
Vector2 Multiply(const ::Vector2& vector2)
const {
return Vector2Multiply(*
this, vector2); }
156 Vector2 operator*(const ::Vector2& vector2)
const {
return Vector2Multiply(*
this, vector2); }
162 set(Vector2Multiply(*
this, vector2));
170 [[nodiscard]]
Vector2 Scale(
const float scale)
const {
return Vector2Scale(*
this, scale); }
181 set(Vector2Scale(*
this, scale));
189 [[nodiscard]]
Vector2 Divide(const ::Vector2& vector2)
const {
return Vector2Divide(*
this, vector2); }
195 Vector2 operator/(const ::Vector2& vector2)
const {
return Vector2Divide(*
this, vector2); }
201 set(Vector2Divide(*
this, vector2));
209 [[nodiscard]]
Vector2 Divide(
const float div)
const { return ::Vector2{x / div, y / div}; }
234 [[nodiscard]]
Vector2 Transform(::Matrix mat)
const { return ::Vector2Transform(*
this, mat); }
239 [[nodiscard]]
Vector2 Lerp(const ::Vector2& vector2,
float amount)
const {
return Vector2Lerp(*
this, vector2, amount); }
244 [[nodiscard]]
Vector2 Reflect(const ::Vector2& normal)
const {
return Vector2Reflect(*
this, normal); }
250 return Vector2Rotate(*
this, angle);
257 return Vector2MoveTowards(*
this, target, maxDistance);
268 [[nodiscard]]
Vector2 Clamp(::Vector2 min, ::Vector2 max)
const { return ::Vector2Clamp(*
this, min, max); }
273 [[nodiscard]]
Vector2 Clamp(
float min,
float max)
const { return ::Vector2ClampValue(*
this, min, max); }
278 [[nodiscard]]
int Equals(::Vector2 q)
const { return ::Vector2Equals(*
this, q); }
283 [[nodiscard]]
float Length()
const {
return Vector2Length(*
this); }
288 [[nodiscard]]
float LengthSqr()
const {
return Vector2LengthSqr(*
this); }
293 [[nodiscard]]
float DotProduct(const ::Vector2& vector2)
const {
return Vector2DotProduct(*
this, vector2); }
298 [[nodiscard]]
float Distance(const ::Vector2& vector2)
const {
return Vector2Distance(*
this, vector2); }
303 [[nodiscard]]
float DistanceSqr(::Vector2 v2)
const { return ::Vector2DistanceSqr(*
this, v2); }
309 return Vector2Angle(*
this, vector2);
323 void DrawPixel(::Color color = {0, 0, 0, 255})
const { ::DrawPixelV(*
this, color); }
325 void DrawLine(::Vector2 endPos, ::Color color = {0, 0, 0, 255})
const { ::DrawLineV(*
this, endPos, color); }
327 void DrawLine(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255})
const {
328 ::DrawLineEx(*
this, endPos, thick, color);
331 void DrawLineBezier(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255})
const {
332 ::DrawLineBezier(*
this, endPos, thick, color);
338 void DrawCircle(
float radius, ::Color color = {0, 0, 0, 255})
const { ::DrawCircleV(*
this, radius, color); }
340 void DrawRectangle(::Vector2 size, ::Color color = {0, 0, 0, 255})
const { ::DrawRectangleV(*
this, size, color); }
342 void DrawPoly(
int sides,
float radius, Degree rotation, ::Color color = {0, 0, 0, 255})
const {
343 ::DrawPoly(*
this, sides, radius, rotation, color);
350 return ::CheckCollisionCircles(*
this, radius1, center2, radius2);
357 return ::CheckCollisionCircleRec(*
this, radius, rec);
363 [[nodiscard]]
bool CheckCollision(::Rectangle rec)
const { return ::CheckCollisionPointRec(*
this, rec); }
369 return ::CheckCollisionPointCircle(*
this, center, radius);
375 [[nodiscard]]
bool CheckCollision(::Vector2 p1, ::Vector2 p2, ::Vector2 p3)
const {
376 return ::CheckCollisionPointTriangle(*
this, p1, p2, p3);
383 CheckCollisionLines(::Vector2 endPos1, ::Vector2 startPos2, ::Vector2 endPos2, ::Vector2* collisionPoint)
const {
384 return ::CheckCollisionLines(*
this, endPos1, startPos2, endPos2, collisionPoint);
391 return ::CheckCollisionPointLine(*
this, p1, p2, threshold);
394 void set(const ::Vector2& vec) {
Radian type (allows automatic worry free conversion between radians and degrees)
bool operator==(const ::Vector2 &other) const
Determine whether or not the vectors are equal.
Vector2 & operator+=(float value)
Add vector and float value.
Vector2 & operator-=(const ::Vector2 &vector2)
Subtract two vectors (v1 - v2)
bool CheckCollision(::Vector2 p1, ::Vector2 p2, ::Vector2 p3) const
Check if point is inside a triangle.
Vector2 operator-(float value) const
Subtract vector by float value.
Vector2 MoveTowards(const ::Vector2 &target, float maxDistance) const
Move Vector towards target.
Radian Angle(const ::Vector2 &vector2) const
Calculate angle from two vectors in X-axis.
Vector2 Subtract(const ::Vector2 &vector2) const
Subtract two vectors (v1 - v2)
Vector2 Clamp(::Vector2 min, ::Vector2 max) const
Clamp the components of the vector between.
Vector2 operator*(const float scale) const
Scale vector (multiply by value)
bool CheckCollision(::Rectangle rec) const
Check if point is inside rectangle.
bool operator!=(const ::Vector2 &other) const
Determines if the vectors are not equal.
Vector2 Lerp(const ::Vector2 &vector2, float amount) const
Calculate linear interpolation between two vectors.
Vector2 & operator*=(const float scale)
Scale vector (multiply by value)
Vector2 & operator/=(const ::Vector2 &vector2)
Divide vector by vector.
float Length() const
Calculate vector length.
float DotProduct(const ::Vector2 &vector2) const
Calculate two vectors dot product.
float LengthSqr() const
Calculate vector square length.
float DistanceSqr(::Vector2 v2) const
Calculate square distance between two vectors.
float Distance(const ::Vector2 &vector2) const
Calculate distance between two vectors.
Vector2 & operator+=(const ::Vector2 &vector2)
Add two vectors (v1 + v2)
Vector2 Clamp(float min, float max) const
// Clamp the magnitude of the vector between two min and max values
Vector2 Subtract(float value) const
Subtract vector by float value.
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 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.
Vector2 & operator-=(float value)
Subtract vector by float value.
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+(float value) const
Add vector and float value.
Vector2 Invert() const
Invert the given vector.
Vector2 Add(float value) const
Add vector and float value.
Vector2 & operator*=(const ::Vector2 &vector2)
Multiply vector by vector.
bool CheckCollisionPointLine(::Vector2 p1, ::Vector2 p2, int threshold=1) const
Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels...
Vector2 Transform(::Matrix mat) const
Transforms a Vector2 by a given Matrix.
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.
Vector2 & operator/=(const float div)
Divide vector by value.
int Equals(::Vector2 q) const
Check whether two given vectors are almost equal.
Vector2 Rotate(Radian angle) const
Rotate Vector by float in radians.
Vector2 Normalize() const
Normalize provided vector.
Vector2 operator-() const
Negate vector.
Vector2 operator-(const ::Vector2 &vector2) const
Subtract two vectors (v1 - v2)
Vector2 Divide(const float div) const
Divide vector by value.
All raylib-cpp classes and functions appear in the raylib namespace.