31 lines
1.8 KiB
C
31 lines
1.8 KiB
C
#include <defocus/df_math.h>
|
||
|
||
#include <math.h>
|
||
|
||
DF_API df_v3 df_normalize_v3(df_v3 v)
|
||
{
|
||
float l = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
|
||
return (df_v3){v.x / l, v.y / l, v.z / l};
|
||
}
|
||
|
||
DF_API float df_len_v3(df_v3 v) { return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); }
|
||
|
||
DF_API df_v3 df_cross(df_v3 a, df_v3 b)
|
||
{
|
||
return (df_v3){
|
||
.x = a.y * b.z - a.z * b.y,
|
||
.y = a.z * b.x - a.x * b.z,
|
||
.z = a.x * b.y - a.y * b.x,
|
||
};
|
||
}
|
||
|
||
DF_API df_v3 df_mul_v3(float s, df_v3 v) { return (df_v3){s * v.x, s * v.y, s * v.z}; }
|
||
|
||
DF_API df_v3 df_add_v3(df_v3 a, df_v3 b) { return (df_v3){a.x + b.x, a.y + b.y, a.z + b.z}; }
|
||
|
||
DF_API df_v3 df_sub_v3(df_v3 a, df_v3 b) { return (df_v3){a.x - b.x, a.y - b.y, a.z - b.z}; }
|
||
|
||
DF_API float df_dot_v3(df_v3 a, df_v3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
|
||
|
||
DF_API float df_len_v2(df_v2 v) { return sqrtf(v.x * v.x + v.y * v.y); }
|