vector2_ptr.c file
Functions
- void vec2_add_ptr(vector2* res, const vector2* a, const vector2* b)
- Adds vectors a and b component-wise, storing the result in res.
- void vec2_sub_ptr(vector2* res, const vector2* a, const vector2* b)
- Subtracts vector b from vector a component-wise, storing the result in res.
-
void vec2_mul_scalar_ptr(vector2* res,
const vector2* v,
const vm_
float_ t s) - Multiplies vector v by scalar s component-wise, storing the result in res.
-
void vec2_div_scalar_ptr(vector2* res,
const vector2* v,
const vm_
float_ t s) - Divides vector v by scalar s component-wise, storing the result in res.
- void vec2_mul_ptr(vector2* res, const vector2* a, const vector2* b)
- Multiplies vectors a and b component-wise, storing the result in res.
- void vec2_neg_ptr(vector2* res, const vector2* v)
- Negates the components of vector v, storing the result in res.
- void vec2_abs_ptr(vector2* res, const vector2* v)
- Computes the absolute values of the components of vector v, storing the result in res.
- void vec2_normalize_ptr(vector2* res, const vector2* v)
- Normalizes vector v to unit length, storing the result in res.
- void vec2_min_ptr(vector2* res, const vector2* a, const vector2* b)
- Computes the component-wise minimum of vectors a and b, storing the result in res.
- void vec2_max_ptr(vector2* res, const vector2* a, const vector2* b)
- Computes the component-wise maximum of vectors a and b, storing the result in res.
- void vec2_sign_ptr(vector2* res, const vector2* v)
- Sets each component of res to the sign of the corresponding component in v (+1, -1).
- void vec2_floor_ptr(vector2* res, const vector2* v)
- Applies the floor function to each component of vector v, storing the result in res.
- void vec2_ceil_ptr(vector2* res, const vector2* v)
- Applies the ceil function to each component of vector v, storing the result in res.
- void vec2_round_ptr(vector2* res, const vector2* v)
- Applies the round function to each component of vector v, storing the result in res.
- void vec2_perpendicular_ptr(vector2* res, const vector2* v)
- Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in res.
- void vec2_cross_ptr(vector2* res, const vector2* a, const vector2* b)
- Computes the 2D cross-product of a and b, storing the scalar value in res->x and 0 in res->y.
-
void vec2_scale_ptr(vector2* res,
const vector2* v,
const vm_
float_ t s) - Scales a vector by a scalar component-wise, storing the result in res.
- void vec2_reflect_ptr(vector2* res, const vector2* v, const vector2* normal)
- Reflects vector v across the normal, storing the result in res.
- void vec2_project_ptr(vector2* res, const vector2* a, const vector2* b)
- Projects vector
aonto vectorb(scalar projection scaled byb). - void vec2_tangent_ptr(vector2* res, const vector2* v)
- Computes a tangent vector perpendicular to the input (90 degrees clockwise).
-
void vec2_rotate_ptr(vector2* result,
const vector2* v,
const vm_
float_ t radians) - Rotates the input vector counterclockwise by the given angle (radians).
-
void vec2_rotate_deg_ptr(vector2* result,
const vector2* v,
const vm_
float_ t degrees) - Rotates vector v by the given angle in degrees, storing the result in result.
- void vec2_slide_ptr(vector2* result, const vector2* v, const vector2* normal)
- Slides the input vector tangent to the normal (removes normal component).
- void vec2_clamp_ptr(vector2* res, const vector2* v, const vector2* min, const vector2* max)
- Clamps vector v component-wise between min and max.
-
void vec2_lerp_ptr(vector2* res,
const vector2* a,
const vector2* b,
const vm_
float_ t t) - Linearly interpolates from a to b by t.
- void vec2_div_ptr(vector2* res, const vector2* a, const vector2* b)
- Divides two vectors component-wise.
-
void vec2_add_scalar_ptr(vector2* res,
const vector2* v,
const vm_
float_ t s) - Adds a scalar to each component.
-
void vec2_sub_scalar_ptr(vector2* res,
const vector2* v,
const vm_
float_ t s) - Subtracts a scalar from each component.
-
void vec2_clamp_scalar_ptr(vector2* res,
const vector2* v,
const vm_
float_ t min, const vm_ float_ t max) - Clamps each component to the scalar range [min, max].
- void vec2_saturate_ptr(vector2* res, const vector2* v)
- Clamps each component to the range [0, 1].
- void vec2_fract_ptr(vector2* res, const vector2* v)
- Returns the fractional part of each component.
-
void vec2_refract_ptr(vector2* res,
const vector2* incident,
const vector2* normal,
const vm_
float_ t eta) - Computes the refraction of incident across normal with ratio eta.
- void vec2_reject_ptr(vector2* res, const vector2* a, const vector2* b)
- Returns the component of a orthogonal to b.
-
void vec2_rotate_around_ptr(vector2* res,
const vector2* v,
const vector2* pivot,
const vm_
float_ t radians) - Rotates v around pivot by angle radians.
-
void vec2_rotate_around_deg_ptr(vector2* res,
const vector2* v,
const vector2* pivot,
const vm_
float_ t degrees) - Rotates vector v around the given pivot point by the specified angle in degrees.
-
void vec2_move_toward_ptr(vector2* res,
const vector2* current,
const vector2* target,
const vm_
float_ t max_delta) - Moves current toward target by at most max_delta.
-
void vec2_limit_length_ptr(vector2* res,
const vector2* v,
const vm_
float_ t max_len) - Clamps the vector length to max_len.
-
void vec2_to_vec3_ptr(vector3* res,
const vector2* v,
const vm_
float_ t z) - Converts a vector2 to a vector3 with the given z.
Function documentation
void vec2_add_ptr(vector2* res, const vector2* a, const vector2* b)
Adds vectors a and b component-wise, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
void vec2_sub_ptr(vector2* res, const vector2* a, const vector2* b)
Subtracts vector b from vector a component-wise, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
void vec2_mul_scalar_ptr(vector2* res,
const vector2* v,
const vm_ float_ t s)
Multiplies vector v by scalar s component-wise, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| s | Input scalar. |
void vec2_div_scalar_ptr(vector2* res,
const vector2* v,
const vm_ float_ t s)
Divides vector v by scalar s component-wise, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| s | Input scalar. |
void vec2_mul_ptr(vector2* res, const vector2* a, const vector2* b)
Multiplies vectors a and b component-wise, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
void vec2_neg_ptr(vector2* res, const vector2* v)
Negates the components of vector v, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_abs_ptr(vector2* res, const vector2* v)
Computes the absolute values of the components of vector v, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_normalize_ptr(vector2* res, const vector2* v)
Normalizes vector v to unit length, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_min_ptr(vector2* res, const vector2* a, const vector2* b)
Computes the component-wise minimum of vectors a and b, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
void vec2_max_ptr(vector2* res, const vector2* a, const vector2* b)
Computes the component-wise maximum of vectors a and b, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
void vec2_sign_ptr(vector2* res, const vector2* v)
Sets each component of res to the sign of the corresponding component in v (+1, -1).
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_floor_ptr(vector2* res, const vector2* v)
Applies the floor function to each component of vector v, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_ceil_ptr(vector2* res, const vector2* v)
Applies the ceil function to each component of vector v, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_round_ptr(vector2* res, const vector2* v)
Applies the round function to each component of vector v, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_perpendicular_ptr(vector2* res, const vector2* v)
Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_cross_ptr(vector2* res, const vector2* a, const vector2* b)
Computes the 2D cross-product of a and b, storing the scalar value in res->x and 0 in res->y.
| Parameters | |
|---|---|
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
void vec2_scale_ptr(vector2* res,
const vector2* v,
const vm_ float_ t s)
Scales a vector by a scalar component-wise, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| s | Input scalar. |
void vec2_reflect_ptr(vector2* res, const vector2* v, const vector2* normal)
Reflects vector v across the normal, storing the result in res.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input incident vector. |
| normal | Input surface normal. |
void vec2_project_ptr(vector2* res, const vector2* a, const vector2* b)
Projects vector a onto vector b (scalar projection scaled by b).
| Parameters | |
|---|---|
| res | The output projected vector. |
| a | The vector to project. |
| b | The direction vector (non-zero length recommended). |
void vec2_tangent_ptr(vector2* res, const vector2* v)
Computes a tangent vector perpendicular to the input (90 degrees clockwise).
| Parameters | |
|---|---|
| res | The output tangent vector. |
| v | The input vector. |
Equivalent to (v.y, -v.x).
void vec2_rotate_ptr(vector2* result,
const vector2* v,
const vm_ float_ t radians)
Rotates the input vector counterclockwise by the given angle (radians).
| Parameters | |
|---|---|
| result | The output rotated vector. |
| v | The input vector. |
| radians | The rotation angle in radians. |
Uses standard 2D rotation matrix.
void vec2_rotate_deg_ptr(vector2* result,
const vector2* v,
const vm_ float_ t degrees)
Rotates vector v by the given angle in degrees, storing the result in result.
| Parameters | |
|---|---|
| result | Output vector. |
| v | Input vector. |
| degrees | Rotation angle in degrees. |
void vec2_slide_ptr(vector2* result, const vector2* v, const vector2* normal)
Slides the input vector tangent to the normal (removes normal component).
| Parameters | |
|---|---|
| result | The output slid vector. |
| v | The input vector. |
| normal | The unit normal vector. |
Formula: v - dot(v, normal) * normal (assumes unit normal).
void vec2_clamp_ptr(vector2* res, const vector2* v, const vector2* min, const vector2* max)
Clamps vector v component-wise between min and max.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector to clamp. |
| min | Minimum bounds vector. |
| max | Maximum bounds vector. |
void vec2_lerp_ptr(vector2* res,
const vector2* a,
const vector2* b,
const vm_ float_ t t)
Linearly interpolates from a to b by t.
| Parameters | |
|---|---|
| res | Output vector. |
| a | First input vector. |
| b | Second input vector. |
| t | Interpolation factor. |
void vec2_div_ptr(vector2* res, const vector2* a, const vector2* b)
Divides two vectors component-wise.
| Parameters | |
|---|---|
| res | Output vector. |
| a | First input vector. |
| b | Second input vector. |
void vec2_add_scalar_ptr(vector2* res,
const vector2* v,
const vm_ float_ t s)
Adds a scalar to each component.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| s | Scalar value. |
void vec2_sub_scalar_ptr(vector2* res,
const vector2* v,
const vm_ float_ t s)
Subtracts a scalar from each component.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| s | Scalar value. |
void vec2_clamp_scalar_ptr(vector2* res,
const vector2* v,
const vm_ float_ t min,
const vm_ float_ t max)
Clamps each component to the scalar range [min, max].
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| min | Lower bound. |
| max | Upper bound. |
void vec2_saturate_ptr(vector2* res, const vector2* v)
Clamps each component to the range [0, 1].
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_fract_ptr(vector2* res, const vector2* v)
Returns the fractional part of each component.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
void vec2_refract_ptr(vector2* res,
const vector2* incident,
const vector2* normal,
const vm_ float_ t eta)
Computes the refraction of incident across normal with ratio eta.
| Parameters | |
|---|---|
| res | Output vector. |
| incident | Incident vector. |
| normal | Surface normal. |
| eta | Ratio of indices of refraction. |
void vec2_reject_ptr(vector2* res, const vector2* a, const vector2* b)
Returns the component of a orthogonal to b.
| Parameters | |
|---|---|
| res | Output vector. |
| a | First input vector. |
| b | Second input vector. |
void vec2_rotate_around_ptr(vector2* res,
const vector2* v,
const vector2* pivot,
const vm_ float_ t radians)
Rotates v around pivot by angle radians.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| pivot | Rotation pivot. |
| radians | Angle in radians. |
void vec2_rotate_around_deg_ptr(vector2* res,
const vector2* v,
const vector2* pivot,
const vm_ float_ t degrees)
Rotates vector v around the given pivot point by the specified angle in degrees.
| Parameters | |
|---|---|
| res | Output vector storing the rotated result. |
| v | Input vector to rotate. |
| pivot | Pivot point around which to rotate. |
| degrees | Rotation angle in degrees. |
This function converts the input angle from degrees to radians and then delegates to the radian-based rotation routine.
void vec2_move_toward_ptr(vector2* res,
const vector2* current,
const vector2* target,
const vm_ float_ t max_delta)
Moves current toward target by at most max_delta.
| Parameters | |
|---|---|
| res | Output vector. |
| current | Current position. |
| target | Target position. |
| max_delta | Maximum distance to move. |
void vec2_limit_length_ptr(vector2* res,
const vector2* v,
const vm_ float_ t max_len)
Clamps the vector length to max_len.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| max_len | Maximum length. |
void vec2_to_vec3_ptr(vector3* res,
const vector2* v,
const vm_ float_ t z)
Converts a vector2 to a vector3 with the given z.
| Parameters | |
|---|---|
| res | Output vector. |
| v | Input vector. |
| z | Z component. |