diff options
| author | MegaMech <MegaMech@users.noreply.github.com> | 2025-02-10 15:05:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-10 15:05:53 -0700 |
| commit | 6a629fcaa946ea564e8348ead2ada6dbefd6c175 (patch) | |
| tree | bc54da17ff8a94f974a1697f4387fda1ddf47e86 /src/engine/actors | |
| parent | a6ecc276e947fbd4f720fe2714ce23e9216070e7 (diff) | |
Add Ship (#191)
* Compile works now
* Update menus
* Update CMakeLists.txt
* Add Ship
* Impl hm ship actors
* Update HM course
Diffstat (limited to 'src/engine/actors')
| -rw-r--r-- | src/engine/actors/Ship.cpp | 61 | ||||
| -rw-r--r-- | src/engine/actors/Ship.h | 34 | ||||
| -rw-r--r-- | src/engine/actors/SpaghettiShip.cpp | 80 | ||||
| -rw-r--r-- | src/engine/actors/SpaghettiShip.h | 28 | ||||
| -rw-r--r-- | src/engine/actors/Starship.cpp | 49 | ||||
| -rw-r--r-- | src/engine/actors/Starship.h | 25 |
6 files changed, 277 insertions, 0 deletions
diff --git a/src/engine/actors/Ship.cpp b/src/engine/actors/Ship.cpp new file mode 100644 index 000000000..148b883eb --- /dev/null +++ b/src/engine/actors/Ship.cpp @@ -0,0 +1,61 @@ +#include "Ship.h" + +#include <libultra/gbi.h> + +extern "C" { +#include "common_structs.h" +#include "math_util.h" +#include "main.h" +#include "courses/harbour/ghostship_model.h" +#include "courses/harbour/ship2_model.h" +#include "courses/harbour/ship3_model.h" +} + +AShip::AShip(FVector pos, AShip::Skin skin) { + Spawn = pos; + Spawn.y += 10; + + switch(skin) { + case GHOSTSHIP: + _skin = ghostship_Plane_mesh; + break; + case SHIP2: + _skin = ship2_SoH_mesh; + break; + case SHIP3: + _skin = ship3_2Ship_mesh; + break; + } +} + +void AShip::Tick() { + static float angle = 0.0f; // Keeps track of the ship's rotation around the circle + float radius = 150.0f; // The radius of the circular path + float speed = 0.01f; // Speed of rotation + + angle += speed; // Increment the angle to move in a circle + + // Update the position based on a circular path + Pos.x = Spawn.x + radius * cosf(angle); + Pos.z = Spawn.z + radius * sinf(angle); + + // Rotate to face forward along the circle + Rot.yaw = -static_cast<int16_t>(angle * (32768.0f / M_PI / 2.0f)); +} + +void AShip::Draw(Camera *camera) { + Mat4 shipMtx; + Vec3f hullPos = {Pos.x, Pos.y, Pos.z}; + Vec3s hullRot = {Rot.pitch, Rot.yaw, Rot.roll}; + + gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); + gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); + + mtxf_pos_rotation_xyz(shipMtx, hullPos, hullRot); + mtxf_scale(shipMtx, 0.4); + if (render_set_position(shipMtx, 0) != 0) { + gSPDisplayList(gDisplayListHead++, _skin); + } +} + +bool AShip::IsMod() { return true; } diff --git a/src/engine/actors/Ship.h b/src/engine/actors/Ship.h new file mode 100644 index 000000000..59ceb68a8 --- /dev/null +++ b/src/engine/actors/Ship.h @@ -0,0 +1,34 @@ +#pragma once + +#include <libultraship.h> +#include <libultra/gbi.h> +#include "engine/Actor.h" +#include "CoreMath.h" + +extern "C" { +#include "common_structs.h" +#include "assets/other_textures.h" +} + +class AShip : public AActor { +public: + + enum Skin { + GHOSTSHIP, + SHIP2, + SHIP3, + }; + + explicit AShip(FVector pos, AShip::Skin); + virtual ~AShip() = default; + + virtual void Tick() override; + virtual void Draw(Camera*) override; + virtual bool IsMod() override; + + FVector Spawn; + FVector Pos; + FRotation Rot = {0, 0, 0}; +private: + Gfx* _skin; +}; diff --git a/src/engine/actors/SpaghettiShip.cpp b/src/engine/actors/SpaghettiShip.cpp new file mode 100644 index 000000000..d53b90f07 --- /dev/null +++ b/src/engine/actors/SpaghettiShip.cpp @@ -0,0 +1,80 @@ +#include "SpaghettiShip.h" + +#include <libultra/gbi.h> + +extern "C" { +#include "common_structs.h" +#include "math_util.h" +#include "main.h" +#include "courses/harbour/ship_model.h" +} + +ASpaghettiShip::ASpaghettiShip(FVector pos) { + Spawn = pos; + Spawn.y += 10; +} + +void ASpaghettiShip::Tick() { + static float angle = 0.0f; // Keeps track of the ship's rotation around the circle + float radius = 150.0f; // The radius of the circular path + float speed = 0.01f; // Speed of rotation + + angle += speed; // Increment the angle to move in a circle + + // Update the position based on a circular path + Pos.x = Spawn.x + radius * cosf(angle); + Pos.z = Spawn.z + radius * sinf(angle); + + // Rotate to face forward along the circle + Rot.yaw = -static_cast<int16_t>(angle * (32768.0f / M_PI / 2.0f)); + + + WheelRot.pitch += 500; +} + +void ASpaghettiShip::Draw(Camera *camera) { + Mat4 shipMtx; + Mat4 objectMtx; + Mat4 resultMtx; + Vec3f hullPos = {Pos.x, Pos.y, Pos.z}; + Vec3s hullRot = {Rot.pitch, Rot.yaw, Rot.roll}; + Vec3s rot = {WheelRot.pitch, WheelRot.yaw, WheelRot.roll}; + + gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); + gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); + + // empty/null mtx as a base + mtxf_pos_rotation_xyz(shipMtx, hullPos, hullRot); + mtxf_scale(shipMtx, 0.4); + if (render_set_position(shipMtx, 0) != 0) {} + + // Render the ships hull + Vec3f hullPos2 = {0, 0, 0}; + mtxf_translate(objectMtx, hullPos2); + mtxf_multiplication(resultMtx, shipMtx, objectMtx); + if (render_set_position(resultMtx, 3) != 0) { + gSPDisplayList(gDisplayListHead++, ship1_Spaghetti_mesh); + } + + // Front tyre + Vec3f pos = {0, 0, 110}; + mtxf_rotate_x(shipMtx, WheelRot.pitch); + mtxf_translate(objectMtx, pos); + mtxf_multiplication(resultMtx, shipMtx, objectMtx); + if (render_set_position(resultMtx, 3) != 0) { + gSPDisplayList(gDisplayListHead++, wheels_Spaghetti_002_mesh); + gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); + } + + // Back tyre + Vec3f pos2 = {0, 0, -165}; + mtxf_rotate_x(shipMtx, WheelRot.pitch); + mtxf_translate(objectMtx, pos2); + mtxf_multiplication(resultMtx, shipMtx, objectMtx); + if (render_set_position(resultMtx, 3) != 0) { + gSPDisplayList(gDisplayListHead++, wheels_Spaghetti_002_mesh); + gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); + } +} + +bool ASpaghettiShip::IsMod() { return true; } diff --git a/src/engine/actors/SpaghettiShip.h b/src/engine/actors/SpaghettiShip.h new file mode 100644 index 000000000..1d0d656c5 --- /dev/null +++ b/src/engine/actors/SpaghettiShip.h @@ -0,0 +1,28 @@ +#pragma once + +#include <libultraship.h> +#include <libultra/gbi.h> +#include "engine/Actor.h" +#include "CoreMath.h" + +extern "C" { +#include "common_structs.h" +#include "assets/other_textures.h" +} + +class ASpaghettiShip : public AActor { +public: + explicit ASpaghettiShip(FVector pos); + virtual ~ASpaghettiShip() = default; + + virtual void Tick() override; + virtual void Draw(Camera*) override; + virtual bool IsMod() override; + + FVector Spawn; + FVector Pos; + FRotation Rot = {0, 0, 0}; + FRotation WheelRot = {0, 0, 0}; +private: + f32 scale; +}; diff --git a/src/engine/actors/Starship.cpp b/src/engine/actors/Starship.cpp new file mode 100644 index 000000000..bc201b84a --- /dev/null +++ b/src/engine/actors/Starship.cpp @@ -0,0 +1,49 @@ +#include "Starship.h" + +#include <libultra/gbi.h> + +extern "C" { +#include "common_structs.h" +#include "math_util.h" +#include "main.h" +#include "courses/harbour/starship_model.h" +} + +AStarship::AStarship(FVector pos) { + Spawn = pos; +} + +void AStarship::Tick() { + static float angle = 0.0f; + float radius = 150.0f; + float speed = 0.01f; + + angle += speed; + + // Move relative to the initial position + Pos.x = Spawn.x + radius * cosf(angle); + Pos.z = Spawn.z + radius * sinf(angle); + + // Keep y from changing (or adjust it if necessary) + Pos.y = Spawn.y; + + // Rotate to face forward along the circle + Rot.yaw = angle * (180.0f / M_PI) + 90.0f; +} + +void AStarship::Draw(Camera *camera) { + Mat4 shipMtx; + Vec3f hullPos = {Pos.x, Pos.y, Pos.z}; + Vec3s hullRot = {Rot.pitch, Rot.yaw, Rot.roll}; + + gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); + gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); + + mtxf_pos_rotation_xyz(shipMtx, hullPos, hullRot); + mtxf_scale(shipMtx, 1.5); + if (render_set_position(shipMtx, 0) != 0) { + gSPDisplayList(gDisplayListHead++, starship_Cube_mesh); + } +} + +bool AStarship::IsMod() { return true; } diff --git a/src/engine/actors/Starship.h b/src/engine/actors/Starship.h new file mode 100644 index 000000000..390aed2ea --- /dev/null +++ b/src/engine/actors/Starship.h @@ -0,0 +1,25 @@ +#pragma once + +#include <libultraship.h> +#include <libultra/gbi.h> +#include "engine/Actor.h" +#include "CoreMath.h" + +extern "C" { +#include "common_structs.h" +#include "assets/other_textures.h" +} + +class AStarship : public AActor { +public: + explicit AStarship(FVector pos); + virtual ~AStarship() = default; + + virtual void Tick() override; + virtual void Draw(Camera*) override; + virtual bool IsMod() override; + + FVector Spawn; + FVector Pos; + FRotation Rot = {0, 0, 0}; +}; |
