|
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 | |
| vector3 | vec3_zero (void) |
| Returns a zero-initialized vector3. | |
| vector3 | vec3_one (void) |
| Returns a vector3 with all components set to 1.0f. | |
| vector3 | vec3_x_axis (const vm_float_t x) |
| Returns a vector3 along the x-axis. | |
| vector3 | vec3_y_axis (const vm_float_t y) |
| Returns a vector3 along the y-axis. | |
| vector3 | vec3_z_axis (const vm_float_t z) |
| Returns a vector3 along the z-axis. | |
| vector3 | vec3_x_scale (const vm_float_t x) |
| Returns a vector3 for scaling along the x-axis. | |
| vector3 | vec3_y_scale (const vm_float_t y) |
| Returns a vector3 for scaling along the y-axis. | |
| vector3 | vec3_z_scale (const vm_float_t z) |
| Returns a vector3 for scaling along the z-axis. | |
| vector3 | vec3_add (const vector3 a, const vector3 b) |
| Component-wise addition of two vectors. | |
| vector3 | vec3_sub (const vector3 a, const vector3 b) |
| Component-wise subtraction of two vectors. | |
| vector3 | vec3_mul_scalar (const vector3 v, const vm_float_t s) |
| Component-wise multiplication of vector by scalar. | |
| vector3 | vec3_div_scalar (const vector3 v, const vm_float_t s) |
| Component-wise division of vector by scalar. | |
| vector3 | vec3_mul (const vector3 a, const vector3 b) |
| Component-wise multiplication of two vectors. | |
| vector3 | vec3_neg (const vector3 v) |
| Negation of a vector. | |
| vector3 | vec3_abs (const vector3 v) |
| Computes the absolute value per component of a vector3. | |
| vector3 | vec3_cross (const vector3 a, const vector3 b) |
| Computes the cross-product of two vector3. | |
| vector3 | vec3_normalize (const vector3 v) |
| Normalizes a vector3 to unit length. | |
| vector3 | vec3_min (const vector3 a, const vector3 b) |
| Computes the component-wise minimum of two vector3. | |
| vector3 | vec3_max (const vector3 a, const vector3 b) |
| Computes the component-wise maximum of two vector3. | |
| vector3 | vec3_sign (const vector3 v) |
| Computes the sign per component of a vector3 (-1, 0, or 1). | |
| vector3 | vec3_floor (const vector3 v) |
| Applies the floor per component to a vector3. | |
| vector3 | vec3_ceil (const vector3 v) |
| Applies ceil per component to a vector3. | |
| vector3 | vec3_round (const vector3 v) |
| Applies round per component to a vector3. | |
| vector3 | vec3_reflect (const vector3 incident, const vector3 normal) |
| Reflects an incident vector over normal. | |
| vector3 | vec3_refract (const vector3 incident, const vector3 normal, const vm_float_t eta) |
| Refracts an incident vector across an interface with a given normal and ratio of refraction eta. | |
| vector3 | vec3_lerp (const vector3 a, const vector3 b, const vm_float_t t) |
| Linearly interpolates between two vector3. | |
| vector3 | vec3_clamp (const vector3 v, const vector3 min, const vector3 max) |
| Clamps a vector3 between min and max per component. | |
| vm_float_t | vec3_distance (const vector3 a, const vector3 b) |
| Computes the Euclidean distance between two vector3. | |
| vm_float_t | vec3_angle (const vector3 a, const vector3 b) |
| Computes the angle between two non-zero vector3 in radians. | |
| vm_float_t | vec3_dot (const vector3 a, const vector3 b) |
| Computes the dot product of two vector3. | |
| vm_float_t | vec3_length (const vector3 v) |
| Computes the length (magnitude) of a vector3. | |
| vector3 | vec3_scale (const vector3 v, const vm_float_t s) |
| Scales the vector by a scalar. | |
| vector3 | vec3_div (const vector3 a, const vector3 b) |
| Divides two vectors component-wise. | |
| vector3 | vec3_add_scalar (const vector3 v, const vm_float_t s) |
| Adds a scalar to each component. | |
| vector3 | vec3_sub_scalar (const vector3 v, const vm_float_t s) |
| Subtracts a scalar from each component. | |
| vector3 | vec3_clamp_scalar (const vector3 v, const vm_float_t min, const vm_float_t max) |
| Clamps each component to the scalar range [min, max]. | |
| vector3 | vec3_saturate (const vector3 v) |
| Clamps each component to the range [0, 1]. | |
| vector3 | vec3_fract (const vector3 v) |
| Returns the fractional part of each component. | |
| vector3 | vec3_project (const vector3 a, const vector3 b) |
| Projects a onto b. | |
| vector3 | vec3_slide (const vector3 v, const vector3 normal) |
| Removes the component of v along normal. | |
| vector3 | vec3_reject (const vector3 a, const vector3 b) |
| Returns the component of a orthogonal to b. | |
| vector3 | vec3_rotate_axis (const vector3 v, const vector3 axis, const vm_float_t angle) |
| Rotates v around axis by angle radians. | |
| vector3 | vec3_splat (const vm_float_t s) |
| Returns a vector with every component set to s. | |
| vector3 | vec3_from_vec2 (const vector2 v, const vm_float_t z) |
| Builds a vector3 from a vector2 and z. | |
| vector3 | vec3_move_toward (const vector3 current, const vector3 target, const vm_float_t max_delta) |
| Moves current toward target by at most max_delta. | |
| vector3 | vec3_limit_length (const vector3 v, const vm_float_t max_len) |
| Clamps the vector length to max_len. | |
| vector2 | vec3_xy (const vector3 v) |
| Returns the x and y components as a 2D vector. | |
| void | vec3_orthonormal_basis (const vector3 n, vector3 *t, vector3 *b) |
| Builds a tangent and bitangent orthonormal to n. | |
| vm_float_t | vec3_length_squared (const vector3 v) |
| Returns the squared Euclidean length. | |
| vm_float_t | vec3_length_manhattan (const vector3 v) |
| Returns the Manhattan (L1) length. | |
| vm_float_t | vec3_length_chebyshev (const vector3 v) |
| Returns the Chebyshev (L-inf) length. | |
| vm_float_t | vec3_distance_squared (const vector3 a, const vector3 b) |
| Returns the squared Euclidean distance between a and b. | |
| vm_float_t | vec3_signed_angle (const vector3 a, const vector3 b, const vector3 axis) |
| Returns the signed angle from a to b around axis. | |
| vm_float_t | vec3_min_component (const vector3 v) |
| Returns the smallest component. | |
| vm_float_t | vec3_max_component (const vector3 v) |
| Returns the largest component. | |
| vm_float_t | vec3_sum (const vector3 v) |
| Returns the sum of all components. | |
| bool | vec3_is_zero (const vector3 v) |
| Returns true if every component is zero. | |
| bool | vec3_is_normalized (const vector3 v) |
| Returns true if the vector has unit length. | |
| bool | vec3_near (const vector3 a, const vector3 b, const vm_float_t eps) |
| Returns true if a and b are within eps of each other. | |
Computes the absolute value per component of a vector3.
See vec3_abs_ptr for the out-parameter version.
| v | The vector. |
Definition at line 196 of file vector3.c.
References vec3_abs_ptr().
Component-wise addition of two vectors.
See vec3_add_ptr for the out-parameter version.
| a | First vector. |
| b | Second vector. |
Definition at line 102 of file vector3.c.
References vec3_add_ptr().
| vector3 vec3_add_scalar | ( | const vector3 | v, |
| const vm_float_t | s ) |
Adds a scalar to each component.
See vec3_add_scalar_ptr instead.
| v | Input vector. |
| s | Scalar value. |
Definition at line 485 of file vector3.c.
References vec3_add_scalar_ptr().
| vm_float_t vec3_angle | ( | const vector3 | a, |
| const vector3 | b ) |
Computes the angle between two non-zero vector3 in radians.
| a | First vector. |
| b | Second vector. |
Definition at line 413 of file vector3.c.
References vec3_dot(), vec3_length(), and VECMAT_ACOS.
Applies ceil per component to a vector3.
See vec3_ceil_ptr for the out-parameter version.
| v | The vector. |
Definition at line 304 of file vector3.c.
References vec3_ceil_ptr().
Clamps a vector3 between min and max per component.
See vec3_clamp_ptr for the out-parameter version.
| v | The vector. |
| min | Minimum bounds. |
| max | Maximum bounds. |
Definition at line 387 of file vector3.c.
References vec3_clamp_ptr().
| vector3 vec3_clamp_scalar | ( | const vector3 | v, |
| const vm_float_t | min, | ||
| const vm_float_t | max ) |
Clamps each component to the scalar range [min, max].
See vec3_clamp_scalar_ptr instead.
| v | Input vector. |
| min | Lower bound. |
| max | Upper bound. |
Definition at line 518 of file vector3.c.
References vec3_clamp_scalar_ptr().
Computes the cross-product of two vector3.
See vec3_cross_ptr for the out-parameter version.
| a | First vector. |
| b | Second vector. |
Definition at line 212 of file vector3.c.
References vec3_cross_ptr().
Referenced by mat4_look_at_ptr(), and vec3_signed_angle().
| vm_float_t vec3_distance | ( | const vector3 | a, |
| const vector3 | b ) |
Computes the Euclidean distance between two vector3.
| a | First vector. |
| b | Second vector. |
Definition at line 401 of file vector3.c.
References vec3_length(), and vec3_sub().
| vm_float_t vec3_distance_squared | ( | const vector3 | a, |
| const vector3 | b ) |
Returns the squared Euclidean distance between a and b.
| a | First input vector. |
| b | Second input vector. |
Definition at line 749 of file vector3.c.
References vector3::x, vector3::y, and vector3::z.
Divides two vectors component-wise.
See vec3_div_ptr instead.
| a | First input vector. |
| b | Second input vector. |
Definition at line 469 of file vector3.c.
References vec3_div_ptr().
| vector3 vec3_div_scalar | ( | const vector3 | v, |
| const vm_float_t | s ) |
Component-wise division of vector by scalar.
See vec3_div_scalar_ptr for the out-parameter version.
| v | The vector. |
| s | The scalar (non-zero). |
Definition at line 150 of file vector3.c.
References vec3_div_scalar_ptr().
| vm_float_t vec3_dot | ( | const vector3 | a, |
| const vector3 | b ) |
Computes the dot product of two vector3.
| a | First vector. |
| b | Second vector. |
Definition at line 428 of file vector3.c.
References vector3::x, vector3::y, and vector3::z.
Referenced by mat4_look_at_ptr(), vec3_angle(), vec3_length(), vec3_length_squared(), vec3_project_ptr(), vec3_reflect_ptr(), vec3_refract_ptr(), vec3_rotate_axis_ptr(), vec3_signed_angle(), and vec3_slide_ptr().
Applies the floor per component to a vector3.
See vec3_floor_ptr for the out-parameter version.
| v | The vector. |
Definition at line 289 of file vector3.c.
References vec3_floor_ptr().
Returns the fractional part of each component.
See vec3_fract_ptr instead.
| v | Input vector. |
Definition at line 548 of file vector3.c.
References vec3_fract_ptr().
| vector3 vec3_from_vec2 | ( | const vector2 | v, |
| const vm_float_t | z ) |
Builds a vector3 from a vector2 and z.
See vec3_from_vec2_ptr instead.
| v | Input vector. |
| z | Z component. |
Definition at line 642 of file vector3.c.
References vec3_from_vec2_ptr().
| bool vec3_is_normalized | ( | const vector3 | v | ) |
Returns true if the vector has unit length.
| v | Input vector. |
Definition at line 823 of file vector3.c.
References vec3_length_squared(), VECMAT_EPSILON, and VECMAT_FABS.
| bool vec3_is_zero | ( | const vector3 | v | ) |
Returns true if every component is zero.
| v | Input vector. |
Definition at line 810 of file vector3.c.
References VECMAT_EPSILON, VECMAT_FABS, vector3::x, vector3::y, and vector3::z.
| vm_float_t vec3_length | ( | const vector3 | v | ) |
Computes the length (magnitude) of a vector3.
| v | The vector. |
Definition at line 439 of file vector3.c.
References vec3_dot(), and VECMAT_SQRT.
Referenced by vec3_angle(), vec3_distance(), vec3_limit_length_ptr(), and vec3_normalize_ptr().
| vm_float_t vec3_length_chebyshev | ( | const vector3 | v | ) |
Returns the Chebyshev (L-inf) length.
| v | Input vector. |
Definition at line 737 of file vector3.c.
References VECMAT_FABS, VECMAT_FMAX, vector3::x, vector3::y, and vector3::z.
| vm_float_t vec3_length_manhattan | ( | const vector3 | v | ) |
Returns the Manhattan (L1) length.
| v | Input vector. |
Definition at line 726 of file vector3.c.
References VECMAT_FABS, vector3::x, vector3::y, and vector3::z.
| vm_float_t vec3_length_squared | ( | const vector3 | v | ) |
Returns the squared Euclidean length.
| v | Input vector. |
Definition at line 715 of file vector3.c.
References vec3_dot().
Referenced by vec3_is_normalized().
| vector3 vec3_lerp | ( | const vector3 | a, |
| const vector3 | b, | ||
| const vm_float_t | t ) |
Linearly interpolates between two vector3.
See vec3_lerp_ptr for the out-parameter version.
| a | Start vector. |
| b | End vector. |
| t | Interpolation factor [0, 1]. |
Definition at line 370 of file vector3.c.
References vec3_lerp_ptr().
| vector3 vec3_limit_length | ( | const vector3 | v, |
| const vm_float_t | max_len ) |
Clamps the vector length to max_len.
See vec3_limit_length_ptr instead.
| v | Input vector. |
| max_len | Maximum length. |
Definition at line 675 of file vector3.c.
References vec3_limit_length_ptr().
Computes the component-wise maximum of two vector3.
See vec3_max_ptr for the out-parameter version.
| a | First vector. |
| b | Second vector. |
Definition at line 259 of file vector3.c.
References vec3_max_ptr().
| vm_float_t vec3_max_component | ( | const vector3 | v | ) |
Returns the largest component.
| v | Input vector. |
Definition at line 788 of file vector3.c.
References VECMAT_FMAX, vector3::x, vector3::y, and vector3::z.
Computes the component-wise minimum of two vector3.
See vec3_min_ptr for the out-parameter version.
| a | First vector. |
| b | Second vector. |
Definition at line 243 of file vector3.c.
References vec3_min_ptr().
| vm_float_t vec3_min_component | ( | const vector3 | v | ) |
Returns the smallest component.
| v | Input vector. |
Definition at line 777 of file vector3.c.
References VECMAT_FMIN, vector3::x, vector3::y, and vector3::z.
| vector3 vec3_move_toward | ( | const vector3 | current, |
| const vector3 | target, | ||
| const vm_float_t | max_delta ) |
Moves current toward target by at most max_delta.
See vec3_move_toward_ptr instead.
| current | Current position. |
| target | Target position. |
| max_delta | Maximum distance to move. |
Definition at line 659 of file vector3.c.
References vec3_move_toward_ptr().
Component-wise multiplication of two vectors.
See vec3_mul_ptr for the out-parameter version.
| a | First vector. |
| b | Second vector. |
Definition at line 166 of file vector3.c.
References vec3_mul_ptr().
| vector3 vec3_mul_scalar | ( | const vector3 | v, |
| const vm_float_t | s ) |
Component-wise multiplication of vector by scalar.
See vec3_mul_scalar_ptr for the out-parameter version.
| v | The vector. |
| s | The scalar. |
Definition at line 134 of file vector3.c.
References vec3_mul_scalar_ptr().
| bool vec3_near | ( | const vector3 | a, |
| const vector3 | 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 836 of file vector3.c.
References VECMAT_FABS, vector3::x, vector3::y, and vector3::z.
Negation of a vector.
See vec3_neg_ptr for the out-parameter version.
| v | The vector. |
Definition at line 181 of file vector3.c.
References vec3_neg_ptr().
Normalizes a vector3 to unit length.
See vec3_normalize_ptr for the out-parameter version.
| v | The vector (non-zero). |
Definition at line 227 of file vector3.c.
References vec3_normalize_ptr().
Referenced by mat4_look_at_ptr(), mat4_rotation_ptr(), and quat_from_axis_angle_ptr().
| vector3 vec3_one | ( | void | ) |
Builds a tangent and bitangent orthonormal to n.
| n | Unit normal. |
| t | Output tangent. |
| b | Output bitangent. |
Definition at line 704 of file vector3.c.
References vec3_orthonormal_basis_ptr().
Projects a onto b.
See vec3_project_ptr instead.
| a | First input vector. |
| b | Second input vector. |
Definition at line 564 of file vector3.c.
References vec3_project_ptr().
Reflects an incident vector over normal.
See vec3_reflect_ptr for the out-parameter version.
| incident | The incident vector. |
| normal | The surface normal. |
Definition at line 335 of file vector3.c.
References vec3_reflect_ptr().
| vector3 vec3_refract | ( | const vector3 | incident, |
| const vector3 | normal, | ||
| const vm_float_t | eta ) |
Refracts an incident vector across an interface with a given normal and ratio of refraction eta.
See vec3_refract_ptr for the out-parameter version.
| incident | The incident vector. |
| normal | The surface normal. |
| eta | The ratio of refraction (eta = n1 / n2). |
Definition at line 353 of file vector3.c.
References vec3_refract_ptr().
Returns the component of a orthogonal to b.
See vec3_reject_ptr instead.
| a | First input vector. |
| b | Second input vector. |
Definition at line 596 of file vector3.c.
References vec3_reject_ptr().
| vector3 vec3_rotate_axis | ( | const vector3 | v, |
| const vector3 | axis, | ||
| const vm_float_t | angle ) |
Rotates v around axis by angle radians.
See vec3_rotate_axis_ptr instead.
| v | Input vector. |
| axis | Rotation axis. |
| angle | Angle in radians. |
Definition at line 613 of file vector3.c.
References vec3_rotate_axis_ptr().
Applies round per component to a vector3.
See vec3_round_ptr for the out-parameter version.
| v | The vector. |
Definition at line 319 of file vector3.c.
References vec3_round_ptr().
Clamps each component to the range [0, 1].
See vec3_saturate_ptr instead.
| v | Input vector. |
Definition at line 533 of file vector3.c.
References vec3_saturate_ptr().
| vector3 vec3_scale | ( | const vector3 | v, |
| const vm_float_t | s ) |
Scales the vector by a scalar.
See vec3_scale_ptr instead.
| v | Input vector. |
| s | Scalar value. |
Definition at line 453 of file vector3.c.
References vec3_scale_ptr().
Computes the sign per component of a vector3 (-1, 0, or 1).
See vec3_sign_ptr for the out-parameter version.
| v | The vector. |
Definition at line 274 of file vector3.c.
References vec3_sign_ptr().
| vm_float_t vec3_signed_angle | ( | const vector3 | a, |
| const vector3 | b, | ||
| const vector3 | axis ) |
Returns the signed angle from a to b around axis.
| a | First input vector. |
| b | Second input vector. |
| axis | Rotation axis. |
Definition at line 765 of file vector3.c.
References vec3_cross(), vec3_dot(), and VECMAT_ATAN2.
Removes the component of v along normal.
See vec3_slide_ptr instead.
| v | Input vector. |
| normal | Surface normal. |
Definition at line 580 of file vector3.c.
References vec3_slide_ptr().
| vector3 vec3_splat | ( | const vm_float_t | s | ) |
Component-wise subtraction of two vectors.
See vec3_sub_ptr for the out-parameter version.
| a | First vector. |
| b | Second vector. |
Definition at line 118 of file vector3.c.
References vec3_sub_ptr().
Referenced by mat4_look_at_ptr(), and vec3_distance().
| vector3 vec3_sub_scalar | ( | const vector3 | v, |
| const vm_float_t | s ) |
Subtracts a scalar from each component.
See vec3_sub_scalar_ptr instead.
| v | Input vector. |
| s | Scalar value. |
Definition at line 501 of file vector3.c.
References vec3_sub_scalar_ptr().
| vm_float_t vec3_sum | ( | const vector3 | v | ) |
Returns the sum of all components.
| v | Input vector. |
Definition at line 799 of file vector3.c.
References vector3::x, vector3::y, and vector3::z.
| vector3 vec3_x_axis | ( | const vm_float_t | x | ) |
| vector3 vec3_x_scale | ( | const vm_float_t | x | ) |
Returns the x and y components as a 2D vector.
See vec3_xy_ptr instead.
| v | Input vector. |
Definition at line 690 of file vector3.c.
References vec3_xy_ptr().
| vector3 vec3_y_axis | ( | const vm_float_t | y | ) |
| vector3 vec3_y_scale | ( | const vm_float_t | y | ) |
| vector3 vec3_z_axis | ( | const vm_float_t | z | ) |
| vector3 vec3_z_scale | ( | const vm_float_t | z | ) |