3-Component Vector
#include <graphics/vec3.h>
-
struct vec3
Two component vector structure.
-
void vec3_set(struct vec3 *dst, float x, float y)
Sets the individual components of a 3-component vector.
- Parameters:
dst – Destination
x – X component
y – Y component
y – Z component
-
void vec3_copy(struct vec3 *dst, const struct vec3 *v)
Copies a vector
- Parameters:
dst – Destination
v – Vector to copy
-
void vec3_from_vec4(struct vec3 *dst, const struct vec4 *v)
Creates a 3-component vector from a 4-component vector
- Parameters:
dst – 3-component vector destination
v – 4-component vector
-
void vec3_add(struct vec3 *dst, const struct vec3 *v1, const struct vec3 *v2)
Adds two vectors
- Parameters:
dst – Destination
v1 – Vector 1
v2 – Vector 2
-
void vec3_sub(struct vec3 *dst, const struct vec3 *v1, const struct vec3 *v2)
Subtracts two vectors
- Parameters:
dst – Destination
v1 – Vector being subtracted from
v2 – Vector being subtracted
-
void vec3_mul(struct vec3 *dst, const struct vec3 *v1, const struct vec3 *v2)
Multiplies two vectors
- Parameters:
dst – Destination
v1 – Vector 1
v2 – Vector 2
-
void vec3_div(struct vec3 *dst, const struct vec3 *v1, const struct vec3 *v2)
Divides two vectors
- Parameters:
dst – Destination
v1 – Dividend
v2 – Divisor
-
void vec3_addf(struct vec3 *dst, const struct vec3 *v, float f)
Adds a floating point to all components
- Parameters:
dst – Destination
dst – Vector
f – Floating point
-
void vec3_subf(struct vec3 *dst, const struct vec3 *v, float f)
Subtracts a floating point from all components
- Parameters:
dst – Destination
v – Vector being subtracted from
f – Floating point being subtracted
-
void vec3_mulf(struct vec3 *dst, const struct vec3 *v, float f)
Multiplies a floating point with all components
- Parameters:
dst – Destination
dst – Vector
f – Floating point
-
void vec3_divf(struct vec3 *dst, const struct vec3 *v, float f)
Divides a floating point from all components
- Parameters:
dst – Destination
v – Vector (dividend)
f – Floating point (divisor)
-
void vec3_neg(struct vec3 *dst, const struct vec3 *v)
Negates a vector
- Parameters:
dst – Destination
v – Vector to negate
-
float vec3_dot(const struct vec3 *v1, const struct vec3 *v2)
Performs a dot product between two vectors
- Parameters:
v1 – Vector 1
v2 – Vector 2
- Returns:
Result of the dot product
-
void vec3_cross(struct vec3 *dst, const struct vec3 *v1, const struct vec3 *v2)
Performs a cross product between two vectors
- Parameters:
dst – Destination
v1 – Vector 1
v2 – Vector 2
-
float vec3_len(const struct vec3 *v)
Gets the length of a vector
- Parameters:
v – Vector
- Returns:
The vector’s length
-
float vec3_dist(const struct vec3 *v1, const struct vec3 *v2)
Gets the distance between two vectors
- Parameters:
v1 – Vector 1
v2 – Vector 2
- Returns:
Distance between the two vectors
-
void vec3_minf(struct vec3 *dst, const struct vec3 *v, float val)
Gets the minimum values between a vector’s components and a floating point
- Parameters:
dst – Destination
v – Vector
val – Floating point
-
void vec3_min(struct vec3 *dst, const struct vec3 *v, const struct vec3 *min_v)
Gets the minimum values between two vectors
- Parameters:
dst – Destination
v – Vector 1
min_v – Vector 2
-
void vec3_maxf(struct vec3 *dst, const struct vec3 *v, float val)
Gets the maximum values between a vector’s components and a floating point
- Parameters:
dst – Destination
v – Vector
val – Floating point
-
void vec3_max(struct vec3 *dst, const struct vec3 *v, const struct vec3 *max_v)
Gets the maximum values between two vectors
- Parameters:
dst – Destination
v – Vector 1
max_v – Vector 2
-
void vec3_abs(struct vec3 *dst, const struct vec3 *v)
Gets the absolute values of each component
- Parameters:
dst – Destination
v – Vector
-
void vec3_floor(struct vec3 *dst, const struct vec3 *v)
Gets the floor values of each component
- Parameters:
dst – Destination
v – Vector
-
void vec3_ceil(struct vec3 *dst, const struct vec3 *v)
Gets the ceiling values of each component
- Parameters:
dst – Destination
v – Vector
-
int vec3_close(const struct vec3 *v1, const struct vec3 *v2, float epsilon)
Compares two vectors
- Parameters:
v1 – Vector 1
v2 – Vector 2
epsilon – Maximum precision for comparison
-
void vec3_norm(struct vec3 *dst, const struct vec3 *v)
Normalizes a vector
- Parameters:
dst – Destination
v – Vector to normalize
-
void vec3_transform(struct vec3 *dst, const struct vec3 *v, const struct matrix4 *m)
Transforms a vector
- Parameters:
dst – Destination
v – Vector
m – Matrix
-
void vec3_rotate(struct vec3 *dst, const struct vec3 *v, const struct matrix3 *m)
Rotates a vector
- Parameters:
dst – Destination
v – Vector
m – Matrix