summaryrefslogtreecommitdiff
path: root/src/window.cpp
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 /src/window.cpp
parent46d814de510d0a7753c3e49eed3b3440d1c7c681 (diff)
pke: camera can track a given target
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/window.cpp b/src/window.cpp
index f5821ae..e44b498 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -909,10 +909,17 @@ void UpdatePresentDescriptorSets() {
void UpdateCamera() {
if (ActiveCamera->stale == PkeCameraStaleFlags{0}) return;
+ CompInstance *inst = nullptr;
+ CompInstance *targetInst = nullptr;
glm::vec3 gPos;
glm::quat gRot;
btTransform trfm;
- ActiveCamera->phys.inst->bt.motionState->getWorldTransform(trfm);
+ if (ActiveCamera == &NullCamera) {
+ inst = &NullCameraInstance;
+ } else {
+ inst = ECS_GetInstance(ActiveCamera->phys.instHandle);
+ }
+ inst->bt.motionState->getWorldTransform(trfm);
BulletToGlm(trfm.getOrigin(), gPos);
BulletToGlm(trfm.getRotation(), gRot);
if (bool(ActiveCamera->stale & PKE_CAMERA_STALE_POS)) {
@@ -923,12 +930,13 @@ void UpdateCamera() {
UBO.view = glm::mat4_cast(gRot);
} else if (bool(ActiveCamera->view == PKE_CAMERA_VIEW_TARGET)) {
glm::vec3 gTargetPos{0.f, 0.f, 0.f};
- if (ActiveCamera->phys.targetInst != nullptr && ActiveCamera->phys.targetInst != CAFE_BABE(CompInstance)) {
+ targetInst = ECS_GetInstance(ActiveCamera->phys.targetInstHandle);
+ if (targetInst != nullptr && targetInst != CAFE_BABE(CompInstance)) {
btTransform targetTrfm;
- ActiveCamera->phys.targetInst->bt.motionState->getWorldTransform(targetTrfm);
- BulletToGlm(trfm.getOrigin(), gTargetPos);
+ targetInst->bt.motionState->getWorldTransform(targetTrfm);
+ BulletToGlm(targetTrfm.getOrigin(), gTargetPos);
}
- UBO.view = glm::lookAt(glm::vec3(0), gPos - gTargetPos, glm::vec3(0.f, 1.f, 0.f));
+ UBO.view = glm::lookAt(glm::vec3(0), gPos + gTargetPos, glm::vec3(0.f, 1.f, 0.f));
}
}
if (bool(ActiveCamera->stale & PKE_CAMERA_STALE_PERSPECTIVE)) {