1#ifndef RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
2#define RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
4#ifndef RAYLIB_CPP_NO_MATH
10#include "./raylib.hpp"
11#include "./raymath.hpp"
12#include "./raylib-cpp-utils.hpp"
13#include "./RadiansDegrees.hpp"
21 Vector2(const ::Vector2& vec) : ::Vector2{vec.x, vec.y} {}
23 Vector2(
float x,
float y) : ::Vector2{x, y} {}
24 Vector2(
float x) : ::Vector2{x, 0} {}
27 GETTERSETTER(
float, X, x)
28 GETTERSETTER(
float, Y, y)
50 return !(*
this == other);
53 std::string ToString()
const {
54 return TextFormat(
"Vector2(%f, %f)", x, y);
57 operator std::string()
const {
61#ifndef RAYLIB_CPP_NO_MATH
66 return Vector2Add(*
this, vector2);
73 return Vector2Add(*
this, vector2);
80 set(Vector2Add(*
this, vector2));
89 return Vector2Subtract(*
this, vector2);
96 return Vector2Subtract(*
this, vector2);
103 set(Vector2Subtract(*
this, vector2));
112 return Vector2Negate(*
this);
119 return Vector2Negate(*
this);
126 return Vector2Multiply(*
this, vector2);
133 return Vector2Multiply(*
this, vector2);
140 set(Vector2Multiply(*
this, vector2));
149 return Vector2Scale(*
this, scale);
156 return Vector2Scale(*
this, scale);
163 set(Vector2Scale(*
this, scale));
172 return Vector2Divide(*
this, vector2);
179 return Vector2Divide(*
this, vector2);
186 set(Vector2Divide(*
this, vector2));
195 return ::Vector2{x / div, y / div};
219 return Vector2Normalize(*
this);
226 return ::Vector2Transform(*
this, mat);
233 return Vector2Lerp(*
this, vector2, amount);
240 return Vector2Reflect(*
this, normal);
247 return Vector2Rotate(*
this, angle);
254 return Vector2MoveTowards(*
this, target, maxDistance);
261 return ::Vector2Invert(*
this);
268 return ::Vector2Clamp(*
this, min, max);
275 return ::Vector2ClampValue(*
this, min, max);
282 return ::Vector2Equals(*
this, q);
289 return Vector2Length(*
this);
296 return Vector2LengthSqr(*
this);
303 return Vector2DotProduct(*
this, vector2);
310 return Vector2Distance(*
this, vector2);
317 return ::Vector2DistanceSqr(*
this, v2);
324 return Vector2Angle(*
this, vector2);
331 return Vector2Zero();
342 void DrawPixel(::Color color = {0, 0, 0, 255})
const {
343 ::DrawPixelV(*
this, color);
346 void DrawLine(::Vector2 endPos, ::Color color = {0, 0, 0, 255})
const {
347 ::DrawLineV(*
this, endPos, color);
350 void DrawLine(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255})
const {
351 ::DrawLineEx(*
this, endPos, thick, color);
354 void DrawLineBezier(::Vector2 endPos,
float thick, ::Color color = {0, 0, 0, 255})
const {
355 ::DrawLineBezier(*
this, endPos, thick, color);
361 void DrawCircle(
float radius, ::Color color = {0, 0, 0, 255})
const {
362 ::DrawCircleV(*
this, radius, color);
365 void DrawRectangle(::Vector2 size, ::Color color = {0, 0, 0, 255})
const {
366 ::DrawRectangleV(*
this, size, color);
369 void DrawPoly(
int sides,
float radius, Degree rotation, ::Color color = {0, 0, 0, 255})
const {
370 ::DrawPoly(*
this, sides, radius, rotation, color);
377 return ::CheckCollisionCircles(*
this, radius1, center2, radius2);
384 return ::CheckCollisionCircleRec(*
this, radius, rec);
391 return ::CheckCollisionPointRec(*
this, rec);
398 return ::CheckCollisionPointCircle(*
this, center, radius);
405 return ::CheckCollisionPointTriangle(*
this, p1, p2, p3);
413 ::Vector2 startPos2, ::Vector2 endPos2,
414 ::Vector2 *collisionPoint)
const {
415 return ::CheckCollisionLines(*
this, endPos1, startPos2, endPos2, collisionPoint);
422 return ::CheckCollisionPointLine(*
this, p1, p2, threshold);
426 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-=(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 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
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 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 Invert() const
Invert the given vector.
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.