|
Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
|
#include <vecmat.h>Go to the source code of this file.
Functions | |
| vector2 | vec2_zero (void) |
| Returns a vector2 with both components set to 0.0f. | |
| vector2 | vec2_one (void) |
| Returns a vector2 with both components set to 1.0f. | |
| vector2 | vec2_x_axis (const vm_float_t x) |
| Returns a vector2 along the x-axis (y = 0.0f). | |
| vector2 | vec2_y_axis (const vm_float_t y) |
| Returns a vector2 along the y-axis (x = 0.0f). | |
| vector2 | vec2_x_scale (const vm_float_t x) |
| Returns a vector2 representing x-axis scaling (y = 1.0f). | |
| vector2 | vec2_y_scale (const vm_float_t y) |
| Returns a vector2 representing y-axis scaling (x = 1.0f). | |
| vector2 | vec2_scale (const vector2 v, const vm_float_t s) |
| Scales a vector by a scalar component-wise. | |
| vector2 | vec2_add (const vector2 a, const vector2 b) |
| Adds two vectors component-wise. | |
| vector2 | vec2_sub (const vector2 a, const vector2 b) |
| Subtracts the second vector from the first component-wise. | |
| vector2 | vec2_mul_scalar (const vector2 v, const vm_float_t s) |
| Multiplies a vector by a scalar component-wise. | |
| vector2 | vec2_div_scalar (const vector2 v, const vm_float_t s) |
| Divides a vector by a scalar component-wise. | |
| vector2 | vec2_mul (const vector2 a, const vector2 b) |
| Multiplies two vectors component-wise (Hadamard product). | |
| vector2 | vec2_neg (const vector2 v) |
| Negates the vector (multiplies each component by -1.0f). | |
| vector2 | vec2_abs (const vector2 v) |
| Returns the absolute values of each component. | |
| vector2 | vec2_cross (const vector2 a, const vector2 b) |
| Computes the 2D cross-product as a vector. | |
| vector2 | vec2_normalize (const vector2 v) |
| Normalizes the vector to unit length. | |
| vector2 | vec2_min (const vector2 a, const vector2 b) |
| Returns the component-wise minimum of two vectors. | |
| vector2 | vec2_max (const vector2 a, const vector2 b) |
| Returns the component-wise maximum of two vectors. | |
| vector2 | vec2_sign (const vector2 v) |
| Returns the sign of each component (+1.0f, -1.0f, or 0.0f). | |
| vector2 | vec2_floor (const vector2 v) |
| Applies floor to each component. | |
| vector2 | vec2_ceil (const vector2 v) |
| Applies ceil to each component. | |
| vector2 | vec2_round (const vector2 v) |
| Applies round to each component. | |
| vector2 | vec2_perpendicular (const vector2 v) |
| Returns the perpendicular vector (90 degrees counterclockwise). | |
| vector2 | vec2_reflect (const vector2 v, const vector2 normal) |
| Reflects vector v across the normal, storing the result in res. | |
| vector2 | vec2_project (const vector2 a, const vector2 b) |
| Projects the first vector onto the second. | |
| vector2 | vec2_tangent (const vector2 v) |
| Returns the tangent vector perpendicular to the input (90 degrees clockwise). | |
| vector2 | vec2_rotate (const vector2 v, const vm_float_t angle) |
| Rotates the input vector counterclockwise by the given angle (radians). | |
| vector2 | vec2_slide (const vector2 v, const vector2 normal) |
| Slides the input vector tangent to the normal (removes normal component). | |
| vector2 | vec2_clamp (const vector2 v, const vector2 min, const vector2 max) |
| Clamps vector v component-wise between min and max. | |
| vm_float_t | vec2_dot (const vector2 a, const vector2 b) |
| Computes the dot product of two vectors. | |
| vm_float_t | vec2_length (const vector2 v) |
| Computes the length (magnitude) of the vector. | |
| vm_float_t | vec2_aspect_ratio (const vector2 v) |
| Computes the aspect ratio of the vector (x / y). | |
| vm_float_t | vec2_distance (const vector2 a, const vector2 b) |
| Computes the Euclidean distance between two vectors (treated as points). | |
| vm_float_t | vec2_angle (const vector2 a, const vector2 b) |
| Computes the angle between two vectors (in radians, range [0, PI]). | |
| vector2 | vec2_lerp (const vector2 a, const vector2 b, const vm_float_t t) |
| Linearly interpolates from a to b by t. | |
| vector2 | vec2_div (const vector2 a, const vector2 b) |
| Divides two vectors component-wise. | |
| vector2 | vec2_add_scalar (const vector2 v, const vm_float_t s) |
| Adds a scalar to each component. | |
| vector2 | vec2_sub_scalar (const vector2 v, const vm_float_t s) |
| Subtracts a scalar from each component. | |
| vector2 | vec2_clamp_scalar (const vector2 v, const vm_float_t min, const vm_float_t max) |
| Clamps each component to the scalar range [min, max]. | |
| vector2 | vec2_saturate (const vector2 v) |
| Clamps each component to the range [0, 1]. | |
| vector2 | vec2_fract (const vector2 v) |
| Returns the fractional part of each component. | |
| vector2 | vec2_refract (const vector2 incident, const vector2 normal, const vm_float_t eta) |
| Computes the refraction of incident across normal with ratio eta. | |
| vector2 | vec2_reject (const vector2 a, const vector2 b) |
| Returns the component of a orthogonal to b. | |
| vector2 | vec2_splat (const vm_float_t s) |
| Returns a vector with every component set to s. | |
| vector2 | vec2_from_angle (const vm_float_t angle) |
| Returns the unit vector at the given angle in radians. | |
| vector2 | vec2_rotate_around (const vector2 v, const vector2 pivot, const vm_float_t angle) |
| Rotates v around pivot by angle radians. | |
| vector2 | vec2_move_toward (const vector2 current, const vector2 target, const vm_float_t max_delta) |
| Moves current toward target by at most max_delta. | |
| vector2 | vec2_limit_length (const vector2 v, const vm_float_t max_len) |
| Clamps the vector length to max_len. | |
| vector3 | vec2_to_vec3 (const vector2 v, const vm_float_t z) |
| Converts a vector2 to a vector3 using z. | |
| vm_float_t | vec2_length_squared (const vector2 v) |
| Returns the squared Euclidean length. | |
| vm_float_t | vec2_length_manhattan (const vector2 v) |
| Returns the Manhattan (L1) length. | |
| vm_float_t | vec2_length_chebyshev (const vector2 v) |
| Returns the Chebyshev (L-inf) length. | |
| vm_float_t | vec2_distance_squared (const vector2 a, const vector2 b) |
| Returns the squared Euclidean distance between a and b. | |
| vm_float_t | vec2_cross_scalar (const vector2 a, const vector2 b) |
| Returns the 2D cross product as a scalar (a.x*b.y - a.y*b.x). | |
| vm_float_t | vec2_heading (const vector2 v) |
| Returns the heading angle of the vector in radians. | |
| vm_float_t | vec2_min_component (const vector2 v) |
| Returns the smallest component. | |
| vm_float_t | vec2_max_component (const vector2 v) |
| Returns the largest component. | |
| vm_float_t | vec2_sum (const vector2 v) |
| Returns the sum of all components. | |
| bool | vec2_is_zero (const vector2 v) |
| Returns true if every component is zero. | |
| bool | vec2_is_normalized (const vector2 v) |
| Returns true if the vector has unit length. | |
| bool | vec2_near (const vector2 a, const vector2 b, const vm_float_t eps) |
| Returns true if a and b are within eps of each other. | |
Returns the absolute values of each component.
See vec2_abs_ptr instead.
| v | The input vector. |
Definition at line 190 of file vector2.c.
References vec2_abs_ptr().
Adds two vectors component-wise.
See vec2_add_ptr instead.
| a | The first vector. |
| b | The second vector. |
Definition at line 96 of file vector2.c.
References vec2_add_ptr().
| vector2 vec2_add_scalar | ( | const vector2 | v, |
| const vm_float_t | s ) |
Adds a scalar to each component.
See vec2_add_scalar_ptr instead.
| v | Input vector. |
| s | Scalar value. |
Definition at line 543 of file vector2.c.
References vec2_add_scalar_ptr().
| vm_float_t vec2_angle | ( | const vector2 | a, |
| const vector2 | b ) |
Computes the angle between two vectors (in radians, range [0, PI]).
Returns 0.0f if either vector has zero length.
| a | The first vector. |
| b | The second vector. |
Definition at line 492 of file vector2.c.
References vec2_dot(), vec2_length(), and VECMAT_ACOS.
| vm_float_t vec2_aspect_ratio | ( | const vector2 | v | ) |
Computes the aspect ratio of the vector (x / y).
Returns 0.0f if y == 0.0f.
| v | The input vector. |
Definition at line 463 of file vector2.c.
References vector2::x, and vector2::y.
Applies ceil to each component.
See vec2_ceil_ptr instead.
| v | The input vector. |
Definition at line 298 of file vector2.c.
References vec2_ceil_ptr().
Clamps vector v component-wise between min and max.
See vec2_clamp_ptr instead.
| v | The input vector. |
| min | The minimum bounds vector. |
| max | The maximum bounds vector. |
Definition at line 425 of file vector2.c.
References vec2_clamp_ptr().
| vector2 vec2_clamp_scalar | ( | const vector2 | v, |
| const vm_float_t | min, | ||
| const vm_float_t | max ) |
Clamps each component to the scalar range [min, max].
See vec2_clamp_scalar_ptr instead.
| v | Input vector. |
| min | Lower bound. |
| max | Upper bound. |
Definition at line 576 of file vector2.c.
References vec2_clamp_scalar_ptr().
Computes the 2D cross-product as a vector.
See vec2_cross_ptr instead.
| a | The first vector. |
| b | The second vector. |
Definition at line 206 of file vector2.c.
References vec2_cross_ptr().
| vm_float_t vec2_cross_scalar | ( | const vector2 | a, |
| const vector2 | b ) |
Returns the 2D cross product as a scalar (a.x*b.y - a.y*b.x).
| a | First input vector. |
| b | Second input vector. |
Definition at line 792 of file vector2.c.
References vector2::x, and vector2::y.
| vm_float_t vec2_distance | ( | const vector2 | a, |
| const vector2 | b ) |
Computes the Euclidean distance between two vectors (treated as points).
| a | The first point. |
| b | The second point. |
Definition at line 476 of file vector2.c.
References VECMAT_SQRT, vector2::x, and vector2::y.
| vm_float_t vec2_distance_squared | ( | const vector2 | a, |
| const vector2 | b ) |
Returns the squared Euclidean distance between a and b.
| a | First input vector. |
| b | Second input vector. |
Definition at line 778 of file vector2.c.
References vector2::x, and vector2::y.
Divides two vectors component-wise.
See vec2_div_ptr instead.
| a | First input vector. |
| b | Second input vector. |
Definition at line 527 of file vector2.c.
References vec2_div_ptr().
| vector2 vec2_div_scalar | ( | const vector2 | v, |
| const vm_float_t | s ) |
Divides a vector by a scalar component-wise.
See vec2_div_scalar_ptr instead.
| v | The input vector. |
| s | The scalar divisor (non-zero). |
Definition at line 144 of file vector2.c.
References vec2_div_scalar_ptr().
| vm_float_t vec2_dot | ( | const vector2 | a, |
| const vector2 | b ) |
Computes the dot product of two vectors.
| a | The first vector. |
| b | The second vector. |
Definition at line 439 of file vector2.c.
References vector2::x, and vector2::y.
Referenced by vec2_angle(), vec2_length(), vec2_length_squared(), vec2_project_ptr(), vec2_reflect_ptr(), vec2_refract_ptr(), and vec2_slide_ptr().
Applies floor to each component.
See vec2_floor_ptr instead.
| v | The input vector. |
Definition at line 283 of file vector2.c.
References vec2_floor_ptr().
Returns the fractional part of each component.
See vec2_fract_ptr instead.
| v | Input vector. |
Definition at line 606 of file vector2.c.
References vec2_fract_ptr().
| vector2 vec2_from_angle | ( | const vm_float_t | angle | ) |
Returns the unit vector at the given angle in radians.
See vec2_from_angle_ptr instead.
| angle | Angle in radians. |
Definition at line 667 of file vector2.c.
References VECMAT_COS, and VECMAT_SIN.
| vm_float_t vec2_heading | ( | const vector2 | v | ) |
Returns the heading angle of the vector in radians.
| v | Input vector. |
Definition at line 803 of file vector2.c.
References VECMAT_ATAN2, vector2::x, and vector2::y.
| bool vec2_is_normalized | ( | const vector2 | v | ) |
Returns true if the vector has unit length.
| v | Input vector. |
Definition at line 858 of file vector2.c.
References vec2_length_squared(), VECMAT_EPSILON, and VECMAT_FABS.
| bool vec2_is_zero | ( | const vector2 | v | ) |
Returns true if every component is zero.
| v | Input vector. |
Definition at line 847 of file vector2.c.
References VECMAT_EPSILON, VECMAT_FABS, vector2::x, and vector2::y.
| vm_float_t vec2_length | ( | const vector2 | v | ) |
Computes the length (magnitude) of the vector.
| v | The input vector. |
Definition at line 450 of file vector2.c.
References vec2_dot(), and VECMAT_SQRT.
Referenced by vec2_angle(), vec2_limit_length_ptr(), and vec2_normalize_ptr().
| vm_float_t vec2_length_chebyshev | ( | const vector2 | v | ) |
Returns the Chebyshev (L-inf) length.
| v | Input vector. |
Definition at line 766 of file vector2.c.
References VECMAT_FABS, VECMAT_FMAX, vector2::x, and vector2::y.
| vm_float_t vec2_length_manhattan | ( | const vector2 | v | ) |
Returns the Manhattan (L1) length.
| v | Input vector. |
Definition at line 755 of file vector2.c.
References VECMAT_FABS, vector2::x, and vector2::y.
| vm_float_t vec2_length_squared | ( | const vector2 | v | ) |
Returns the squared Euclidean length.
| v | Input vector. |
Definition at line 744 of file vector2.c.
References vec2_dot().
Referenced by vec2_is_normalized().
| vector2 vec2_lerp | ( | const vector2 | a, |
| const vector2 | b, | ||
| const vm_float_t | t ) |
Linearly interpolates from a to b by t.
See vec2_lerp_ptr instead.
| a | First input vector. |
| b | Second input vector. |
| t | Interpolation factor. |
Definition at line 511 of file vector2.c.
References vec2_lerp_ptr().
| vector2 vec2_limit_length | ( | const vector2 | v, |
| const vm_float_t | max_len ) |
Clamps the vector length to max_len.
See vec2_limit_length_ptr instead.
| v | Input vector. |
| max_len | Maximum length. |
Definition at line 715 of file vector2.c.
References vec2_limit_length_ptr().
Returns the component-wise maximum of two vectors.
See vec2_max_ptr instead.
| a | The first vector. |
| b | The second vector. |
Definition at line 253 of file vector2.c.
References vec2_max_ptr().
| vm_float_t vec2_max_component | ( | const vector2 | v | ) |
Returns the largest component.
| v | Input vector. |
Definition at line 825 of file vector2.c.
References VECMAT_FMAX, vector2::x, and vector2::y.
Returns the component-wise minimum of two vectors.
See vec2_min_ptr instead.
| a | The first vector. |
| b | The second vector. |
Definition at line 237 of file vector2.c.
References vec2_min_ptr().
| vm_float_t vec2_min_component | ( | const vector2 | v | ) |
Returns the smallest component.
| v | Input vector. |
Definition at line 814 of file vector2.c.
References VECMAT_FMIN, vector2::x, and vector2::y.
| vector2 vec2_move_toward | ( | const vector2 | current, |
| const vector2 | target, | ||
| const vm_float_t | max_delta ) |
Moves current toward target by at most max_delta.
See vec2_move_toward_ptr instead.
| current | Current position. |
| target | Target position. |
| max_delta | Maximum distance to move. |
Definition at line 699 of file vector2.c.
References vec2_move_toward_ptr().
Multiplies two vectors component-wise (Hadamard product).
See vec2_mul_ptr instead.
| a | The first vector. |
| b | The second vector. |
Definition at line 160 of file vector2.c.
References vec2_mul_ptr().
| vector2 vec2_mul_scalar | ( | const vector2 | v, |
| const vm_float_t | s ) |
Multiplies a vector by a scalar component-wise.
See vec2_mul_scalar_ptr instead.
| v | The input vector. |
| s | The scalar multiplier. |
Definition at line 128 of file vector2.c.
References vec2_mul_scalar_ptr().
| bool vec2_near | ( | const vector2 | a, |
| const vector2 | b, | ||
| const vm_float_t | eps ) |
Returns true if a and b are within eps of each other.
| a | First input vector. |
| b | Second input vector. |
| eps | Distance tolerance. |
Definition at line 871 of file vector2.c.
References VECMAT_FABS, vector2::x, and vector2::y.
Negates the vector (multiplies each component by -1.0f).
See vec2_neg_ptr instead.
| v | The input vector. |
Definition at line 175 of file vector2.c.
References vec2_neg_ptr().
Normalizes the vector to unit length.
See vec2_normalize_ptr instead.
| v | The input vector. |
Definition at line 221 of file vector2.c.
References vec2_normalize_ptr().
| vector2 vec2_one | ( | void | ) |
Returns the perpendicular vector (90 degrees counterclockwise).
See vec2_perpendicular_ptr instead.
| v | The input vector. |
Definition at line 329 of file vector2.c.
References vec2_perpendicular_ptr().
Projects the first vector onto the second.
See vec2_project_ptr instead.
| a | The vector to project. |
| b | The projection direction vector. |
Definition at line 361 of file vector2.c.
References vec2_project_ptr().
Reflects vector v across the normal, storing the result in res.
See vec2_reflect_ptr instead.
| v | The incident vector. |
| normal | The unit normal vector. |
Definition at line 345 of file vector2.c.
References vec2_reflect_ptr().
| vector2 vec2_refract | ( | const vector2 | incident, |
| const vector2 | normal, | ||
| const vm_float_t | eta ) |
Computes the refraction of incident across normal with ratio eta.
See vec2_refract_ptr instead.
| incident | Incident vector. |
| normal | Surface normal. |
| eta | Ratio of indices of refraction. |
Definition at line 623 of file vector2.c.
References vec2_refract_ptr().
Returns the component of a orthogonal to b.
See vec2_reject_ptr instead.
| a | First input vector. |
| b | Second input vector. |
Definition at line 639 of file vector2.c.
References vec2_reject_ptr().
| vector2 vec2_rotate | ( | const vector2 | v, |
| const vm_float_t | angle ) |
Rotates the input vector counterclockwise by the given angle (radians).
See vec2_rotate_ptr instead.
| v | The input vector. |
| angle | The rotation angle in radians. |
Definition at line 392 of file vector2.c.
References vec2_rotate_ptr().
| vector2 vec2_rotate_around | ( | const vector2 | v, |
| const vector2 | pivot, | ||
| const vm_float_t | angle ) |
Rotates v around pivot by angle radians.
See vec2_rotate_around_ptr instead.
| v | Input vector. |
| pivot | Rotation pivot. |
| angle | Angle in radians. |
Definition at line 682 of file vector2.c.
References vec2_rotate_around_ptr().
Applies round to each component.
See vec2_round_ptr instead.
| v | The input vector. |
Definition at line 313 of file vector2.c.
References vec2_round_ptr().
Clamps each component to the range [0, 1].
See vec2_saturate_ptr instead.
| v | Input vector. |
Definition at line 591 of file vector2.c.
References vec2_saturate_ptr().
| vector2 vec2_scale | ( | const vector2 | v, |
| const vm_float_t | s ) |
Scales a vector by a scalar component-wise.
See vec2_scale_ptr instead.
| v | The input vector. |
| s | The scalar multiplier. |
Definition at line 80 of file vector2.c.
References vec2_scale_ptr().
Returns the sign of each component (+1.0f, -1.0f, or 0.0f).
See vec2_sign_ptr instead.
| v | The input vector. |
Definition at line 268 of file vector2.c.
References vec2_sign_ptr().
Slides the input vector tangent to the normal (removes normal component).
See vec2_slide_ptr instead.
| v | The input vector. |
| normal | The unit normal vector. |
Definition at line 408 of file vector2.c.
References vec2_slide_ptr().
| vector2 vec2_splat | ( | const vm_float_t | s | ) |
Subtracts the second vector from the first component-wise.
See vec2_sub_ptr instead.
| a | The first vector. |
| b | The second vector. |
Definition at line 112 of file vector2.c.
References vec2_sub_ptr().
| vector2 vec2_sub_scalar | ( | const vector2 | v, |
| const vm_float_t | s ) |
Subtracts a scalar from each component.
See vec2_sub_scalar_ptr instead.
| v | Input vector. |
| s | Scalar value. |
Definition at line 559 of file vector2.c.
References vec2_sub_scalar_ptr().
| vm_float_t vec2_sum | ( | const vector2 | v | ) |
Returns the sum of all components.
| v | Input vector. |
Definition at line 836 of file vector2.c.
References vector2::x, and vector2::y.
Returns the tangent vector perpendicular to the input (90 degrees clockwise).
See vec2_tangent_ptr instead.
| v | The input vector. |
Definition at line 376 of file vector2.c.
References vec2_tangent_ptr().
| vector3 vec2_to_vec3 | ( | const vector2 | v, |
| const vm_float_t | z ) |
Converts a vector2 to a vector3 using z.
See vec2_to_vec3_ptr instead.
| v | Input vector. |
| z | Z component. |
Definition at line 731 of file vector2.c.
References vec2_to_vec3_ptr().
| vector2 vec2_x_axis | ( | const vm_float_t | x | ) |
| vector2 vec2_x_scale | ( | const vm_float_t | x | ) |
| vector2 vec2_y_axis | ( | const vm_float_t | y | ) |
| vector2 vec2_y_scale | ( | const vm_float_t | y | ) |