raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
raylib::Vector2 Class Reference

Vector2 type. More...

#include <Vector2.hpp>

Public Member Functions

 Vector2 (const ::Vector2 &vec)
 
 Vector2 (float x)
 
 Vector2 (float x, float y)
 
Vector2 Add (const ::Vector2 &vector2) const
 Add two vectors (v1 + v2) More...
 
Vector2 Add (float value) const
 Add vector and float value. More...
 
Radian Angle (const ::Vector2 &vector2) const
 Calculate angle from two vectors in X-axis. More...
 
bool CheckCollision (::Rectangle rec) const
 Check if point is inside rectangle. More...
 
bool CheckCollision (::Vector2 center, float radius) const
 Check if point is inside circle. More...
 
bool CheckCollision (::Vector2 p1, ::Vector2 p2, ::Vector2 p3) const
 Check if point is inside a triangle. More...
 
bool CheckCollisionCircle (float radius, ::Rectangle rec) const
 Check collision between circle and rectangle. More...
 
bool CheckCollisionCircle (float radius1, ::Vector2 center2, float radius2) const
 Check collision between two circles. More...
 
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 reference. More...
 
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 [threshold]. More...
 
Vector2 Clamp (::Vector2 min, ::Vector2 max) const
 Clamp the components of the vector between. More...
 
Vector2 Clamp (float min, float max) const
 // Clamp the magnitude of the vector between two min and max values More...
 
float Distance (const ::Vector2 &vector2) const
 Calculate distance between two vectors. More...
 
float DistanceSqr (::Vector2 v2) const
 Calculate square distance between two vectors. More...
 
Vector2 Divide (const ::Vector2 &vector2) const
 Divide vector by vector. More...
 
Vector2 Divide (const float div) const
 Divide vector by value. More...
 
float DotProduct (const ::Vector2 &vector2) const
 Calculate two vectors dot product. More...
 
void DrawCircle (float radius, ::Color color={0, 0, 0, 255}) const
 Draw a color-filled circle (Vector version) More...
 
void DrawLine (::Vector2 endPos, ::Color color={0, 0, 0, 255}) const
 
void DrawLine (::Vector2 endPos, float thick, ::Color color={0, 0, 0, 255}) const
 
void DrawLineBezier (::Vector2 endPos, float thick, ::Color color={0, 0, 0, 255}) const
 
void DrawPixel (::Color color={0, 0, 0, 255}) const
 
void DrawPoly (int sides, float radius, Degree rotation, ::Color color={0, 0, 0, 255}) const
 
void DrawRectangle (::Vector2 size, ::Color color={0, 0, 0, 255}) const
 
int Equals (::Vector2 q) const
 Check whether two given vectors are almost equal. More...
 
float GetX () const
 Retrieves the x value for the object. More...
 
float GetY () const
 Retrieves the y value for the object. More...
 
Vector2 Invert () const
 Invert the given vector. More...
 
float Length () const
 Calculate vector length. More...
 
float LengthSqr () const
 Calculate vector square length. More...
 
Vector2 Lerp (const ::Vector2 &vector2, float amount) const
 Calculate linear interpolation between two vectors. More...
 
Vector2 MoveTowards (const ::Vector2 &target, float maxDistance) const
 Move Vector towards target. More...
 
Vector2 Multiply (const ::Vector2 &vector2) const
 Multiply vector by vector. More...
 
Vector2 Negate () const
 Negate vector. More...
 
Vector2 Normalize () const
 Normalize provided vector. More...
 
 operator std::string () const
 
bool operator!= (const ::Vector2 &other) const
 Determines if the vectors are not equal. More...
 
Vector2 operator* (const ::Vector2 &vector2) const
 Multiply vector by vector. More...
 
Vector2 operator* (const float scale) const
 Scale vector (multiply by value) More...
 
Vector2operator*= (const ::Vector2 &vector2)
 Multiply vector by vector. More...
 
Vector2operator*= (const float scale)
 Scale vector (multiply by value) More...
 
Vector2 operator+ (const ::Vector2 &vector2) const
 Add two vectors (v1 + v2) More...
 
Vector2 operator+ (float value) const
 Add vector and float value. More...
 
