diff options
| author | MegaMech <MegaMech@users.noreply.github.com> | 2025-11-09 19:07:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-09 19:07:44 -0700 |
| commit | de9c5d510175bba11ab8704e67be3a3a94f9149e (patch) | |
| tree | 34c42dbfe9f2a6eb5fbce5f6a31b532ff2a3f243 /src/engine/actors/Starship.cpp | |
| parent | 760fa3bf5226c2a6052a5d4d53fd0e27f2911e60 (diff) | |
Implement SpawnParams struct (#536)
* Impl SpawnParams
* Added json submodule
* Update json
* Update
* Works
* Remove comment
* Works refactor
* Snowman and thwomp working
* Impl hot air balloon
* More progress
* All OObjects are done
* cleanup
* Refactor 2Dpath to normal path
* Update nlohmann json & fix compile
* Rest of actors
* MORE CHANGES
* Finish actors
* Done PR, some fix to collision viewer
* Impl falling rocks
* Add const
* wip editor refactor
* Property work
* continue
* Overridable editor properties
* Actor saving/loading works now
* Fix light alignment
* Clarification
* Impl penguin
* params impl signs
* properties impl falling rock
* More property impls
* impl air balloon
* Add spawnParams to OObject Translate
* Snowman translate better
* impl hedgehog properly
* properties impl trophy
* thwomp progress
* Finish impl properties
* Fix compile
* Fix cursor collisions
* Move registered actors
* Rename pathPoint XYZ to xyz
* Fix editor pause bug
* Clean up
* Review comments
* Remove SpawnParams struct from actor classes
* Rename
* Player Label First Iteration
* Work now
* Working 3d text
* Fix boo bug
* Finish AText actor
* Fix spawnparams compile
* Register AText
* Finish Text Actor
* Fix thwomp interpolation
* Fix compile
* Fix crab and hedgehog
* Fix loading flagpole
* Fix Hot Air Balloon
* Turn zbuffer on for AText
* Update
---------
Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
Diffstat (limited to 'src/engine/actors/Starship.cpp')
| -rw-r--r-- | src/engine/actors/Starship.cpp | 122 |
1 files changed, 113 insertions, 9 deletions
diff --git a/src/engine/actors/Starship.cpp b/src/engine/actors/Starship.cpp index e104d0eb6..7723ac2d5 100644 --- a/src/engine/actors/Starship.cpp +++ b/src/engine/actors/Starship.cpp @@ -2,6 +2,7 @@ #include <libultra/gbi.h> #include "Matrix.h" +#include "port/Game.h" extern "C" { #include "common_structs.h" @@ -10,26 +11,44 @@ extern "C" { #include "courses/harbour/starship_model.h" } -AStarship::AStarship(FVector pos) { +AStarship::AStarship(const SpawnParams& params) : AActor(params) { Name = "Starship"; - Spawn = pos; + ResourceName = "hm:starship"; + FVector pos = params.Location.value_or(FVector(0, 0, 0)); SetLocation(pos); - Scale = FVector(1.5, 1.5, 1.5); - Model = starship_Cube_mesh; + IRotator rot = params.Rotation.value_or(IRotator(0, 0, 0)); + Rot[0] = rot.pitch; + Rot[1] = rot.yaw; + Rot[2] = rot.roll; + Scale = params.Scale.value_or(FVector(0, 0, 0)); + Speed = params.Speed.value_or(0.01f); + SpeedB = params.SpeedB.value_or(150.0f); + Model = (const char*)starship_Cube_mesh; +} + +void AStarship::SetSpawnParams(SpawnParams& params) { + AActor::SetSpawnParams(params); + params.SpeedB = SpeedB; +} + +void AStarship::BeginPlay() { + // Prevent collision mesh from being generated extra times. + if (Triangles.size() == 0) { + Editor::GenerateCollisionMesh(this, (Gfx*)Model, 1.0f); + } } void AStarship::Tick() { static float angle = 0.0f; - float radius = 150.0f; - float speed = 0.01f; - angle += speed; + angle += Speed; // Move relative to the initial position FVector pos = GetLocation(); - pos.x = Spawn.x + radius * cosf(angle); - pos.z = Spawn.z + radius * sinf(angle); + FVector spawn = SpawnPos; + pos.x = spawn.x + SpeedB * cosf(angle); + pos.z = spawn.z + SpeedB * sinf(angle); SetLocation(pos); // Keep y from changing (or adjust it if necessary) @@ -40,3 +59,88 @@ void AStarship::Tick() { } bool AStarship::IsMod() { return true; } + +void AStarship::DrawEditorProperties() { + ImGui::Text("Location"); + ImGui::SameLine(); + FVector location = FVector(Pos[0], Pos[1], Pos[2]); + if (ImGui::DragFloat3("##Location", (float*)&location)) { + Translate(location); + gEditor.eObjectPicker.eGizmo.Pos = location; + } + + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UNDO "##ResetPos")) { + FVector location = FVector(0, 0, 0); + Translate(location); + gEditor.eObjectPicker.eGizmo.Pos = location; + } + + ImGui::Text("Rotation"); + ImGui::SameLine(); + + IRotator objRot = GetRotation(); + + // Convert to temporary int values (to prevent writing 32bit values to 16bit variables) + int rot[3] = { + objRot.pitch, + objRot.yaw, + objRot.roll + }; + + if (ImGui::DragInt3("##Rotation", rot, 5.0f)) { + for (size_t i = 0; i < 3; i++) { + // Wrap around 0–65535 + rot[i] = (rot[i] % 65536 + 65536) % 65536; + } + IRotator newRot; + newRot.Set( + static_cast<uint16_t>(rot[0]), + static_cast<uint16_t>(rot[1]), + static_cast<uint16_t>(rot[2]) + ); + Rotate(newRot); + } + + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UNDO "##ResetRot")) { + IRotator rot = IRotator(0, 0, 0); + Rotate(rot); + } + + FVector scale = GetScale(); + ImGui::Text("Scale "); + ImGui::SameLine(); + + ImGui::DragFloat3("##Scale", (float*)&scale, 0.1f); + SetScale(scale); + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UNDO "##ResetScale")) { + FVector scale = FVector(0.4f, 0.4f, 0.4f); + SetScale(scale); + } + + ImGui::Text("Speed"); + ImGui::SameLine(); + + float speed = Speed; + if (ImGui::DragFloat("##Speed", &speed, 0.01f)) { + Speed = speed; + } + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UNDO "##ResetSpeed")) { + Speed = 0.0f; + } + + ImGui::Text("Radius"); + ImGui::SameLine(); + + float speed2 = SpeedB; + if (ImGui::DragFloat("##SpeedB", &speed2, 5.0f)) { + SpeedB = speed2; + } + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UNDO "##ResetSpeedB")) { + SpeedB = 0.0f; + } +} |
