vector4.c file
Functions
- auto vec4_zero(void) -> vector4
- Returns a zero-initialized
vector4. - auto vec4_one(void) -> vector4
- Returns a
vector4with all components set to 1.0f. -
auto vec4_x_axis(const vm_
float_ t x) -> vector4 - Returns a
vector4along the x-axis. -
auto vec4_y_axis(const vm_
float_ t y) -> vector4 - Returns a
vector4along the y-axis. -
auto vec4_z_axis(const vm_
float_ t z) -> vector4 - Returns a
vector4along the z-axis. -
auto vec4_w_axis(const vm_
float_ t w) -> vector4 - Returns a
vector4along the w-axis. -
auto vec4_x_scale(const vm_
float_ t x) -> vector4 - Returns a
vector4for scaling along the x-axis. -
auto vec4_y_scale(const vm_
float_ t y) -> vector4 - Returns a
vector4for scaling along the y-axis. -
auto vec4_z_scale(const vm_
float_ t z) -> vector4 - Returns a
vector4for scaling along the z-axis. -
auto vec4_w_scale(const vm_
float_ t w) -> vector4 - Returns a vector4 for scaling along the w-axis.
- auto vec4_add(const vector4 a, const vector4 b) -> vector4
- Component-wise addition of two vectors.
- auto vec4_sub(const vector4 a, const vector4 b) -> vector4
- Component-wise subtraction of two vectors.
-
auto vec4_mul_scalar(const vector4 v,
const vm_
float_ t s) -> vector4 - Component-wise multiplication of vector by scalar.
-
auto vec4_div_scalar(const vector4 v,
const vm_
float_ t s) -> vector4 - Component-wise division of vector by scalar.
- auto vec4_mul(const vector4 a, const vector4 b) -> vector4
- Component-wise multiplication of two vectors.
- auto vec4_neg(const vector4 v) -> vector4
- Negation of a vector.
- auto vec4_abs(const vector4 v) -> vector4
- Computes the absolute value per component of a
vector4. - auto vec4_normalize(const vector4 v) -> vector4
- Normalizes a
vector4to unit length. - auto vec4_min(const vector4 a, const vector4 b) -> vector4
- Computes the component-wise minimum of two
vector4. - auto vec4_max(const vector4 a, const vector4 b) -> vector4
- Computes the component-wise maximum of two
vector4. - auto vec4_sign(const vector4 v) -> vector4
- Computes the sign per component of a
vector4(-1, 0, or 1). - auto vec4_floor(const vector4 v) -> vector4
- Applies the floor per component to a
vector4. - auto vec4_ceil(const vector4 v) -> vector4
- Applies ceil per component to a
vector4. - auto vec4_round(const vector4 v) -> vector4
- Applies round per component to a
vector4. -
auto vec4_lerp(const vector4 a,
const vector4 b,
const vm_
float_ t t) -> vector4 - Linearly interpolates between two
vector4. - auto vec4_clamp(const vector4 v, const vector4 min, const vector4 max) -> vector4
- Clamps a
vector4between min and max per component. - auto vec4_homogenize(const vector4 v) -> vector4
- Homogenizes a
vector4(divides x, y, z by w). -
auto vec4_dot(const vector4 a,
const vector4 b) -> vm_
float_ t - Computes the dot product of two
vector4. -
auto vec4_length(const vector4 v) -> vm_
float_ t - Computes the length (magnitude) of a
vector4. -
auto vec4_distance(const vector4 a,
const vector4 b) -> vm_
float_ t - Computes the Euclidean distance between two
vector4. - auto vec4_to_vec3(const vector4 v) -> vector3
- Converts a
vector4to avector3(discards the w component). - auto vec4_div(const vector4 a, const vector4 b) -> vector4
- Divides two vectors component-wise.
-
auto vec4_add_scalar(const vector4 v,
const vm_
float_ t s) -> vector4 - Adds a scalar to each component.
-
auto vec4_sub_scalar(const vector4 v,
const vm_
float_ t s) -> vector4 - Subtracts a scalar from each component.
-
auto vec4_clamp_scalar(const vector4 v,
const vm_
float_ t min, const vm_ float_ t max) -> vector4 - Clamps each component to the scalar range [min, max].
- auto vec4_saturate(const vector4 v) -> vector4
- Clamps each component to the range [0, 1].
- auto vec4_fract(const vector4 v) -> vector4
- Returns the fractional part of each component.
- auto vec4_project(const vector4 a, const vector4 b) -> vector4
- Projects a onto b.
- auto vec4_reject(const vector4 a, const vector4 b) -> vector4
- Returns the component of a orthogonal to b.
- auto vec4_slide(const vector4 v, const vector4 normal) -> vector4
- Removes the component of v along normal.
-
auto vec4_splat(const vm_
float_ t s) -> vector4 - Returns a vector with every component set to s.
-
auto vec4_length_squared(const vector4 v) -> vm_
float_ t - Returns the squared Euclidean length.
-
auto vec4_distance_squared(const vector4 a,
const vector4 b) -> vm_
float_ t - Returns the squared Euclidean distance between a and b.
- auto vec4_is_zero(const vector4 v) -> bool
- Returns true if every component is zero.
- auto vec4_is_normalized(const vector4 v) -> bool
- Returns true if the vector has unit length.
-
auto vec4_near(const vector4 a,
const vector4 b,
const vm_
float_ t eps) -> bool - Returns true if a and b are within eps of each other.
Function documentation
vector4 vec4_x_axis(const vm_ float_ t x)
Returns a vector4 along the x-axis.
| Parameters | |
|---|---|
| x | The x component value. |
| Returns | A vector4 with (x, 0.0f, 0.0f, 0.0f). |
vector4 vec4_y_axis(const vm_ float_ t y)
Returns a vector4 along the y-axis.
| Parameters | |
|---|---|
| y | The y component value. |
| Returns | A vector4 with (0.0f, y, 0.0f, 0.0f). |
vector4 vec4_z_axis(const vm_ float_ t z)
Returns a vector4 along the z-axis.
| Parameters | |
|---|---|
| z | The z component value. |
| Returns | A vector4 with (0.0f, 0.0f, z, 0.0f). |
vector4 vec4_w_axis(const vm_ float_ t w)
Returns a vector4 along the w-axis.
| Parameters | |
|---|---|
| w | The w component value. |
| Returns | A vector4 with (0.0f, 0.0f, 0.0f, w). |
vector4 vec4_x_scale(const vm_ float_ t x)
Returns avector4 for scaling along the x-axis.
| Parameters | |
|---|---|
| x | The x scale factor. |
| Returns | A vector4 with (x, 1.0f, 1.0f, 1.0f). |
vector4 vec4_y_scale(const vm_ float_ t y)
Returns a vector4 for scaling along the y-axis.
| Parameters | |
|---|---|
| y | The y scale factor. |
| Returns | A vector4 with (1.0f, y, 1.0f, 1.0f). |
vector4 vec4_z_scale(const vm_ float_ t z)
Returns a vector4for scaling along the z-axis.
| Parameters | |
|---|---|
| z | The z scale factor. |
| Returns | A vector4 with (1.0f, 1.0f, z, 1.0f). |
vector4 vec4_w_scale(const vm_ float_ t w)
Returns a vector4 for scaling along the w-axis.
| Parameters | |
|---|---|
| w | The w scale factor. |
| Returns | A vector4 with (1.0f, 1.0f, 1.0f, w). |
vector4 vec4_mul_scalar(const vector4 v,
const vm_ float_ t s)
Component-wise multiplication of vector by scalar.
| Parameters | |
|---|---|
| v | The vector. |
| s | The scalar. |
| Returns | Result vector. |
vector4 vec4_div_scalar(const vector4 v,
const vm_ float_ t s)
Component-wise division of vector by scalar.
| Parameters | |
|---|---|
| v | The vector. |
| s | The scalar (non-zero). |
| Returns | Result vector. |
vector4 vec4_normalize(const vector4 v)
Normalizes a vector4 to unit length.
| Parameters | |
|---|---|
| v | The vector (non-zero). |
| Returns | The normalized vector. |
vector4 vec4_floor(const vector4 v)
Applies the floor per component to a vector4.
| Parameters | |
|---|---|
| v | The vector. |
| Returns | The floored vector. |
vector4 vec4_round(const vector4 v)
Applies round per component to a vector4.
| Parameters | |
|---|---|
| v | The vector. |
| Returns | The rounded vector. |
vector4 vec4_homogenize(const vector4 v)
Homogenizes a vector4 (divides x, y, z by w).
| Parameters | |
|---|---|
| v | The homogeneous vector (w != 0.0f). |
| Returns | The normalized cartesian vector4. |
vm_ float_ t vec4_dot(const vector4 a,
const vector4 b)
Computes the dot product of two vector4.
| Parameters | |
|---|---|
| a | First vector. |
| b | Second vector. |
| Returns | The dot product (a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w). |
vm_ float_ t vec4_length(const vector4 v)
Computes the length (magnitude) of a vector4.
| Parameters | |
|---|---|
| v | The vector. |
| Returns | The Euclidean length of v. |
vm_ float_ t vec4_distance(const vector4 a,
const vector4 b)
Computes the Euclidean distance between two vector4.
| Parameters | |
|---|---|
| a | First vector. |
| b | Second vector. |
| Returns | The distance between a and b. |
vector4 vec4_add_scalar(const vector4 v,
const vm_ float_ t s)
Adds a scalar to each component.
| Parameters | |
|---|---|
| v | Input vector. |
| s | Scalar value. |
| Returns | The resulting vector4. |
vector4 vec4_sub_scalar(const vector4 v,
const vm_ float_ t s)
Subtracts a scalar from each component.
| Parameters | |
|---|---|
| v | Input vector. |
| s | Scalar value. |
| Returns | The resulting vector4. |
vector4 vec4_clamp_scalar(const vector4 v,
const vm_ float_ t min,
const vm_ float_ t max)
Clamps each component to the scalar range [min, max].
| Parameters | |
|---|---|
| v | Input vector. |
| min | Lower bound. |
| max | Upper bound. |
| Returns | The resulting vector4. |
vector4 vec4_saturate(const vector4 v)
Clamps each component to the range [0, 1].
| Parameters | |
|---|---|
| v | Input vector. |
| Returns | The resulting vector4. |
vector4 vec4_fract(const vector4 v)
Returns the fractional part of each component.
| Parameters | |
|---|---|
| v | Input vector. |
| Returns | The resulting vector4. |
vector4 vec4_project(const vector4 a, const vector4 b)
Projects a onto b.
| Parameters | |
|---|---|
| a | First input vector. |
| b | Second input vector. |
| Returns | The resulting vector4. |
vector4 vec4_reject(const vector4 a, const vector4 b)
Returns the component of a orthogonal to b.
| Parameters | |
|---|---|
| a | First input vector. |
| b | Second input vector. |
| Returns | The resulting vector4. |
vector4 vec4_slide(const vector4 v, const vector4 normal)
Removes the component of v along normal.
| Parameters | |
|---|---|
| v | Input vector. |
| normal | Surface normal. |
| Returns | The resulting vector4. |
vector4 vec4_splat(const vm_ float_ t s)
Returns a vector with every component set to s.
| Parameters | |
|---|---|
| s | Scalar value. |
| Returns | The resulting vector4. |
vm_ float_ t vec4_length_squared(const vector4 v)
Returns the squared Euclidean length.
| Parameters | |
|---|---|
| v | Input vector. |
| Returns | The resulting scalar. |
vm_ float_ t vec4_distance_squared(const vector4 a,
const vector4 b)
Returns the squared Euclidean distance between a and b.
| Parameters | |
|---|---|
| a | First input vector. |
| b | Second input vector. |
| Returns | The resulting scalar. |
bool vec4_is_zero(const vector4 v)
Returns true if every component is zero.
| Parameters | |
|---|---|
| v | Input vector. |
| Returns | True if every component is zero. |
bool vec4_is_normalized(const vector4 v)
Returns true if the vector has unit length.
| Parameters | |
|---|---|
| v | Input vector. |
| Returns | True if the vector has unit length. |
bool vec4_near(const vector4 a,
const vector4 b,
const vm_ float_ t eps)
Returns true if a and b are within eps of each other.
| Parameters | |
|---|---|
| a | First input vector. |
| b | Second input vector. |
| eps | Distance tolerance. |
| Returns | True if a and b are within eps. |