mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-08-04 01:23:11 -04:00
Basic Scene Explorer Works
This commit is contained in:
@@ -102,4 +102,10 @@ void Editor::AddObject(FVector* pos, Gfx* model, float scale, CollisionType coll
|
||||
|
||||
void Editor::ClearObjects() {
|
||||
eGameObjects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::SelectObjectFromSceneExplorer(GameObject* object) {
|
||||
eObjectPicker._selected = object;
|
||||
eObjectPicker.eGizmo.Enabled = true;
|
||||
eObjectPicker.eGizmo.EnableNoCursor(object);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
void AddObject(FVector* pos, Gfx* model, float scale, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue);
|
||||
void ClearObjects();
|
||||
void RemoveObject();
|
||||
void SelectObjectFromSceneExplorer(GameObject* object);
|
||||
private:
|
||||
bool _draw = false;
|
||||
Vec3f _ray;
|
||||
|
||||
@@ -18,6 +18,20 @@ extern "C" {
|
||||
#include "camera.h"
|
||||
}
|
||||
|
||||
bool IsInGameScreen() {
|
||||
auto wnd = GameEngine::Instance->context->GetWindow();
|
||||
Ship::Coords mouse = wnd->GetMousePos();
|
||||
|
||||
// Define viewport boundaries
|
||||
int left = gfx_current_game_window_viewport.x;
|
||||
int right = left + OTRGetGameRenderWidth();
|
||||
int top = gfx_current_game_window_viewport.y;
|
||||
int bottom = top + OTRGetGameRenderHeight();
|
||||
|
||||
// Check if the mouse is within the game render area
|
||||
return (mouse.x >= left && mouse.x < right) && (mouse.y >= top && mouse.y < bottom);
|
||||
}
|
||||
|
||||
FVector ScreenRayTrace() {
|
||||
auto wnd = GameEngine::Instance->context->GetWindow();
|
||||
Camera* camera = &cameras[0];
|
||||
|
||||
@@ -41,6 +41,7 @@ struct GameObject {
|
||||
* ray.y = camera->pos[1] + direction.y * length;
|
||||
* ray.z = camera->pos[2] + direction.z * length;
|
||||
*/
|
||||
bool IsInGameScreen();
|
||||
FVector ScreenRayTrace();
|
||||
bool QueryCollisionRayActor(Vec3f rayOrigin, Vec3f rayDir, Vec3f actorMin, Vec3f actorMax, float* t);
|
||||
FVector4 MultiplyMatrixVector(float matrix[4][4], float vector[4]);
|
||||
|
||||
@@ -50,8 +50,6 @@ void Gizmo::Tick() {
|
||||
|
||||
// Makes the gizmo visible
|
||||
void Gizmo::Enable(GameObject* object, Ray ray) {
|
||||
static float length = 180.0f; // Default value
|
||||
|
||||
_selected = object;
|
||||
_ray = ray.Direction;
|
||||
Pos = FVector(
|
||||
@@ -61,6 +59,15 @@ void Gizmo::Enable(GameObject* object, Ray ray) {
|
||||
);
|
||||
}
|
||||
|
||||
void Gizmo::EnableNoCursor(GameObject* object) {
|
||||
_selected = object;
|
||||
Pos = FVector(
|
||||
object->Pos->x,
|
||||
object->Pos->y,
|
||||
object->Pos->z
|
||||
);
|
||||
}
|
||||
|
||||
void Gizmo::Translate() {
|
||||
static float length = 180.0f; // Default value
|
||||
|
||||
@@ -70,7 +77,6 @@ void Gizmo::Translate() {
|
||||
}
|
||||
|
||||
if (Enabled) {
|
||||
//FVector ray = ScreenRayTrace();
|
||||
length = sqrt(
|
||||
pow(_selected->Pos->x - cameras[0].pos[0], 2) +
|
||||
pow(_selected->Pos->y - cameras[0].pos[1], 2) +
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
void Load();
|
||||
|
||||
void Enable(GameObject* object, Ray ray);
|
||||
void EnableNoCursor(GameObject* object); // Used for scene explorer selection
|
||||
void Translate();
|
||||
void DrawHandles();
|
||||
f32 SnapToSurface(FVector* pos);
|
||||
|
||||
@@ -40,17 +40,22 @@ void ObjectPicker::Tick() {
|
||||
void ObjectPicker::SelectObject(std::vector<GameObject>& objects) {
|
||||
Ray ray;
|
||||
ray.Origin = FVector(cameras[0].pos[0], cameras[0].pos[1], cameras[0].pos[2]);
|
||||
ray.Direction = ScreenRayTrace();
|
||||
|
||||
ObjectPicker::FindObject(ray, objects);
|
||||
// This allows selection of objects in the scene explorer.
|
||||
// Otherwise this would still run when selecting buttons in editor windows.
|
||||
if (IsInGameScreen()) {
|
||||
ray.Direction = ScreenRayTrace();
|
||||
|
||||
if (_selected != nullptr) {
|
||||
eGizmo.Enable(_selected, ray);
|
||||
eGizmo.Enabled = true;
|
||||
} else {
|
||||
//eGizmo.Disable();
|
||||
eGizmo.Enabled = false;
|
||||
eGizmo._selected = nullptr;
|
||||
ObjectPicker::FindObject(ray, objects);
|
||||
|
||||
if (_selected != nullptr) {
|
||||
eGizmo.Enable(_selected, ray);
|
||||
eGizmo.Enabled = true;
|
||||
} else {
|
||||
//eGizmo.Disable();
|
||||
eGizmo.Enabled = false;
|
||||
eGizmo._selected = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ class ObjectPicker {
|
||||
void Load();
|
||||
void Tick();
|
||||
Gizmo eGizmo;
|
||||
GameObject* _selected;
|
||||
private:
|
||||
bool _draw = false;
|
||||
Vec3f _ray;
|
||||
GameObject* _selected;
|
||||
GameObject* _lastSelected;
|
||||
s32 Inverse(MtxF* src, MtxF* dest);
|
||||
void Copy(MtxF* src, MtxF* dest);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <common_structs.h>
|
||||
#include <defines.h>
|
||||
|
||||
namespace Editor {
|
||||
namespace EditorNamespace {
|
||||
|
||||
ContentBrowserWindow::~ContentBrowserWindow() {
|
||||
SPDLOG_TRACE("destruct editor window");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <libultraship/libultraship.h>
|
||||
|
||||
namespace Editor {
|
||||
namespace EditorNamespace {
|
||||
class ContentBrowserWindow : public Ship::GuiWindow {
|
||||
public:
|
||||
using Ship::GuiWindow::GuiWindow;
|
||||
|
||||
@@ -79,13 +79,15 @@ void SetupGuiElements() {
|
||||
SPDLOG_ERROR("Could not find input GfxDebuggerWindow");
|
||||
}
|
||||
|
||||
mToolsWindow = std::make_shared<Editor::ToolsWindow>("gEditorEnabled", true, "Tools", ImVec2(100, 100), (ImGuiWindowFlags_NoTitleBar));
|
||||
mToolsWindow = std::make_shared<EditorNamespace::ToolsWindow>("gEditorEnabled", true, "Tools", ImVec2(100, 100),
|
||||
(ImGuiWindowFlags_NoTitleBar));
|
||||
gui->AddGuiWindow(mToolsWindow);
|
||||
|
||||
mSceneExplorerWindow = std::make_shared<Editor::SceneExplorerWindow>("gEditorEnabled", "Scene Explorer");
|
||||
mSceneExplorerWindow = std::make_shared<EditorNamespace::SceneExplorerWindow>("gEditorEnabled", "Scene Explorer");
|
||||
gui->AddGuiWindow(mSceneExplorerWindow);
|
||||
|
||||
mContentBrowserWindow = std::make_shared<Editor::ContentBrowserWindow>("gEditorEnabled", "Content Browser");
|
||||
mContentBrowserWindow =
|
||||
std::make_shared<EditorNamespace::ContentBrowserWindow>("gEditorEnabled", "Content Browser");
|
||||
gui->AddGuiWindow(mContentBrowserWindow);
|
||||
|
||||
mGameInfoWindow = std::make_shared<GameInfo::GameInfoWindow>("gGameInfoEnabled", "Game Info");
|
||||
|
||||
@@ -11,16 +11,24 @@
|
||||
#include <common_structs.h>
|
||||
#include <defines.h>
|
||||
|
||||
namespace Editor {
|
||||
#include "engine/editor/Editor.h"
|
||||
#include "port/Game.h"
|
||||
|
||||
namespace EditorNamespace {
|
||||
|
||||
SceneExplorerWindow::~SceneExplorerWindow() {
|
||||
SPDLOG_TRACE("destruct editor window");
|
||||
}
|
||||
|
||||
void SceneExplorerWindow::DrawElement() {
|
||||
ImGui::Text("This is your Scene Explorer window!");
|
||||
if (ImGui::Button("Click Me")) {
|
||||
// Handle button click (example)
|
||||
ImGui::Text("Scene");
|
||||
|
||||
int id = 0; // id for now because we don't have unique names atm
|
||||
for (auto& object : gEditor.eGameObjects) {
|
||||
std::string label = fmt::format("Object {}", id++);
|
||||
if (ImGui::Button(label.c_str())) {
|
||||
gEditor.SelectObjectFromSceneExplorer(&object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <libultraship/libultraship.h>
|
||||
#include "port/Game.h"
|
||||
|
||||
namespace Editor {
|
||||
|
||||
namespace EditorNamespace {
|
||||
class SceneExplorerWindow : public Ship::GuiWindow {
|
||||
public:
|
||||
using Ship::GuiWindow::GuiWindow;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <common_structs.h>
|
||||
#include <defines.h>
|
||||
|
||||
namespace Editor {
|
||||
namespace EditorNamespace {
|
||||
|
||||
ToolsWindow::~ToolsWindow() {
|
||||
SPDLOG_TRACE("destruct editor window");
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <libultraship/libultraship.h>
|
||||
|
||||
namespace Editor {
|
||||
namespace EditorNamespace {
|
||||
class ToolsWindow : public Ship::GuiWindow {
|
||||
public:
|
||||
using Ship::GuiWindow::GuiWindow;
|
||||
|
||||
Reference in New Issue
Block a user