Vector2operator+= (const ::Vector2 &vector2)
 Add two vectors (v1 + v2) More...
 
Vector2operator+= (float value)
 Add vector and float value. More...
 
Vector2 operator- () const
 Negate vector. More...
 
Vector2 operator- (const ::Vector2 &vector2) const
 Subtract two vectors (v1 - v2) More...
 
Vector2 operator- (float value) const
 Subtract vector by float value. More...
 
Vector2operator-= (const ::Vector2 &vector2)
 Subtract two vectors (v1 - v2) More...
 
Vector2operator-= (float value)
 Subtract vector by float value. More...
 
Vector2 operator/ (const ::Vector2 &vector2) const
 Divide vector by vector. More...
 
Vector2 operator/ (const float div) const
 Divide vector by value. More...
 
Vector2operator/= (const ::Vector2 &vector2)
 Divide vector by vector. More...
 
Vector2operator/= (const float div)
 Divide vector by value. More...
 
Vector2operator= (const ::Vector2 &vector2)
 Set the Vector2 to the same as the given Vector2. More...
 
bool operator== (const ::Vector2 &other) const
 Determine whether or not the vectors are equal. More...
 
Vector2 Reflect (const ::Vector2 &normal) const
 Calculate reflected vector to normal. More...
 
Vector2 Rotate (Radian angle) const
 Rotate Vector by float in radians. More...
 
Vector2 Scale (const float scale) const
 Scale vector (multiply by value) More...
 
void SetX (float value)
 Sets the x value for the object. More...
 
void SetY (float value)
 Sets the y value for the object. More...
 
Vector2 Subtract (const ::Vector2 &vector2) const
 Subtract two vectors (v1 - v2) More...
 
Vector2 Subtract (float value) const
 Subtract vector by float value. More...
 
std::string ToString () const
 
Vector2 Transform (::Matrix mat) const
 Transforms a Vector2 by a given Matrix. More...
 

Static Public Member Functions

static Vector2 One ()
 Vector with components value 1.0f. More...
 
static Vector2 Zero ()
 Vector with components value 0.0f. More...
 

Protected Member Functions

void set (const ::Vector2 &vec)
 

Detailed Description

Vector2 type.

Definition at line 20 of file Vector2.hpp.

Constructor & Destructor Documentation

◆ Vector2() [1/4]

raylib::Vector2::Vector2 ( const ::Vector2 &  vec)
inline

Definition at line 22 of file Vector2.hpp.

◆ Vector2() [2/4]

raylib::Vector2::Vector2 ( float  x,
float  y 
)
inline

Definition at line 24 of file Vector2.hpp.

◆ Vector2() [3/4]

raylib::Vector2::Vector2 ( float  x)
inline

Definition at line 25 of file Vector2.hpp.

◆ Vector2() [4/4]

raylib::Vector2::Vector2 ( )
inline

Definition at line 26 of file Vector2.hpp.

Member Function Documentation

◆ Add() [1/2]

Vector2 raylib::Vector2::Add ( const ::Vector2 &  vector2) const
inline

Add two vectors (v1 + v2)

Definition at line 57 of file Vector2.hpp.

◆ Add() [2/2]

Vector2 raylib::Vector2::Add ( float  value) const
inline

Add vector and float value.

Definition at line 76 of file Vector2.hpp.

◆ Angle()

Radian raylib::Vector2::Angle ( const ::Vector2 &  vector2) const
inline

Calculate angle from two vectors in X-axis.

Definition at line 308 of file Vector2.hpp.

◆ CheckCollision() [1/3]

bool raylib::Vector2::CheckCollision ( ::Rectangle  rec) const
inline

Check if point is inside rectangle.

Definition at line 363 of file Vector2.hpp.

◆ CheckCollision() [2/3]

bool raylib::Vector2::CheckCollision ( ::Vector2  center,
float  radius 
) const
inline

Check if point is inside circle.

Definition at line 368 of file Vector2.hpp.

◆ CheckCollision() [3/3]

bool raylib::Vector2::CheckCollision ( ::Vector2  p1,
::Vector2  p2,
::Vector2  p3 
) const
inline

Check if point is inside a triangle.

Definition at line 375 of file Vector2.hpp.

