|
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 | |
| 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 a onto vector b (scalar projection scaled by b). | |
| 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 angle) |
| Rotates the input vector counterclockwise by the given angle (radians). | |
| 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 angle) |
| Rotates v around pivot by angle radians. | |
| 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. | |
Computes the absolute values of the components of vector v, storing the result in res.
| res | Output vector. |
| v | Input vector. |
Definition at line 95 of file vector2_ptr.c.
References VECMAT_FABS, vector2::x, and vector2::y.
Referenced by vec2_abs().
Adds vectors a and b component-wise, storing the result in res.
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
Definition at line 14 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_add().
| void vec2_add_scalar_ptr | ( | vector2 * | res, |
| const vector2 * | v, | ||
| const vm_float_t | s ) |
Adds a scalar to each component.
| res | Output vector. |
| v | Input vector. |
| s | Scalar value. |
Definition at line 371 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_add_scalar().
Applies the ceil function to each component of vector v, storing the result in res.
| res | Output vector. |
| v | Input vector. |
Definition at line 180 of file vector2_ptr.c.
References VECMAT_CEIL, vector2::x, and vector2::y.
Referenced by vec2_ceil().
Clamps vector v component-wise between min and max.
| res | Output vector. |
| v | Input vector to clamp. |
| min | Minimum bounds vector. |
| max | Maximum bounds vector. |
Definition at line 331 of file vector2_ptr.c.
References VECMAT_FMAX, VECMAT_FMIN, vector2::x, and vector2::y.
Referenced by vec2_clamp().
| 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].
| res | Output vector. |
| v | Input vector. |
| min | Lower bound. |
| max | Upper bound. |
Definition at line 398 of file vector2_ptr.c.
References VECMAT_FMAX, VECMAT_FMIN, vector2::x, and vector2::y.
Referenced by vec2_clamp_scalar(), and vec2_saturate_ptr().
Computes the 2D cross-product of a and b, storing the scalar value in res->x and 0 in res->y.
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
Definition at line 220 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_cross().
Divides two vectors component-wise.
| res | Output vector. |
| a | First input vector. |
| b | Second input vector. |
Definition at line 358 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_div().
| 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.
| res | Output vector. |
| v | Input vector. |
| s | Input scalar. |
Definition at line 53 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_div_scalar().
Applies the floor function to each component of vector v, storing the result in res.
| res | Output vector. |
| v | Input vector. |
Definition at line 167 of file vector2_ptr.c.
References VECMAT_FLOOR, vector2::x, and vector2::y.
Referenced by vec2_floor().
Returns the fractional part of each component.
| res | Output vector. |
| v | Input vector. |
Definition at line 421 of file vector2_ptr.c.
References VECMAT_FLOOR, vector2::x, and vector2::y.
Referenced by vec2_fract().
| 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.
| res | Output vector. |
| a | First input vector. |
| b | Second input vector. |
| t | Interpolation factor. |
Definition at line 345 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_lerp().
| void vec2_limit_length_ptr | ( | vector2 * | res, |
| const vector2 * | v, | ||
| const vm_float_t | max_len ) |
Clamps the vector length to max_len.
| res | Output vector. |
| v | Input vector. |
| max_len | Maximum length. |
Definition at line 511 of file vector2_ptr.c.
References vec2_length(), vector2::x, and vector2::y.
Referenced by vec2_limit_length().
Computes the component-wise maximum of vectors a and b, storing the result in res.
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
Definition at line 141 of file vector2_ptr.c.
References VECMAT_FMAX, vector2::x, and vector2::y.
Referenced by vec2_max().
Computes the component-wise minimum of vectors a and b, storing the result in res.
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
Definition at line 127 of file vector2_ptr.c.
References VECMAT_FMIN, vector2::x, and vector2::y.
Referenced by vec2_min().
| 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.
| res | Output vector. |
| current | Current position. |
| target | Target position. |
| max_delta | Maximum distance to move. |
Definition at line 490 of file vector2_ptr.c.
References VECMAT_SQRT, vector2::x, and vector2::y.
Referenced by vec2_move_toward().
Multiplies vectors a and b component-wise, storing the result in res.
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
Definition at line 70 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_mul().
| 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.
| res | Output vector. |
| v | Input vector. |
| s | Input scalar. |
Definition at line 40 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_mul_scalar().
Negates the components of vector v, storing the result in res.
| res | Output vector. |
| v | Input vector. |
Definition at line 82 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_neg().
Normalizes vector v to unit length, storing the result in res.
| res | Output vector. |
| v | Input vector. |
Definition at line 107 of file vector2_ptr.c.
References vec2_length(), vector2::x, and vector2::y.
Referenced by vec2_normalize(), and vec2i_normalize_to_vec2_ptr().
Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in res.
| res | Output vector. |
| v | Input vector. |
Definition at line 206 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_perpendicular().
Projects vector a onto vector b (scalar projection scaled by b).
| res | The output projected vector. |
| a | The vector to project. |
| b | The direction vector (non-zero length recommended). |
Definition at line 261 of file vector2_ptr.c.
References vec2_dot(), vector2::x, and vector2::y.
Referenced by vec2_project(), and vec2_reject_ptr().
Reflects vector v across the normal, storing the result in res.
| res | Output vector. |
| v | Input incident vector. |
| normal | Input surface normal. |
Definition at line 247 of file vector2_ptr.c.
References vec2_dot(), vector2::x, and vector2::y.
Referenced by vec2_reflect().
| 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.
| res | Output vector. |
| incident | Incident vector. |
| normal | Surface normal. |
| eta | Ratio of indices of refraction. |
Definition at line 435 of file vector2_ptr.c.
References vec2_dot(), VECMAT_SQRT, vector2::x, and vector2::y.
Referenced by vec2_refract().
Returns the component of a orthogonal to b.
| res | Output vector. |
| a | First input vector. |
| b | Second input vector. |
Definition at line 456 of file vector2_ptr.c.
References vec2_project_ptr(), vector2::x, and vector2::y.
Referenced by vec2_reject().
| void vec2_rotate_around_ptr | ( | vector2 * | res, |
| const vector2 * | v, | ||
| const vector2 * | pivot, | ||
| const vm_float_t | angle ) |
Rotates v around pivot by angle radians.
| res | Output vector. |
| v | Input vector. |
| pivot | Rotation pivot. |
| angle | Angle in radians. |
Definition at line 472 of file vector2_ptr.c.
References vec2_rotate_ptr(), vector2::x, and vector2::y.
Referenced by vec2_rotate_around().
| void vec2_rotate_ptr | ( | vector2 * | result, |
| const vector2 * | v, | ||
| const vm_float_t | angle ) |
Rotates the input vector counterclockwise by the given angle (radians).
Uses standard 2D rotation matrix.
| result | The output rotated vector. |
| v | The input vector. |
| angle | The rotation angle in radians. |
Definition at line 297 of file vector2_ptr.c.
References VECMAT_COS, VECMAT_SIN, vector2::x, and vector2::y.
Referenced by vec2_rotate(), and vec2_rotate_around_ptr().
Applies the round function to each component of vector v, storing the result in res.
| res | Output vector. |
| v | Input vector. |
Definition at line 193 of file vector2_ptr.c.
References VECMAT_ROUND, vector2::x, and vector2::y.
Referenced by vec2_round().
Clamps each component to the range [0, 1].
| res | Output vector. |
| v | Input vector. |
Definition at line 410 of file vector2_ptr.c.
References vec2_clamp_scalar_ptr().
Referenced by vec2_saturate().
| 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.
| res | Output vector. |
| v | Input vector. |
| s | Input scalar. |
Definition at line 234 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_scale().
Sets each component of res to the sign of the corresponding component in v (+1, -1).
| res | Output vector. |
| v | Input vector. |
Definition at line 154 of file vector2_ptr.c.
References VECMAT_COPYSIGN, vector2::x, and vector2::y.
Referenced by vec2_sign().
Slides the input vector tangent to the normal (removes normal component).
Formula: v - dot(v, normal) * normal (assumes unit normal).
| result | The output slid vector. |
| v | The input vector. |
| normal | The unit normal vector. |
Definition at line 316 of file vector2_ptr.c.
References vec2_dot(), vector2::x, and vector2::y.
Referenced by vec2_slide().
Subtracts vector b from vector a component-wise, storing the result in res.
| res | Output vector. |
| a | Input vector a. |
| b | Input vector b. |
Definition at line 27 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_sub().
| void vec2_sub_scalar_ptr | ( | vector2 * | res, |
| const vector2 * | v, | ||
| const vm_float_t | s ) |
Subtracts a scalar from each component.
| res | Output vector. |
| v | Input vector. |
| s | Scalar value. |
Definition at line 384 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_sub_scalar().
Computes a tangent vector perpendicular to the input (90 degrees clockwise).
Equivalent to (v.y, -v.x).
| res | The output tangent vector. |
| v | The input vector. |
Definition at line 282 of file vector2_ptr.c.
References vector2::x, and vector2::y.
Referenced by vec2_tangent().
| 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.
| res | Output vector. |
| v | Input vector. |
| z | Z component. |
Definition at line 530 of file vector2_ptr.c.
References vector2::x, vector3::x, vector2::y, vector3::y, and vector3::z.
Referenced by vec2_to_vec3().