summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2024-01-18 22:37:02 -0500
committerJonathan Bradley <jcb@pikum.xyz>2024-01-18 22:37:02 -0500
commit1b48d1382d2d57a822201f34743a51813798b348 (patch)
tree612672a4be654b38f3b44580f85e4f0637952512 /editor
parent2e680ebd77236f7b62b9ded1b083c86f9e13b1c8 (diff)
camera checkpoint - large refactor for attempting to let physics own camera position
Diffstat (limited to 'editor')
-rw-r--r--editor/editor.cpp129
1 files changed, 68 insertions, 61 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index f22c3dd..e0ac795 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -12,6 +12,7 @@
#include "level.hpp"
#include "math-helpers.hpp"
#include "player-input.hpp"
+#include "plugins.hpp"
#include "project.hpp"
#include "thread_pool.hpp"
#include "vendor/glm_include.hpp"
@@ -47,15 +48,6 @@ const char* const dbgCtrl_DeleteSelectedItem = "debug-delete-selected-item";
ThreadPoolHandle threadPoolHandle = ThreadPoolHandle_MAX;
-PkeCamera cameraDbg {
- .pos = glm::vec3(4.f, 4.f, 4.f),
- .rot = glm::quat(1.f, 0.f, 0.f, 0.f),
- .target = glm::vec3(0.f),
- .type = PKE_CAMERA_TYPE_PERSPECTIVE,
- .view = PKE_CAMERA_VIEW_FREE,
- .stale = PKE_CAMERA_STALE_ALL,
-};
-
InputActionSetHandle debugControlsHandle = InputActionSetHandle_MAX;
bool shouldSetupEditor = true;
bool shouldDisableEditor = false;
@@ -290,15 +282,17 @@ void PkeEditor_Tick(double delta) {
pkeSettings.editorSettings.isUsingDebugCamera = true;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
selectedCamera = CameraHandle_MAX;
- if (ActiveCamera != &cameraDbg) {
- cameraDbg.pos = ActiveCamera->pos;
- if (ActiveCamera->view == cameraDbg.view) {
- cameraDbg.rot = ActiveCamera->rot;
- } else {
- cameraDbg.rot = glm::quat(UBO.view);
- }
- cameraDbg.stale = PKE_CAMERA_STALE_ALL;
- ActiveCamera = &cameraDbg;
+ if (ActiveCamera != &NullCamera) {
+ btTransform btfm;
+ ActiveCamera->phys.inst->bt.motionState->getWorldTransform(btfm);
+ NullCamera.phys.inst->bt.motionState->setWorldTransform(btfm);
+ NullCamera.phys.inst->bt.rigidBody->setWorldTransform(btfm);
+ NullCamera.phys.inst->bt.rigidBody->activate();
+ NullCamera.phys.targetInst = ActiveCamera->phys.targetInst;
+ NullCamera.type = ActiveCamera->type;
+ NullCamera.view = ActiveCamera->view;
+ NullCamera.stale = PKE_CAMERA_STALE_ALL;
+ ActiveCamera = &NullCamera;
}
} else if (toggleCameraMovement->isPressed && pkeSettings.editorSettings.isUsingDebugCamera == true) {
pkeSettings.editorSettings.isUsingDebugCamera = false;
@@ -307,19 +301,29 @@ void PkeEditor_Tick(double delta) {
}
}
- if (pkeSettings.editorSettings.isUsingDebugCamera && ActiveCamera == &cameraDbg) {
+ if (pkeSettings.editorSettings.isUsingDebugCamera && ActiveCamera == &NullCamera) {
holder = PkeInput_Query(dbgCtrl_CameraRot);
+
+ btTransform trfm;
+ NullCamera.phys.inst->bt.motionState->getWorldTransform(trfm);
+
if (holder.type != InputEventHash{0}) {
const PkeCursorPosEvent *posEvent = static_cast<PkeCursorPosEvent *>(holder.ptr);
if (posEvent->xMotion || posEvent->yMotion) {
- glm::vec3 axis1Heading = glm::conjugate(cameraDbg.rot) * glm::vec3(1.f, 0.f, 0.f);
- glm::vec3 axis2Heading = glm::conjugate(cameraDbg.rot) * glm::vec3(0.f, 1.f, 0.f);
+ glm::quat gRot;
+ BulletToGlm(trfm.getRotation(), gRot);
+
+ glm::vec3 axis1Heading = glm::conjugate(gRot) * glm::vec3(1.f, 0.f, 0.f);
+ glm::vec3 axis2Heading = glm::conjugate(gRot) * glm::vec3(0.f, 1.f, 0.f);
glm::quat pitch = glm::angleAxis(float(posEvent->yMotion) * 0.01f, glm::normalize(axis1Heading));
glm::quat yaw = glm::angleAxis(float(posEvent->xMotion) * 0.01f, glm::normalize(axis2Heading));
- glm::quat rot = cameraDbg.rot * pitch * yaw;
+ glm::quat rot = gRot * pitch * yaw;
auto eul = glm::eulerAngles(rot);
- cameraDbg.rot = glm::quat(eul);
- cameraDbg.stale = cameraDbg.stale | PKE_CAMERA_STALE_ROT;
+ gRot = glm::quat(eul);
+ btQuaternion bRot;
+ GlmToBullet(gRot, bRot);
+ trfm.setRotation(bRot);
+ NullCamera.stale = NullCamera.stale | PKE_CAMERA_STALE_ROT;
}
}
@@ -393,18 +397,31 @@ void PkeEditor_Tick(double delta) {
double axis2 = (forwardCount * accelerated) + -(backCount * accelerated);
double axis3 = -(upCount * accelerated) + (downCount * accelerated);
if (axis1 != 0 || axis2 != 0 || axis3 != 0) {
- glm::vec3 axis1Heading = glm::conjugate(cameraDbg.rot) * glm::vec3(-axis1, 0.f, 0.f);
- glm::vec3 axis2Heading = glm::conjugate(cameraDbg.rot) * glm::vec3(0.f, 0.f, axis2);
- glm::vec3 axis3Heading = glm::conjugate(cameraDbg.rot) * glm::vec3(0.f, axis3, 0.f);
- cameraDbg.pos += glm::vec3(axis1Heading + axis2Heading + axis3Heading);
- cameraDbg.stale = cameraDbg.stale | PKE_CAMERA_STALE_POS;
+ glm::quat gRot;
+ BulletToGlm(trfm.getRotation(), gRot);
+ glm::vec3 axis1Heading = glm::conjugate(gRot) * glm::vec3(-axis1, 0.f, 0.f);
+ glm::vec3 axis2Heading = glm::conjugate(gRot) * glm::vec3(0.f, 0.f, axis2);
+ glm::vec3 axis3Heading = glm::conjugate(gRot) * glm::vec3(0.f, axis3, 0.f);
+ glm::vec3 gPos;
+ BulletToGlm(trfm.getOrigin(), gPos);
+ gPos += glm::vec3(axis1Heading + axis2Heading + axis3Heading);
+ btVector3 bPos;
+ GlmToBullet(gPos, bPos);
+ trfm.setOrigin(bPos);
+ NullCamera.stale = NullCamera.stale | PKE_CAMERA_STALE_POS;
}
double axis4 = -(rotCCCount * delta) + (rotCCount * delta);
if (axis4 != 0.0) {
- cameraDbg.rot = glm::quat(glm::vec3(0.f, 0.f, axis4)) * cameraDbg.rot;
- cameraDbg.stale = cameraDbg.stale | PKE_CAMERA_STALE_ROT;
+ glm::quat gRot;
+ BulletToGlm(trfm.getRotation(), gRot);
+ gRot = glm::quat(glm::vec3(0.f, 0.f, axis4)) * gRot;
+ NullCamera.stale = NullCamera.stale | PKE_CAMERA_STALE_ROT;
}
+
+ NullCamera.phys.inst->bt.motionState->setWorldTransform(trfm);
+ NullCamera.phys.inst->bt.rigidBody->setWorldTransform(trfm);
+ NullCamera.phys.inst->bt.rigidBody->activate();
}
holder = PkeInput_Query(dbgCtrl_DeleteSelectedItem);
@@ -682,18 +699,15 @@ void RecordImGuiCameras() {
}
if (ImGui::Button("Create")) {
InstPos instPos{};
- btVector3 pos;
- btQuaternion quat;
- GlmToBullet(ActiveCamera->pos, pos);
- GlmToBullet(ActiveCamera->rot, quat);
instPos.mass = 1.f;
- instPos.posRot.setOrigin(pos);
- instPos.posRot.setRotation(quat);
+ ActiveCamera->phys.inst->bt.motionState->getWorldTransform(instPos.posRot);
+ instPos.scale = ActiveCamera->phys.inst->bt.rigidBody->getCollisionShape()->getLocalScaling();
auto &cam = PkeCamera_Register(instPos);
- cam.target = ActiveCamera->target;
+ cam.phys.targetInst = ActiveCamera->phys.targetInst;
cam.type = ActiveCamera->type;
cam.view = ActiveCamera->view;
cam.isPrimary = false;
+ PkeLevel_RegisterCamera(pkeSettings.rt.activeLevel, cam.camHandle);
}
static ImGuiTableFlags tableFlags{
@@ -703,11 +717,9 @@ void RecordImGuiCameras() {
if (ImGui::BeginTable("Entities", 9, tableFlags)) {
ImGui::TableSetupColumn("Interact");
ImGui::TableSetupColumn("CameraHandle");
- ImGui::TableSetupColumn("Pos");
- ImGui::TableSetupColumn("Rot");
ImGui::TableSetupColumn("Target");
ImGui::TableSetupColumn("Type");
- ImGui::TableSetupColumn("Orientation");
+ ImGui::TableSetupColumn("View");
ImGui::TableSetupColumn("Stale");
ImGui::TableSetupColumn("IsPrimary");
ImGui::TableHeadersRow();
@@ -738,18 +750,14 @@ void RecordImGuiCameras() {
ImGui::TableSetColumnIndex(1);
ImGui::Text("0x%016lX", cam.handle.hash);
ImGui::TableSetColumnIndex(2);
- ImGui::Text("%4.2f,%4.2f,%4.2f", cam.pos[0], cam.pos[1], cam.pos[2]);
+ ImGui::Text("0x%p", cam.phys.targetInst);
ImGui::TableSetColumnIndex(3);
- ImGui::Text("%4.2f,%4.2f,%4.2f,%4.2f", cam.rot[0], cam.rot[1], cam.rot[2], cam.rot[3]);
- ImGui::TableSetColumnIndex(4);
- ImGui::Text("%4.2f,%4.2f,%4.2f", cam.target[0], cam.target[1], cam.target[2]);
- ImGui::TableSetColumnIndex(5);
ImGui::Text("%hhu", cam.type);
- ImGui::TableSetColumnIndex(6);
+ ImGui::TableSetColumnIndex(4);
ImGui::Text("%hhu", cam.view);
- ImGui::TableSetColumnIndex(7);
+ ImGui::TableSetColumnIndex(5);
ImGui::Text("%hhu", cam.stale);
- ImGui::TableSetColumnIndex(8);
+ ImGui::TableSetColumnIndex(6);
ImGui::Text("%i", cam.isPrimary);
ImGui::PopID();
}
@@ -764,13 +772,6 @@ void RecordImGuiCameras() {
if (cam) {
bool isOrientTarget{bool(static_cast<PkeCameraView_T>(cam->view & PKE_CAMERA_VIEW_TARGET))};
bool isOrientFree{bool(static_cast<PkeCameraView_T>(cam->view & PKE_CAMERA_VIEW_FREE))};
- if (ImGui::InputScalarN("Pos", ImGuiDataType_Float, &cam->pos, 3, nullptr, nullptr, nullptr))
- cam->stale = cam->stale | PKE_CAMERA_STALE_POS;
- if (ImGui::InputScalarN("Rot", ImGuiDataType_Float, &cam->rot, 4, nullptr, nullptr, nullptr, isOrientFree ? 0 : inputTextFlags))
- cam->stale = cam->stale | PKE_CAMERA_STALE_ROT;
- if (ImGui::InputScalarN("Target", ImGuiDataType_Float, &cam->target, 3, nullptr, nullptr, nullptr, isOrientTarget ? 0 : inputTextFlags))
- cam->stale = cam->stale | PKE_CAMERA_STALE_ROT;
-
bool isPerspective{bool(static_cast<PkeCameraType_T>(cam->type & PKE_CAMERA_TYPE_PERSPECTIVE))};
bool isOrthogonal{bool(static_cast<PkeCameraType_T>(cam->type & PKE_CAMERA_TYPE_ORTHOGONAL))};
ImGui::BeginDisabled(isPerspective);
@@ -1092,7 +1093,8 @@ void RecordImGui_CompInstPos(bool readonly, CompInstance *component) {
ImGui::InputScalar("Phys - Rigid Body", ImGuiDataType_U64, &component->bt.rigidBody, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly);
ImGui::InputScalar("Phys - Motion State", ImGuiDataType_U64, &component->bt.motionState, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly);
- ImGui::BeginDisabled(ActiveCamera->handle == component->entHandle || ActiveCamera->phys.inst == nullptr || ActiveCamera->phys.inst == CAFE_BABE(CompInstance));
+ // exclude EntityHandle_MAX so you can't attach the NullCamera
+ ImGui::BeginDisabled(ActiveCamera->handle == component->entHandle || ActiveCamera->handle == EntityHandle_MAX || ActiveCamera->phys.inst == nullptr || ActiveCamera->phys.inst == CAFE_BABE(CompInstance));
if (ImGui::Button("Attach Active Camera")) {
PkeCamera_AttachToInstance(ActiveCamera->camHandle, component);
}
@@ -1389,11 +1391,16 @@ void PkeEditor_Init() {
debugControlsHandle = PkeInput_RegisterSet(debugControlsSet);
- NullCamera.pos = glm::vec3(-40.f, -40.f, -40.f),
- NullCamera.rot = glm::quat(1.f, 0.f, 0.f, 0.f),
- NullCamera.target = glm::vec3(0.f),
+ btTransform trfm{};
+ trfm.setIdentity();
+ trfm.setOrigin(btVector3(-40.f, -40.f, -40.f));
+ trfm.setRotation(btQuaternion(0.f, 0.f, 0.f, 1.f));
+
+ NullCamera.phys.inst->bt.motionState->setWorldTransform(trfm);
+ NullCamera.phys.inst->bt.rigidBody->setWorldTransform(trfm);
+ NullCamera.phys.inst->bt.rigidBody->activate();
NullCamera.type = PKE_CAMERA_TYPE_PERSPECTIVE,
- NullCamera.view = PKE_CAMERA_VIEW_TARGET,
+ NullCamera.view = PKE_CAMERA_VIEW_FREE,
NullCamera.stale = PKE_CAMERA_STALE_ALL,
threadPoolHandle = PkeThreads_Init(1, 1);