◆ CheckCollisionCircle() [1/2]

bool raylib::Vector2::CheckCollisionCircle ( float  radius,
::Rectangle  rec 
) const
inline

Check collision between circle and rectangle.

Definition at line 356 of file Vector2.hpp.

◆ CheckCollisionCircle() [2/2]

bool raylib::Vector2::CheckCollisionCircle ( float  radius1,
::Vector2  center2,
float  radius2 
) const
inline

Check collision between two circles.

Definition at line 349 of file Vector2.hpp.

◆ CheckCollisionLines()

bool raylib::Vector2::CheckCollisionLines ( ::Vector2  endPos1,
::Vector2  startPos2,
::Vector2  endPos2,
::Vector2 *  collisionPoint 
) const
inline

Check the collision between two lines defined by two points each, returns collision point by reference.

Definition at line 383 of file Vector2.hpp.

◆ CheckCollisionPointLine()

bool raylib::Vector2::CheckCollisionPointLine ( ::Vector2  p1,
::Vector2  p2,
int  threshold = 1 
) const
inline

Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold].

Definition at line 390 of file Vector2.hpp.

◆ Clamp() [1/2]

Vector2 raylib::Vector2::Clamp ( ::Vector2  min,
::Vector2  max 
) const
inline

Clamp the components of the vector between.

Definition at line 268 of file Vector2.hpp.

◆ Clamp() [2/2]

Vector2 raylib::Vector2::Clamp ( float  min,
float  max 
) const
inline

// Clamp the magnitude of the vector between two min and max values

Definition at line 273 of file Vector2.hpp.

◆ Distance()

float raylib::Vector2::Distance ( const ::Vector2 &  vector2) const
inline

Calculate distance between two vectors.

Definition at line 298 of file Vector2.hpp.

◆ DistanceSqr()

float raylib::Vector2::DistanceSqr ( ::Vector2  v2) const
inline

Calculate square distance between two vectors.

Definition at line 303 of file Vector2.hpp.

◆ Divide() [1/2]

Vector2 raylib::Vector2::Divide ( const ::Vector2 &  vector2) const
inline

Divide vector by vector.

Definition at line 189 of file Vector2.hpp.

Referenced by operator/().

◆ Divide() [2/2]

Vector2 raylib::Vector2::Divide ( const float  div) const
inline

Divide vector by value.

Definition at line 209 of file Vector2.hpp.

◆ DotProduct()

float raylib::Vector2::DotProduct ( const ::Vector2 &  vector2) const
inline

Calculate two vectors dot product.

Definition at line 293 of file Vector2.hpp.

◆ DrawCircle()

void raylib::Vector2::DrawCircle ( float  radius,
::Color  color = {0, 0, 0, 255} 
) const
inline

Draw a color-filled circle (Vector version)

Definition at line 338 of file Vector2.hpp.

◆ DrawLine() [1/2]

void raylib::Vector2::DrawLine ( ::Vector2  endPos,
::Color  color = {0, 0, 0, 255} 
) const
inline

Definition at line 325 of file Vector2.hpp.

◆ DrawLine() [2/2]

void raylib::Vector2::DrawLine ( ::Vector2  endPos,
float  thick,
::Color  color = {0, 0, 0, 255} 
) const
inline

Definition at line 327 of file Vector2.hpp.

◆ DrawLineBezier()

void raylib::Vector2::DrawLineBezier ( ::Vector2  endPos,
float  thick,
::Color  color = {0, 0, 0, 255} 
) const
inline

Definition at line 331 of file Vector2.hpp.

◆ DrawPixel()

void raylib::Vector2::DrawPixel ( ::Color  color = {0, 0, 0, 255}) const
inline

Definition at line 323 of file Vector2.hpp.

◆ DrawPoly()

void raylib::Vector2::DrawPoly ( int  sides,
float  radius,
Degree  rotation,
::Color  color = {0, 0, 0, 255} 
) const
inline

Definition at line 342 of file Vector2.hpp.

◆ DrawRectangle()

void raylib::Vector2::DrawRectangle ( ::Vector2  size,
::Color  color = {0, 0, 0, 255} 
) const
inline

Definition at line 340 of file Vector2.hpp.

