bgc-c/basic-geometry/rotation3.h

93 lines
2.4 KiB
C

#ifndef _BGC_ROTATION3_H_
#define _BGC_ROTATION3_H_
#include "utilities.h"
#include "angle.h"
#include "vector3.h"
typedef struct {
BGC_FP32_Vector3 axis;
float radians;
} BGC_FP32_Rotation3;
typedef struct {
BGC_FP64_Vector3 axis;
double radians;
} BGC_FP64_Rotation3;
extern const BGC_FP32_Rotation3 BGC_FP32_IDLE_ROTATION3;
extern const BGC_FP64_Rotation3 BGC_FP64_IDLE_ROTATION3;
// =================== Reset ==================== //
inline void bgc_fp32_rotation3_reset(BGC_FP32_Rotation3* rotation)
{
rotation->axis.x1 = 0.0f;
rotation->axis.x2 = 0.0f;
rotation->axis.x3 = 0.0f;
rotation->radians = 0.0f;
}
inline void bgc_fp64_rotation3_reset(BGC_FP64_Rotation3* rotation)
{
rotation->axis.x1 = 0.0;
rotation->axis.x2 = 0.0;
rotation->axis.x3 = 0.0;
rotation->radians = 0.0;
}
// ================= Set Values ================= //
inline void bgc_fp32_rotation3_make(const float x1, const float x2, const float x3, const float angle, const int unit, BGC_FP32_Rotation3* rotation)
{
rotation->axis.x1 = x1;
rotation->axis.x2 = x2;
rotation->axis.x3 = x3;
if (bgc_fp32_vector3_normalize(&rotation->axis)) {
rotation->radians = bgc_fp32_angle_to_radians(angle, unit);
}
else {
rotation->radians = 0.0f;
}
}
inline void bgc_fp64_rotation3_make(const double x1, const double x2, const double x3, const double angle, const int unit, BGC_FP64_Rotation3* rotation)
{
rotation->axis.x1 = x1;
rotation->axis.x2 = x2;
rotation->axis.x3 = x3;
if (bgc_fp64_vector3_normalize(&rotation->axis)) {
rotation->radians = bgc_fp64_angle_to_radians(angle, unit);
}
else {
rotation->radians = 0.0;
}
}
inline void bgc_fp32_rotation3_make_for_axis(const BGC_FP32_Vector3* axis, const float angle, const int unit, BGC_FP32_Rotation3* rotation)
{
if (bgc_fp32_vector3_get_normalized(&rotation->axis, axis)) {
rotation->radians = bgc_fp32_angle_to_radians(angle, unit);
}
else {
rotation->radians = 0.0f;
}
}
inline void bgc_fp64_rotation3_make_for_axis(const BGC_FP64_Vector3* axis, const double angle, const int unit, BGC_FP64_Rotation3* rotation)
{
if (bgc_fp64_vector3_get_normalized(&rotation->axis, axis)) {
rotation->radians = bgc_fp64_angle_to_radians(angle, unit);
}
else {
rotation->radians = 0.0;
}
}
#endif