diff options
| author | Lucas Shaw <49287729+shawlucas@users.noreply.github.com> | 2024-04-11 02:20:00 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-10 23:20:00 -0700 |
| commit | fb02647839bda70f4e50a2f79c7bdcfb93ef61af (patch) | |
| tree | 65c13ed9b50fe68cfb6da0b236f2db364969f0e2 /include | |
| parent | 7146ace5cb89772c195a41ee41b375cf4fe2166e (diff) | |
m_olib.c OK (#167)
* m_olib.c OK
* ran format.py
* added functions to header file
* updated graphics macros in two overlays to make them work with format.py
* rename z64camera.h to m_camera2.h
* made recommended changes
Diffstat (limited to 'include')
| -rw-r--r-- | include/m_camera2.h | 8 | ||||
| -rw-r--r-- | include/m_olib.h | 33 | ||||
| -rw-r--r-- | include/macros.h | 2 | ||||
| -rw-r--r-- | include/z64math.h | 20 |
4 files changed, 48 insertions, 15 deletions
diff --git a/include/m_camera2.h b/include/m_camera2.h new file mode 100644 index 0000000..fa9d81b --- /dev/null +++ b/include/m_camera2.h @@ -0,0 +1,8 @@ +#ifndef M_CAMERA_H +#define M_CAMERA_H + +// these two angle conversion macros are slightly inaccurate +#define CAM_DEG_TO_BINANG(degrees) (s16)((degrees) * ((f32)0xFFFF / 360) + .5f) +#define CAM_BINANG_TO_DEG(binang) ((f32)(binang) * (360.0001525f / 0xFFFF)) + +#endif diff --git a/include/m_olib.h b/include/m_olib.h index 1f25530..0c10d46 100644 --- a/include/m_olib.h +++ b/include/m_olib.h @@ -2,21 +2,24 @@ #define M_OLIB_H #include "ultra64.h" +#include "m_lib.h" +#include "libc64/math64.h" +#include "m_camera2.h" -// void distance_between(); -// void distance_between2(); -// void distance_2d(); -// void never_zero(); -// void limiter(); -// void unitvector_by_2pos(); -// void spolar2world(); -// void sglobe2world(); -// void world2spolar(); -// void world2sglobe(); -// void spolar_by_2pos(); -// void sglobe_by_2pos(); -// void radianxy_by_2pos(); -// void degreexy_by_2pos(); -// void sanglexy_by_2pos(); +f32 distance_between(xyz_t* a, xyz_t* b); +f32 distance_between2(xyz_t* a, xyz_t* b, xyz_t* dest); +f32 distance_2d(xyz_t* a, xyz_t* b); +f32 never_zero(f32 val, f32 min); +f32 limiter(f32 val, f32 max); +xyz_t unitvector_by_2pos(xyz_t* a, xyz_t* b); +xyz_t spolar2world(VecSph* sph); +xyz_t sglobe2world(VecGeo* geo); +VecSph world2spolar(xyz_t* vec); +VecGeo world2sglobe(xyz_t* vec); +VecSph spolar_by_2pos(xyz_t* a, xyz_t* b); +VecGeo sglobe_by_2pos(xyz_t* a, xyz_t* b); +xyz_t radianxy_by_2pos(xyz_t* a, xyz_t* b); +xyz_t degreexy_by_2pos(xyz_t* a, xyz_t* b); +s_xyz sanglexy_by_2pos(xyz_t* a, xyz_t* b); #endif diff --git a/include/macros.h b/include/macros.h index 7b4df6b..b855eb3 100644 --- a/include/macros.h +++ b/include/macros.h @@ -24,6 +24,8 @@ #define ABS(x) (((x) >= 0) ? (x): -(x)) #define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) +#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) +#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) #define DECR(x) ((x) == 0 ? 0 : --(x)) diff --git a/include/z64math.h b/include/z64math.h index 4187622..b533ba2 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -42,6 +42,20 @@ typedef struct { /* 0x8 */ s32 z; } Vec3i; // size = 0xC +typedef struct { + /* 0x0 */ f32 r; // radius + /* 0x4 */ s16 pitch; // depends on coordinate system. See below. + /* 0x6 */ s16 yaw; // azimuthal angle +} VecSphGeo; // size = 0x8 + +// Defines a point in the spherical coordinate system. +// Pitch is 0 along the positive y-axis (up) +typedef VecSphGeo VecSph; + +// Defines a point in the geographic coordinate system. +// Pitch is 0 along the xz-plane (horizon) +typedef VecSphGeo VecGeo; + typedef float MtxF_t[4][4]; typedef union { MtxF_t mf; @@ -86,4 +100,10 @@ typedef union { #define BINANG_SUB(a, b) ((s16)(a - b)) #define BINANG_ADD(a, b) ((s16)(a + b)) +// Vector macros +#define SQXZ(vec) ((vec.x) * (vec.x) + (vec.z) * (vec.z)) +#define DOTXZ(vec1, vec2) ((vec1.x) * (vec2.x) + (vec1.z) * (vec2.z)) +#define SQXYZ(vec) ((vec.x) * (vec.x) + (vec.y) * (vec.y) + (vec.z) * (vec.z)) +#define DOTXYZ(vec1, vec2) ((vec1.x) * (vec2.x) + (vec1.y) * (vec2.y) + (vec1.z) * (vec2.z)) + #endif |