◆ Equals()

int raylib::Vector2::Equals ( ::Vector2  q) const
inline

Check whether two given vectors are almost equal.

Definition at line 278 of file Vector2.hpp.

◆ GetX()

float raylib::Vector2::GetX ( ) const
inline

Retrieves the x value for the object.

Returns
The x value of the object.

Definition at line 28 of file Vector2.hpp.

◆ GetY()

float raylib::Vector2::GetY ( ) const
inline

Retrieves the y value for the object.

Returns
The y value of the object.

Definition at line 29 of file Vector2.hpp.

◆ Invert()

Vector2 raylib::Vector2::Invert ( ) const
inline

Invert the given vector.

Definition at line 263 of file Vector2.hpp.

◆ Length()

float raylib::Vector2::Length ( ) const
inline

Calculate vector length.

Definition at line 283 of file Vector2.hpp.

◆ LengthSqr()

float raylib::Vector2::LengthSqr ( ) const
inline

Calculate vector square length.

Definition at line 288 of file Vector2.hpp.

◆ Lerp()

Vector2 raylib::Vector2::Lerp ( const ::Vector2 &  vector2,
float  amount 
) const
inline

Calculate linear interpolation between two vectors.

Definition at line 239 of file Vector2.hpp.

◆ MoveTowards()

Vector2 raylib::Vector2::MoveTowards ( const ::Vector2 &  target,
float  maxDistance 
) const
inline

Move Vector towards target.

Definition at line 256 of file Vector2.hpp.

◆ Multiply()

Vector2 raylib::Vector2::Multiply ( const ::Vector2 &  vector2) const
inline

Multiply vector by vector.

Definition at line 151 of file Vector2.hpp.

◆ Negate()

Vector2 raylib::Vector2::Negate ( ) const
inline

Negate vector.

Definition at line 141 of file Vector2.hpp.

◆ Normalize()

Vector2 raylib::Vector2::Normalize ( ) const
inline

Normalize provided vector.

Definition at line 229 of file Vector2.hpp.

◆ One()

static Vector2 raylib::Vector2::One ( )
inlinestatic

Vector with components value 1.0f.

Definition at line 320 of file Vector2.hpp.

◆ operator std::string()

raylib::Vector2::operator std::string ( ) const
inline

Definition at line 51 of file Vector2.hpp.

◆ operator!=()

bool raylib::Vector2::operator!= ( const ::Vector2 &  other) const
inline

Determines if the vectors are not equal.

Definition at line 47 of file Vector2.hpp.

◆ operator*() [1/2]

Vector2 raylib::Vector2::operator* ( const ::Vector2 &  vector2) const
inline

Multiply vector by vector.

Definition at line 156 of file Vector2.hpp.

◆ operator*() [2/2]

Vector2 raylib::Vector2::operator* ( const float  scale) const
inline

Scale vector (multiply by value)

Definition at line 175 of file Vector2.hpp.

◆ operator*=() [1/2]

Vector2 & raylib::Vector2::operator*= ( const ::Vector2 &  vector2)
inline

Multiply vector by vector.

Definition at line 161 of file Vector2.hpp.

◆ operator*=() [2/2]

Vector2 & raylib::Vector2::operator*= ( const float  scale)
inline

Scale vector (multiply by value)

Definition at line 180 of file Vector2.hpp.

◆ operator+() [1/2]

Vector2 raylib::Vector2::operator+ ( const ::Vector2 &  vector2) const
inline

Add two vectors (v1 + v2)

Definition at line 62 of file Vector2.hpp.

◆ operator+() [2/2]

Vector2 raylib::Vector2::operator+ ( float  value) const
inline

Add vector and float value.

Definition at line 83 of file Vector2.hpp.

◆ operator+=() [1/2]

Vector2 & raylib::Vector2::operator+= ( const ::Vector2 &  vector2)
inline

Add two vectors (v1 + v2)

Definition at line 67 of file Vector2.hpp.

◆ operator+=() [2/2]

Vector2 & raylib::Vector2::operator+= ( float  value)
inline

Add vector and float value.

Definition at line 90 of file Vector2.hpp.

◆ operator-() [1/3]

