116 lines
2.1 KiB
C
116 lines
2.1 KiB
C
/**
|
|
* @file vec3.h
|
|
* @brief 3D Vector mathematics for ASCII 3D Renderer
|
|
* @author ASCII3D Project
|
|
* @version 1.0.0
|
|
*/
|
|
|
|
#ifndef ASCII3D_VEC3_H
|
|
#define ASCII3D_VEC3_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* @brief 3D Vector structure
|
|
*/
|
|
typedef struct Vec3 {
|
|
float x;
|
|
float y;
|
|
float z;
|
|
} Vec3;
|
|
|
|
/**
|
|
* @brief Create a new Vec3
|
|
* @param x X component
|
|
* @param y Y component
|
|
* @param z Z component
|
|
* @return New Vec3 instance
|
|
*/
|
|
Vec3 vec3_create(float x, float y, float z);
|
|
|
|
/**
|
|
* @brief Add two vectors
|
|
* @param a First vector
|
|
* @param b Second vector
|
|
* @return Result of a + b
|
|
*/
|
|
Vec3 vec3_add(Vec3 a, Vec3 b);
|
|
|
|
/**
|
|
* @brief Subtract two vectors
|
|
* @param a First vector
|
|
* @param b Second vector
|
|
* @return Result of a - b
|
|
*/
|
|
Vec3 vec3_sub(Vec3 a, Vec3 b);
|
|
|
|
/**
|
|
* @brief Scale a vector by a scalar
|
|
* @param v Vector to scale
|
|
* @param s Scalar value
|
|
* @return Scaled vector
|
|
*/
|
|
Vec3 vec3_scale(Vec3 v, float s);
|
|
|
|
/**
|
|
* @brief Calculate dot product of two vectors
|
|
* @param a First vector
|
|
* @param b Second vector
|
|
* @return Dot product
|
|
*/
|
|
float vec3_dot(Vec3 a, Vec3 b);
|
|
|
|
/**
|
|
* @brief Calculate cross product of two vectors
|
|
* @param a First vector
|
|
* @param b Second vector
|
|
* @return Cross product
|
|
*/
|
|
Vec3 vec3_cross(Vec3 a, Vec3 b);
|
|
|
|
/**
|
|
* @brief Calculate length of a vector
|
|
* @param v Vector
|
|
* @return Length
|
|
*/
|
|
float vec3_length(Vec3 v);
|
|
|
|
/**
|
|
* @brief Normalize a vector
|
|
* @param v Vector to normalize
|
|
* @return Normalized vector
|
|
*/
|
|
Vec3 vec3_normalize(Vec3 v);
|
|
|
|
/**
|
|
* @brief Rotate vector around X axis
|
|
* @param v Vector to rotate
|
|
* @param angle Angle in radians
|
|
* @return Rotated vector
|
|
*/
|
|
Vec3 vec3_rotate_x(Vec3 v, float angle);
|
|
|
|
/**
|
|
* @brief Rotate vector around Y axis
|
|
* @param v Vector to rotate
|
|
* @param angle Angle in radians
|
|
* @return Rotated vector
|
|
*/
|
|
Vec3 vec3_rotate_y(Vec3 v, float angle);
|
|
|
|
/**
|
|
* @brief Rotate vector around Z axis
|
|
* @param v Vector to rotate
|
|
* @param angle Angle in radians
|
|
* @return Rotated vector
|
|
*/
|
|
Vec3 vec3_rotate_z(Vec3 v, float angle);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* ASCII3D_VEC3_H */
|