summaryrefslogtreecommitdiff
path: root/src/engine/CoreMath.h
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2025-05-14 18:30:32 -0600
committerGitHub <noreply@github.com>2025-05-14 18:30:32 -0600
commit32632cacdb316d7f2d3b6ecdb634f0ef9aebadf0 (patch)
treed374a84675fc0f49100c275aa34828bc9db538f8 /src/engine/CoreMath.h
parent70f049cb6c326dede27e0ba7e88ac0d67b7651a4 (diff)
Impl new intro (#193)
* Update menus * Update CMakeLists.txt * Add Ship * Impl hm ship actors * Update HM course * Impl new intro * Finish intro scene * Rename * Start Editor Work * raycast works * Fix ScreenRayTrace in widescreen * Basic Actor Picking * wip * Editor use vtx collision * gizmo work * otr works for object picking * Impl objects for editor * actor init * Update * Add all axis move (freemove) * Docking Windows works here * Setup imgui layout for editor * Editor Snap to Ground works * Basic Scene Explorer Works * Editor get actor names * Impl editor object names * impl Editor Play and Pause buttons * Editor translate works while paused * Fix freecam lighting * Added adjustable track properties to editor * Editor matrix, icons, rotation, impl light * Setup Track Properties 1 * Editor tooling wip * Load modded o2rs * Don't enable hud if editor is enabled * Updates * SceneManager nearly working * Fix mario kart 64 intro logo sizing * Fix Rotator * Finish new matrix translation code * Cleanup headers * Cleanup * Cleanup 2 * Cleanup 3 * Prevent divize by zero crash * Add visible circle for translate in all axis * Editor scaling/rot works properly now * Scale All_Axis evenly * Fixes to includes to work on Linux. * Removed overfilled arguments in gfx_create_framebuffer() * Added missing function definitions to Game.h * Editor sun face the camera * Add rotation model to gizmo * Add new handles * Failed attempt at transforming collision * Impl water volume * Import fast64 paths * water surface * Scene Setup 1 * Custom Track O2R almost working needs testing * Custom Track Load path O2r * Render custom track. Wip collision * Add missing function * Debug Spawning Custom O2R Track * Import courses working now * Fix memory leak * Remove New Track Button * Engine.cpp more consistent with sf64 * Fix Editor Enable Button * Editor Accurate mouse click drag objects * Editor selects closest object and cleanup * Gizmo rot and scale collision working * Remove constexpr from IRotator * Impl properties for location/rot/scale * Better Properties display, swap rot handles * Fix content browser dock and editor now disabled by default * Remove GameInfoWindow, Multiplayer Button, and FPS Slider * Disable Editor when its disabled * Add new logo to hm intro * Fix pause menu item box cursor * Remove minimap from Course::from_json and to_json * Impl Import Minimap * Fix custom minimap rendering * minimap uses extension .png * Refactor minimap * Freecam only for player 1 * GrandPrix Balloons work in custom track * Track Id is now std::string and outside of Props * Moved editor assets to be included in ship.o2r * Fixed GenerateO2R to package the correct folder and save to the correct filename * Linux specific changes. * Added "#include <stdio.h>" that required them * Changed how the "ship.o2r" file is loaded to allow it to load the file from within appimages. * Changed the Linuxdeploy version to avoid errors later when the Github Actions creates appimages(same fix applied to other ports.) * Revert "Moved editor assets to be included in ship.o2r" This reverts commit 05704c01f761baa67a83e357d9765f5c6b5e3fdb. * Added back files(this time without LUS changes) * Changed workflow file to use correct filename for assets file. * Missed a few spots in the workflow file. * Added .desktop file and made corrections to the main workflow. * Added the rest of upstream CMakeLists.txt * disabled USE_NETWORKING * New InverseMatrix * Renamed both .o2r files to be more accurate to its contents. * Reverted CmakeList.txt --------- Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com> Co-authored-by: sitton76 <58642183+sitton76@users.noreply.github.com>
Diffstat (limited to 'src/engine/CoreMath.h')
-rw-r--r--src/engine/CoreMath.h143
1 files changed, 126 insertions, 17 deletions
diff --git a/src/engine/CoreMath.h b/src/engine/CoreMath.h
index ea74dd9a4..2c232aab9 100644
--- a/src/engine/CoreMath.h
+++ b/src/engine/CoreMath.h
@@ -10,16 +10,55 @@
*
*/
-
+/**
+ *
+ * Applies pos, rot, and scale
+ *
+ */
struct FVector {
float x, y, z;
#ifdef __cplusplus
- FVector& operator=(const FVector& other) {
- x = other.x;
- y = other.y;
- z = other.z;
- return *this;
+ // Operator to add two FVector objects
+ FVector operator+(const FVector& other) const {
+ return FVector(x + other.x, y + other.y, z + other.z);
+ }
+
+ // Operator to subtract two FVector objects
+ FVector operator-(const FVector& other) const {
+ return FVector(x - other.x, y - other.y, z - other.z);
+ }
+
+ // Operator to multiply a FVector by a scalar (float)
+ FVector operator*(float scalar) const {
+ return FVector(x * scalar, y * scalar, z * scalar);
+ }
+
+ float Dot(const FVector& other) const {
+ return x * other.x + y * other.y + z * other.z;
+ }
+
+
+ FVector Cross(const FVector& other) const {
+ return FVector(
+ y * other.z - z * other.y,
+ z * other.x - x * other.z,
+ x * other.y - y * other.x
+ );
+ }
+
+ float Magnitude() const {
+ return std::sqrt(x * x + y * y + z * z);
+ }
+
+ FVector Normalize() const {
+ float len = std::sqrt(x * x + y * y + z * z);
+ if (len > 0.0001f) {
+ return FVector(
+ x / len, y / len, z / len
+ );
+ }
+ return FVector(0, 0, 0);
}
FVector() : x(0), y(0), z(0) {}
@@ -27,6 +66,16 @@ struct FVector {
#endif // __cplusplus
};
+struct FVector4 {
+ float x, y, z, w;
+
+#ifdef __cplusplus
+
+ FVector4() : x(0), y(0), z(0), w(0) {}
+ FVector4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
+#endif // __cplusplus
+};
+
/**
* For providing X and Z when you do not need Y
* Some actors set themselves on the surface automatically
@@ -50,35 +99,95 @@ struct FVector2D {
// Sets integer X Z coordinates
typedef struct IVector2D {
- int32_t X, Z;
+ int32_t X, Y;
#ifdef __cplusplus
- IVector2D() : X(0), Z(0) {} // Default constructor
+ IVector2D() : X(0), Y(0) {} // Default constructor
- IVector2D(int32_t x, int32_t z) : X(x), Z(z) {} // Constructor to initialize with values
+ IVector2D(int32_t x, int32_t y) : X(x), Y(y) {} // Constructor to initialize with values
IVector2D& operator=(const IVector2D& other) {
X = other.X;
- Z = other.Z;
+ Y = other.Y;
return *this;
}
#endif // __cplusplus
} IVector2D;
-struct FRotation {
+/**
+ * This struct immediately converts float pitch/yaw/roll in degrees to n64 int16_t binary angles 0-0xFFFF == 0-360 degrees
+ * ToDegrees() Receive an FRotator of float degrees back.
+ * Set() Set an n64 int16_t binary angles 0-0xFFFF
+ */
+struct IRotator {
+ uint16_t pitch, yaw, roll;
+
+#ifdef __cplusplus
+ IRotator& operator=(const IRotator& other) {
+ pitch = other.pitch;
+ yaw = other.yaw;
+ roll = other.roll;
+ return *this;
+ }
+
+ [[nodiscard]] void Set(uint16_t p, uint16_t y, uint16_t r) {
+ pitch = p;
+ yaw = y;
+ roll = r;
+ }
+
+ IRotator() : pitch(0), yaw(0), roll(0) {}
+ IRotator(float p, float y, float r) {
+ pitch = p * (UINT16_MAX / 360);
+ yaw = y * (UINT16_MAX / 360);
+ roll = r * (UINT16_MAX / 360);
+ }
+
+ // Convert to radians as FVector
+ [[nodiscard]] FVector ToRadians() const {
+ float scale = 2.0f * M_PI / 65536.0f;
+ return FVector(
+ pitch * scale,
+ yaw * scale,
+ roll * scale
+ );
+ }
+#endif // __cplusplus
+};
+
+/**
+ * Use IRotator unless you want to do some math in degrees.
+ * Always use ToBinary() or Rotator when sending into matrices or apply translation functions
+ * Convert from IRotator to FRotator float degrees by doing FRotator(myIRotator);
+ */
+struct FRotator {
float pitch, yaw, roll;
#ifdef __cplusplus
- FRotation& operator=(const FRotation& other) {
+ FRotator& operator=(const FRotator& other) {
pitch = other.pitch;
- yaw = other.yaw;
- roll = other.roll;
+ yaw = other.yaw;
+ roll = other.roll;
return *this;
}
- FRotation() : pitch(0), yaw(0), roll(0) {}
- FRotation(float p, float y, float r) : pitch(p), yaw(y), roll(r) {}
+ // Convert to binary rotator 0 --> INT16_MAX
+ [[nodiscard]] IRotator ToBinary() const {
+ return IRotator(
+ static_cast<uint16_t>(pitch * (UINT16_MAX / 360)),
+ static_cast<uint16_t>(yaw * (UINT16_MAX / 360)),
+ static_cast<uint16_t>(roll * (UINT16_MAX / 360))
+ );
+ }
+
+ FRotator() : pitch(0), yaw(0), roll(0) {}
+ FRotator(float p, float y, float r) : pitch(p), yaw(y), roll(r) {}
+ FRotator(IRotator rot) {
+ pitch = static_cast<float>(rot.pitch * (360 / UINT16_MAX));
+ yaw = static_cast<float>(rot.yaw * (360 / UINT16_MAX));
+ roll = static_cast<float>(rot.roll * (360 / UINT16_MAX));
+ }
#endif // __cplusplus
};
@@ -118,4 +227,4 @@ struct IPathSpan {
#endif // __cplusplus
};
-#endif // CORE_MATH_H \ No newline at end of file
+#endif // CORE_MATH_H