summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-01-14 15:50:04 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-01-14 15:50:04 -0500
commit80a67230fe192287503092a3d256aea3a494409c (patch)
tree187f2e7a41e0cd206d9969284a3abce4028d89f5 /editor
parent46d814de510d0a7753c3e49eed3b3440d1c7c681 (diff)
pke: camera can track a given target
Diffstat (limited to 'editor')
-rw-r--r--editor/editor.cpp96
1 files changed, 68 insertions, 28 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 024e855..2bcca0a 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -288,11 +288,12 @@ void PkeEditor_Tick(double delta) {
selectedCamera = CameraHandle_MAX;
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;
+ CompInstance *inst = ECS_GetInstance(ActiveCamera->phys.instHandle);
+ inst->bt.motionState->getWorldTransform(btfm);
+ NullCameraInstance.bt.motionState->setWorldTransform(btfm);
+ NullCameraInstance.bt.rigidBody->setWorldTransform(btfm);
+ NullCameraInstance.bt.rigidBody->activate();
+ NullCamera.phys.targetInstHandle = ActiveCamera->phys.targetInstHandle;
NullCamera.type = ActiveCamera->type;
NullCamera.view = ActiveCamera->view;
NullCamera.stale = PKE_CAMERA_STALE_ALL;
@@ -309,7 +310,7 @@ void PkeEditor_Tick(double delta) {
holder = PkeInput_Query(dbgCtrl_CameraRot);
btTransform trfm;
- NullCamera.phys.inst->bt.motionState->getWorldTransform(trfm);
+ NullCameraInstance.bt.motionState->getWorldTransform(trfm);
if (holder.type != InputEventHash{0}) {
const PkeCursorPosEvent *posEvent = static_cast<PkeCursorPosEvent *>(holder.ptr);
@@ -426,9 +427,9 @@ void PkeEditor_Tick(double delta) {
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();
+ NullCameraInstance.bt.motionState->setWorldTransform(trfm);
+ NullCameraInstance.bt.rigidBody->setWorldTransform(trfm);
+ NullCameraInstance.bt.rigidBody->activate();
}
holder = PkeInput_Query(dbgCtrl_DeleteSelectedItem);
@@ -700,17 +701,21 @@ void RecordImGuiEntityTypes() {
}
void RecordImGuiCameras() {
+ CompInstance *activeInst = nullptr;
+ CompInstance *activeTargetInst = nullptr;
if (!ImGui::Begin("Cameras")) {
ImGui::End();
return;
}
+ activeInst = ECS_GetInstance(ActiveCamera->phys.instHandle);
+ activeTargetInst = ECS_GetInstance(ActiveCamera->phys.targetInstHandle);
if (ImGui::Button("Create")) {
InstPos instPos{};
instPos.mass = 1.f;
- ActiveCamera->phys.inst->bt.motionState->getWorldTransform(instPos.posRot);
- instPos.scale = ActiveCamera->phys.inst->bt.rigidBody->getCollisionShape()->getLocalScaling();
+ activeInst->bt.motionState->getWorldTransform(instPos.posRot);
+ instPos.scale = activeInst->bt.rigidBody->getCollisionShape()->getLocalScaling();
auto &cam = PkeCamera_Register(instPos);
- cam.phys.targetInst = ActiveCamera->phys.targetInst;
+ cam.phys.targetInstHandle = ActiveCamera->phys.targetInstHandle;
cam.type = ActiveCamera->type;
cam.view = ActiveCamera->view;
cam.isPrimary = false;
@@ -752,17 +757,13 @@ void RecordImGuiCameras() {
}
ImGui::SameLine();
if (ImGui::Button("Select")) {
- selectedEntity = cam.phys.inst;
+ selectedEntity = ECS_GetInstance(cam.phys.instHandle);
}
ImGui::EndDisabled();
ImGui::TableSetColumnIndex(1);
ImGui::Text("0x%08X 0x%08X", cam.handle.bucketIndex, cam.handle.itemIndex);
ImGui::TableSetColumnIndex(2);
- if (cam.phys.targetInst != nullptr) {
- ImGui::Text("0x%08X 0x%08X", cam.phys.targetInst->entHandle.bucketIndex, cam.phys.targetInst->entHandle.itemIndex);
- } else {
- ImGui::Text("0x%p", cam.phys.targetInst);
- }
+ ImGui::Text("0x%08X 0x%08X", cam.phys.targetInstHandle.bucketIndex, cam.phys.targetInstHandle.itemIndex);
ImGui::TableSetColumnIndex(3);
ImGui::Text("%hhu", (unsigned char)cam.type);
ImGui::TableSetColumnIndex(4);
@@ -775,9 +776,10 @@ void RecordImGuiCameras() {
if (ImGui::Button("Update Position")) {
InstPos instPos{};
instPos.mass = 1.f;
- ActiveCamera->phys.inst->bt.motionState->getWorldTransform(instPos.posRot);
- instPos.scale = ActiveCamera->phys.inst->bt.rigidBody->getCollisionShape()->getLocalScaling();
- ECS_UpdateInstance(cam.phys.inst, instPos, true);
+ activeInst->bt.motionState->getWorldTransform(instPos.posRot);
+ instPos.scale = activeInst->bt.rigidBody->getCollisionShape()->getLocalScaling();
+ CompInstance *camInst = ECS_GetInstance(cam.phys.instHandle);
+ ECS_UpdateInstance(camInst, instPos, true);
}
ImGui::SameLine();
if (ImGui::Button("Make Primary")) {
@@ -1118,11 +1120,13 @@ 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);
- // 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) || PkeCamera_Get(selectedEntity->entHandle) != nullptr);
- if (ImGui::Button("Attach Active Camera")) {
- PkeCamera_AttachToInstance(ActiveCamera->camHandle, component);
+ // exclude EntityHandle_MAX so you can't target via the NullCamera
+ ImGui::BeginDisabled(ActiveCamera->handle == component->entHandle || ActiveCamera->handle == EntityHandle_MAX || ActiveCamera->phys.instHandle == InstanceHandle_MAX || PkeCamera_Get(selectedEntity->entHandle) != nullptr);
+ if (ImGui::Button("Set Active Camera Target")) {
+ PkeCamera_TargetInstance(ActiveCamera->camHandle, component);
}
+ ImGui::SameLine();
+ ImGui::Text("Active Camera: 0x%08X 0x%08X", ActiveCamera->handle.bucketIndex, ActiveCamera->handle.itemIndex);
ImGui::EndDisabled();
if (changed) {
@@ -1251,6 +1255,32 @@ void RecordImGuiProjectBrowser() {
ImGui::End();
}
+void RecordImGuiSceneBrowser() {
+ NULL_CHAR_ARR(text, 128);
+ CompInstance *instances;
+ EntityType *entType;
+ uint64_t i, k;
+ uint64_t bucketCount, itemCount;
+ if (!ImGui::Begin("SceneBrowser", &pkeSettings.editorSettings.isShowingSceneEditor)) {
+ ImGui::End();
+ return;
+ }
+
+ bucketCount = ECS_GetInstances_BucketCount();
+ for (i = 0; i < bucketCount; ++i) {
+ instances = ECS_GetInstances(0, itemCount);
+ for (k = 0; k < itemCount; ++k) {
+ entType = EntityType_FindByEntityHandle(instances[k].entHandle);
+ sprintf(text, "%s: %08x %08x", entType != nullptr ? entType->entityTypeCode.val : "(no type)", instances[k].instanceHandle.bucketIndex, instances[k].instanceHandle.itemIndex);
+ if (ImGui::Button(text)) {
+ selectedEntity = &instances[k];
+ }
+ }
+ }
+
+ ImGui::End();
+}
+
void RecordImGuiSceneEditor() {
if (!ImGui::Begin("SceneEditorEntityTypes", &pkeSettings.editorSettings.isShowingSceneEditor)) {
ImGui::End();
@@ -1271,6 +1301,7 @@ void RecordImGuiSceneEditor() {
if (selectedEntity != nullptr) {
static PkeArray<CompGrBinds *> entGrBinds;
static PkeArray<CompInstance *> entInstances;
+ static EntityType *entType;
bool reset = false;
if (entGrBinds.next > 0) {
if (entGrBinds.data[0]->entHandle != selectedEntity->entHandle) {
@@ -1284,6 +1315,7 @@ void RecordImGuiSceneEditor() {
if (reset) {
PkeArray_SoftReset(&entGrBinds);
PkeArray_SoftReset(&entInstances);
+ entType = nullptr;
}
if (entGrBinds.next == 0)
ECS_GetGrBinds(ECS_GetEntity(selectedEntity->entHandle), entGrBinds);
@@ -1296,6 +1328,13 @@ void RecordImGuiSceneEditor() {
entityInstancesToCreate.Push(entityType);
}
}
+ entType = EntityType_FindByEntityHandle(selectedEntity->entHandle);
+ if (entType != nullptr) {
+ ImGui::Text("%s: %s", "EntType: ", entType->entityTypeCode.val);
+ } else {
+ ImGui::Text("%s: %s", "EntType: ", "Unknown");
+ }
+ ImGui::Text("%s: %08x %08x", "Entity Handle: ", selectedEntity->entHandle.bucketIndex, selectedEntity->entHandle.itemIndex);
for (int64_t i = 0; i < entGrBinds.next; ++i) {
RecordImGui_CompGrBinds(true, entGrBinds.data[i]);
}
@@ -1315,6 +1354,7 @@ void PkeEditor_RecordImGui() {
RecordImGuiEditorWrapper();
RecordImGuiProjectSettingsEditor();
RecordImGuiProjectBrowser();
+ RecordImGuiSceneBrowser();
RecordImGuiSceneEditor();
RecordImGuiUBO();
RecordImGuiCameras();
@@ -1421,9 +1461,9 @@ void PkeEditor_Init() {
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();
+ NullCameraInstance.bt.motionState->setWorldTransform(trfm);
+ NullCameraInstance.bt.rigidBody->setWorldTransform(trfm);
+ NullCameraInstance.bt.rigidBody->activate();
NullCamera.type = PKE_CAMERA_TYPE_PERSPECTIVE,
NullCamera.view = PKE_CAMERA_VIEW_FREE,
NullCamera.stale = PKE_CAMERA_STALE_ALL,