mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-08-23 15:47:03 -04:00
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>
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
#include <libultra/gbi.h>
|
||||
#include "../CoreMath.h"
|
||||
#include <libultra/types.h>
|
||||
#include "../World.h"
|
||||
#include "engine/World.h"
|
||||
#include "engine/Actor.h"
|
||||
#include "engine/objects/Object.h"
|
||||
|
||||
#include "ObjectPicker.h"
|
||||
#include "port/Engine.h"
|
||||
@@ -33,8 +35,9 @@ void ObjectPicker::Tick() {
|
||||
}
|
||||
|
||||
void ObjectPicker::SelectObject(std::vector<GameObject*> objects) {
|
||||
Camera* camera = gEditor.eCamera;
|
||||
Ray ray;
|
||||
ray.Origin = FVector(cameras[0].pos[0], cameras[0].pos[1], cameras[0].pos[2]);
|
||||
ray.Origin = FVector(camera->pos[0], camera->pos[1], camera->pos[2]);
|
||||
|
||||
// This allows selection of objects in the scene explorer.
|
||||
// Otherwise this would still run when selecting buttons in editor windows.
|
||||
@@ -43,22 +46,23 @@ void ObjectPicker::SelectObject(std::vector<GameObject*> objects) {
|
||||
|
||||
ObjectPicker::FindObject(ray, objects);
|
||||
|
||||
if (_selected != nullptr) {
|
||||
eGizmo.SetGizmo(_selected, ray);
|
||||
eGizmo.Enabled = true;
|
||||
} else {
|
||||
//eGizmo.Disable();
|
||||
eGizmo.Enabled = false;
|
||||
eGizmo._selected = nullptr;
|
||||
}
|
||||
std::visit([this, ray](auto* obj) {
|
||||
if (obj) {
|
||||
eGizmo.SetGizmo(_selected, ray);
|
||||
eGizmo.Enabled = true;
|
||||
} else {
|
||||
eGizmo.Enabled = false;
|
||||
_selected = static_cast<GameObject*>(nullptr);
|
||||
}
|
||||
}, _selected);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectPicker::DragHandle() {
|
||||
Camera* camera = gEditor.eCamera;
|
||||
Ray ray;
|
||||
ray.Origin = FVector(cameras[0].pos[0], cameras[0].pos[1], cameras[0].pos[2]);
|
||||
ray.Origin = FVector(camera->pos[0], camera->pos[1], camera->pos[2]);
|
||||
ray.Direction = ScreenRayTrace();
|
||||
|
||||
// Skip if a drag is already in progress
|
||||
if (eGizmo.SelectedHandle != Gizmo::GizmoHandle::None) {
|
||||
eGizmo._ray = ray.Direction;
|
||||
@@ -116,7 +120,6 @@ void ObjectPicker::DragHandle() {
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (closestHandle != Gizmo::GizmoHandle::None && closestClickPos.has_value()) {
|
||||
eGizmo.SelectedHandle = closestHandle;
|
||||
eGizmo._ray = ray.Direction;
|
||||
@@ -126,32 +129,68 @@ void ObjectPicker::DragHandle() {
|
||||
}
|
||||
|
||||
void ObjectPicker::Draw() {
|
||||
if (_selected != NULL) {
|
||||
eGizmo.Draw();
|
||||
}
|
||||
std::visit([](auto* obj) {
|
||||
if (obj) {
|
||||
gEditor.eObjectPicker.eGizmo.Draw();
|
||||
}
|
||||
}, _selected);
|
||||
|
||||
if (Debug) {
|
||||
Camera* camera = gEditor.eCamera;
|
||||
Mat4 CursorMtx;
|
||||
IRotator rot = IRotator(0,0,0);
|
||||
FVector scale = FVector(0.1, 0.1, 0.1);
|
||||
FVector scale = FVector(1, 1, 1);
|
||||
FVector ray = ScreenRayTrace();
|
||||
|
||||
float x = (cameras[0].pos[0] + ray.x * 800);
|
||||
float y = (cameras[0].pos[1] + ray.y * 800);
|
||||
float z = (cameras[0].pos[2] + ray.z * 800);
|
||||
float x = (camera->pos[0] + ray.x * 800);
|
||||
float y = (camera->pos[1] + ray.y * 800);
|
||||
float z = (camera->pos[2] + ray.z * 800);
|
||||
|
||||
ApplyMatrixTransformations((float(*)[4])&CursorMtx, FVector(x, y, z), rot, scale);
|
||||
Editor_AddMatrix((float(*)[4])&CursorMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
|
||||
gSPDisplayList(gDisplayListHead++, (Gfx*)"__OTR__tracks/sphere");
|
||||
gSPDisplayList(gDisplayListHead++, (Gfx*)"__OTR__gizmo/gizmo_center_button");
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectPicker::FindObject(Ray ray, std::vector<GameObject*> objects) {
|
||||
bool found = false;
|
||||
GameObject* closestObject = nullptr;
|
||||
float closestDistance = FLT_MAX;
|
||||
float distance = FLT_MAX;
|
||||
std::variant<AActor*, OObject*, GameObject*> object;
|
||||
|
||||
for (auto& object : objects) {
|
||||
_selected = static_cast<GameObject*>(nullptr);
|
||||
|
||||
auto [hitActor, hitActorDist] = ObjectPicker::CheckAActorRay(ray);
|
||||
if (hitActor) {
|
||||
object = hitActor;
|
||||
distance = hitActorDist;
|
||||
}
|
||||
|
||||
// OObjects
|
||||
auto [hitObject, hitObjectDist] = ObjectPicker::CheckOObjectRay(ray);
|
||||
if (hitObject && (hitObjectDist < distance)) {
|
||||
object = hitObject;
|
||||
distance = hitObjectDist;
|
||||
}
|
||||
|
||||
// Editor objects
|
||||
auto [hitEditorObject, hitEditorObjectDist] = ObjectPicker::CheckEditorObjectRay(ray);
|
||||
if (hitEditorObject && (hitEditorObjectDist < distance)) {
|
||||
object = hitEditorObject;
|
||||
distance = hitEditorObjectDist;
|
||||
}
|
||||
|
||||
// Set _selected from object variant
|
||||
_selected = object;
|
||||
std::visit([this](auto* obj) {
|
||||
if (obj) {
|
||||
}
|
||||
}, object);
|
||||
}
|
||||
|
||||
std::pair<GameObject*, float> ObjectPicker::CheckEditorObjectRay(Ray ray) {
|
||||
GameObject* hitObject = nullptr;
|
||||
float hitDistance = FLT_MAX;
|
||||
|
||||
for (auto& object : gEditor.eGameObjects) {
|
||||
float boundingBox = object->BoundingBoxSize;
|
||||
if (boundingBox == 0.0f) {
|
||||
boundingBox = 2.0f;
|
||||
@@ -161,11 +200,10 @@ void ObjectPicker::FindObject(Ray ray, std::vector<GameObject*> objects) {
|
||||
case GameObject::CollisionType::VTX_INTERSECT:
|
||||
for (const auto& tri : object->Triangles) {
|
||||
float t;
|
||||
if (IntersectRayTriangleAndTransform(ray, *object->Pos, tri, t)) {
|
||||
if (t < closestDistance) {
|
||||
closestDistance = t;
|
||||
closestObject = object;
|
||||
printf("SELECTED OBJECT\n");
|
||||
if (IntersectRayTriangleAndTransform(ray, object->Pos, tri, t)) {
|
||||
if (t < hitDistance) {
|
||||
hitDistance = t;
|
||||
hitObject = object;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,18 +211,18 @@ void ObjectPicker::FindObject(Ray ray, std::vector<GameObject*> objects) {
|
||||
case GameObject::CollisionType::BOUNDING_BOX: {
|
||||
float max = 2.0f;
|
||||
float min = -2.0f;
|
||||
Vec3f boxMin = { object->Pos->x + boundingBox * min,
|
||||
object->Pos->y + boundingBox * min,
|
||||
object->Pos->z + boundingBox * min };
|
||||
Vec3f boxMin = { object->Pos.x + boundingBox * min,
|
||||
object->Pos.y + boundingBox * min,
|
||||
object->Pos.z + boundingBox * min };
|
||||
|
||||
Vec3f boxMax = { object->Pos->x + boundingBox * max,
|
||||
object->Pos->y + boundingBox * max,
|
||||
object->Pos->z + boundingBox * max };
|
||||
Vec3f boxMax = { object->Pos.x + boundingBox * max,
|
||||
object->Pos.y + boundingBox * max,
|
||||
object->Pos.z + boundingBox * max };
|
||||
float t;
|
||||
if (QueryCollisionRayActor(&ray.Origin.x, &ray.Direction.x, boxMin, boxMax, &t)) {
|
||||
if (t < closestDistance) {
|
||||
closestDistance = t;
|
||||
closestObject = object;
|
||||
if (t < hitDistance) {
|
||||
hitDistance = t;
|
||||
hitObject = object;
|
||||
printf("FOUND BOUNDING BOX OBJECT\n");
|
||||
}
|
||||
break;
|
||||
@@ -196,12 +234,62 @@ void ObjectPicker::FindObject(Ray ray, std::vector<GameObject*> objects) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (closestObject != nullptr) {
|
||||
_selected = closestObject;
|
||||
// printf("FOUND COLLISION %d\n", type);
|
||||
} else {
|
||||
// printf("NO COLLISION\n");
|
||||
_selected = nullptr;
|
||||
return std::pair(hitObject, hitDistance);
|
||||
}
|
||||
|
||||
std::pair<OObject*, float> ObjectPicker::CheckOObjectRay(Ray ray) {
|
||||
OObject* hitObject = nullptr;
|
||||
float hitDistance = FLT_MAX;
|
||||
|
||||
|
||||
return std::pair(hitObject, hitDistance);
|
||||
}
|
||||
|
||||
std::pair<AActor*, float> ObjectPicker::CheckAActorRay(Ray ray) {
|
||||
AActor* hitActor = nullptr;
|
||||
float hitDistance = FLT_MAX;
|
||||
|
||||
for (auto actor : gWorldInstance.Actors) {
|
||||
if ((actor->bPendingDestroy) && (!actor->IsMod())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float boundingBox = actor->BoundingBoxSize;
|
||||
if (boundingBox == 0.0f) {
|
||||
boundingBox = 2.0f;
|
||||
}
|
||||
|
||||
if (actor->Triangles.size()) {
|
||||
for (const auto& tri : actor->Triangles) {
|
||||
float t;
|
||||
if (IntersectRayTriangleAndTransform(ray, FVector(actor->Pos[0], actor->Pos[1], actor->Pos[2]), tri, t)) {
|
||||
if (t < hitDistance) {
|
||||
hitDistance = t;
|
||||
hitActor = static_cast<AActor*>(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
float max = 1.2f;
|
||||
float min = -1.2f;
|
||||
Vec3f boxMin = { actor->Pos[0] + boundingBox * min,
|
||||
actor->Pos[1] + boundingBox * min,
|
||||
actor->Pos[2] + boundingBox * min };
|
||||
|
||||
Vec3f boxMax = { actor->Pos[0] + boundingBox * max,
|
||||
actor->Pos[1] + boundingBox * max,
|
||||
actor->Pos[2] + boundingBox * max };
|
||||
float t;
|
||||
if (QueryCollisionRayActor(&ray.Origin.x, &ray.Direction.x, boxMin, boxMax, &t)) {
|
||||
if (t < hitDistance) {
|
||||
hitDistance = t;
|
||||
hitActor = static_cast<AActor*>(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::pair(hitActor, hitDistance);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user