Vector2 raylib::Vector2::operator- ( ) const
inline

Negate vector.

Definition at line 146 of file Vector2.hpp.

◆ operator-() [2/3]

Vector2 raylib::Vector2::operator- ( const ::Vector2 &  vector2) const
inline

Subtract two vectors (v1 - v2)

Definition at line 104 of file Vector2.hpp.

◆ operator-() [3/3]

Vector2 raylib::Vector2::operator- ( float  value) const
inline

Subtract vector by float value.

Definition at line 125 of file Vector2.hpp.

◆ operator-=() [1/2]

Vector2 & raylib::Vector2::operator-= ( const ::Vector2 &  vector2)
inline

Subtract two vectors (v1 - v2)

Definition at line 109 of file Vector2.hpp.

◆ operator-=() [2/2]

Vector2 & raylib::Vector2::operator-= ( float  value)
inline

Subtract vector by float value.

Definition at line 132 of file Vector2.hpp.

◆ operator/() [1/2]

Vector2 raylib::Vector2::operator/ ( const ::Vector2 &  vector2) const
inline

Divide vector by vector.

Definition at line 195 of file Vector2.hpp.

◆ operator/() [2/2]

Vector2 raylib::Vector2::operator/ ( const float  div) const
inline

Divide vector by value.

Definition at line 214 of file Vector2.hpp.

References Divide().

◆ operator/=() [1/2]

Vector2 & raylib::Vector2::operator/= ( const ::Vector2 &  vector2)
inline

Divide vector by vector.

Definition at line 200 of file Vector2.hpp.

◆ operator/=() [2/2]

Vector2 & raylib::Vector2::operator/= ( const float  div)
inline

Divide vector by value.

Definition at line 219 of file Vector2.hpp.

◆ operator=()

Vector2 & raylib::Vector2::operator= ( const ::Vector2 &  vector2)
inline

Set the Vector2 to the same as the given Vector2.

Definition at line 34 of file Vector2.hpp.

◆ operator==()

bool raylib::Vector2::operator== ( const ::Vector2 &  other) const
inline

Determine whether or not the vectors are equal.

Definition at line 42 of file Vector2.hpp.

◆ Reflect()

Vector2 raylib::Vector2::Reflect ( const ::Vector2 &  normal) const
inline

Calculate reflected vector to normal.

Definition at line 244 of file Vector2.hpp.

◆ Rotate()

Vector2 raylib::Vector2::Rotate ( Radian  angle) const
inline

Rotate Vector by float in radians.

Definition at line 249 of file Vector2.hpp.

◆ Scale()

Vector2 raylib::Vector2::Scale ( const float  scale) const
inline

Scale vector (multiply by value)

Definition at line 170 of file Vector2.hpp.

◆ set()

void raylib::Vector2::set ( const ::Vector2 &  vec)
inlineprotected

Definition at line 394 of file Vector2.hpp.

◆ SetX()

void raylib::Vector2::SetX ( float  value)
inline

Sets the x value for the object.

Parameters
valueThe value of which to set x to.

Definition at line 28 of file Vector2.hpp.

◆ SetY()

void raylib::Vector2::SetY ( float  value)
inline

Sets the y value for the object.

Parameters
valueThe value of which to set y to.

Definition at line 29 of file Vector2.hpp.

◆ Subtract() [1/2]

Vector2 raylib::Vector2::Subtract ( const ::Vector2 &  vector2) const
inline

Subtract two vectors (v1 - v2)

Definition at line 99 of file Vector2.hpp.

◆ Subtract() [2/2]

Vector2 raylib::Vector2::Subtract ( float  value) const
inline

Subtract vector by float value.

Definition at line 118 of file Vector2.hpp.

◆ ToString()

std::string raylib::Vector2::ToString ( ) const
inline

Definition at line 49 of file Vector2.hpp.

◆ Transform()

Vector2 raylib::Vector2::Transform ( ::Matrix  mat) const
inline

Transforms a Vector2 by a given Matrix.

Definition at line 234 of file Vector2.hpp.

◆ Zero()

static Vector2 raylib::Vector2::Zero ( )
inlinestatic

Vector with components value 0.0f.

Definition at line 315 of file Vector2.hpp.