2D vector operations library More...
Macros | |
| #define | M_PI 3.14159265358979323846f |
Functions | |
| float | Vec2_Magnitude (Vec2 v) |
| [Utility] Returns the magnitude of a vector. | |
| float | Vec2_Distance (Vec2 a, Vec2 b) |
| [Utility] Returns the magnitude of a vector. | |
| Vec2 | Vec2_Normalize (Vec2 v) |
| [Utility] Returns the normalized vector of the input vector. | |
| Vec2 | Vec2_Add (Vec2 a, Vec2 b) |
| [Utility] Adds two vectors. | |
| Vec2 | Vec2_Increment (Vec2 *a, Vec2 b) |
| [Utility] Increments the vector pointed to by a with vector b. | |
| Vec2 | Vec2_Subtract (Vec2 a, Vec2 b) |
| [Utility] Subtracts vector b from vector a. | |
| Vec2 | Vec2_Decrement (Vec2 *a, Vec2 b) |
| [Utility] Decrements the vector pointed to by a by vector b. | |
| Vec2 | Vec2_Multiply (Vec2 v, float scalar) |
| [Utility] Multiplies a vector by a scalar. | |
| Vec2 | Vec2_Divide (Vec2 v, float scalar) |
| [Utility] Divides a vector by a scalar. | |
| float | Vec2_Dot (Vec2 a, Vec2 b) |
| [Utility] Returns the dot product of two vectors. | |
| Vec2 | Vec2_Lerp (Vec2 a, Vec2 b, float t) |
| [Utility] Linearly interpolates between vectors a and b. | |
| Vec2 | Vec2_RotateRadians (Vec2 v, float angle) |
| [Utility] Rotates a vector around the origin by a given angle (in radians). | |
| Vec2 | Vec2_RotateDegrees (Vec2 v, float angle) |
| [Utility] Rotates a vector around the origin by a given angle (in degrees). | |
| Vec2 | Vec2_RotateAroundRadians (Vec2 point, Vec2 center, float angle) |
| [Utility] Rotates a point around a center by a given angle (in radians). | |
| Vec2 | Vec2_RotateAroundDegrees (Vec2 point, Vec2 center, float angle) |
| [Utility] Rotates a point around a center by a given angle (in degrees). | |
| SDL_Rect | Vec2_ToRect (Vec2 position, Vec2 size) |
| [Utility] Converts a position and size into an SDL_Rect. | |
| SDL_Rect | Vec2_ToCenteredRect (Vec2 position, Vec2 size) |
| [Utility] Converts a position and size into a centered SDL_Rect. | |
| Vec2 | Vec2_ToCenteredPosition (Vec2 position, Vec2 size) |
| [Utility] Converts a position and size to a centered position. | |
| void | Vec2_FromRect (SDL_Rect rect, Vec2 *position, Vec2 *size) |
| [Utility] Extracts a position and size from an SDL_Rect. | |
| Vec2 | Vec2_Clamp (Vec2 v, Vec2 min, Vec2 max) |
| [Utility] Clamps a vector between min and max vectors. | |
| Vec2 | Vec2_Max (Vec2 a, Vec2 b) |
| [Utility] Returns a vector that is the component-wise maximum of a and b. | |
| Vec2 | Vec2_Min (Vec2 a, Vec2 b) |
| [Utility] Returns a vector that is the component-wise minimum of a and b. | |
| Vec2 | Vec2_Abs (Vec2 v) |
| [Utility] Returns the absolute values of a vector's components. | |
| Vec2 | Vec2_FromPoint (SDL_Point point) |
| [Utility] Converts an SDL_Point to a Vec2. | |
| SDL_Point | Vec2_ToPoint (Vec2 v) |
| [Utility] Converts a Vec2 to an SDL_Point. | |
| bool | Vec2_AreEqual (Vec2 a, Vec2 b) |
| Vec2 | Vec2_Square (float side) |
| SDL_Rect | Vec2_ToSquareRect (Vec2 position, float side) |
| SDL_Rect | Vec2_ToCenteredSquareRect (Vec2 position, float side) |
| float | Vec2_AngleBetween (Vec2 a, Vec2 b) |
| Calculates the angle between two vectors in degrees. | |
2D vector operations library
Implements a comprehensive set of vector operations for 2D space, supporting game physics, transformations, and coordinate handling.
| #define M_PI 3.14159265358979323846f |
[Utility] Returns the absolute values of a vector's components.
Get the absolute value of a vector.
| v | The vector to compute absolute values for. |
[Utility] Adds two vectors.
Add two vectors.
| a | The first vector. |
| b | The second vector. |
Calculates the angle between two vectors in degrees.
| a | The first vector. |
| b | The second vector. |
[Utility] Clamps a vector between min and max vectors.
Clamp a vector between two vectors.
Ensures the vector's components stay within the provided bounds.
| v | The vector to clamp. |
| min | The minimum values. |
| max | The maximum values. |
[Utility] Decrements the vector pointed to by a by vector b.
Decrement vector a by vector b.
| a | Pointer to the vector to decrement. |
| b | The vector by which a will be decremented. |
[Utility] Returns the magnitude of a vector.
Calculate the distance between two vectors.
Magnitude is the length of a vector.
| v | The vector to get the magnitude of. |
[Utility] Divides a vector by a scalar.
Divide a vector by a scalar.
| v | The vector to divide. |
| scalar | The scalar divisor. |
[Utility] Returns the dot product of two vectors.
Calculate the dot product of two vectors.
| a | The first vector. |
| b | The second vector. |
| Vec2 Vec2_FromPoint | ( | SDL_Point | point | ) |
[Utility] Extracts a position and size from an SDL_Rect.
Extract position and size from an SDL_Rect.
| rect | The SDL_Rect to decompose. |
| position | Pointer to store the position. |
| size | Pointer to store the size. |
[Utility] Increments the vector pointed to by a with vector b.
Increment vector a by vector b.
| a | Pointer to the vector to increment. |
| b | The vector to add. |
[Utility] Linearly interpolates between vectors a and b.
Linearly interpolate between two vectors.
| a | The start vector. |
| b | The destination vector. |
| t | The interpolation factor (0.0 to 1.0). |
| float Vec2_Magnitude | ( | Vec2 | v | ) |
[Utility] Returns the magnitude of a vector.
Calculate the magnitude (length) of a vector.
Magnitude is the length of a vector.
| v | The vector to get the magnitude of. |
[Utility] Returns a vector that is the component-wise maximum of a and b.
Get the maximum of two vectors.
| a | The first vector. |
| b | The second vector. |
[Utility] Returns a vector that is the component-wise minimum of a and b.
Get the minimum of two vectors.
| a | The first vector. |
| b | The second vector. |
[Utility] Multiplies a vector by a scalar.
Multiply a vector by a scalar.
| v | The vector to multiply. |
| scalar | The scalar multiplier. |
[Utility] Returns the normalized vector of the input vector.
Normalize a vector (make it unit length)
A normalized vector has a magnitude of 1 and the same direction as v.
| v | The vector to normalize. |
[Utility] Rotates a point around a center by a given angle (in degrees).
Rotate a point around a center by an angle in degrees.
| point | The point to rotate. |
| center | The pivot for rotation. |
| angle | The rotation angle in degrees. |
[Utility] Rotates a point around a center by a given angle (in radians).
Rotate a point around a center by an angle in radians.
Translates the point to origin-relative, rotates it, then translates back.
| point | The point to rotate. |
| center | The pivot for rotation. |
| angle | The rotation angle in radians. |
[Utility] Rotates a vector around the origin by a given angle (in degrees).
Rotate a vector by an angle in degrees.
| v | The vector to rotate. |
| angle | The angle in degrees. |
[Utility] Rotates a vector around the origin by a given angle (in radians).
Rotate a vector by an angle in radians.
| v | The vector to rotate. |
| angle | The angle to rotate by in radians. |
| Vec2 Vec2_Square | ( | float | side | ) |
[Utility] Subtracts vector b from vector a.
Subtract vector b from vector a.
| a | The vector to subtract from. |
| b | The vector to subtract. |
[Utility] Converts a position and size to a centered position.
Convert a position and size to a centered position.
Useful for positioning sprites centered on a coordinate.
| position | The top-left position. |
| size | The size of the object. |
[Utility] Converts a position and size into a centered SDL_Rect.
Convert a position and size to a centered SDL_Rect.
Centers the rect at the specified position.
| position | The center position. |
| size | The width and height. |
| SDL_Rect Vec2_ToCenteredSquareRect | ( | Vec2 | position, |
| float | side | ||
| ) |
| SDL_Point Vec2_ToPoint | ( | Vec2 | v | ) |
[Utility] Converts a position and size into an SDL_Rect.
Convert a position and size to an SDL_Rect.
| position | The top-left position. |
| size | The width and height. |
| SDL_Rect Vec2_ToSquareRect | ( | Vec2 | position, |
| float | side | ||
| ) |