From ac48ce776c153c75155024180dd459d82f731e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Do=CC=88ring?= Date: Thu, 6 Jun 2024 11:58:39 +0200 Subject: [PATCH] Missing functions --- src/Geo/AABB.php | 19 +++++++++++++++++++ src/System/VISUCameraSystem.php | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Geo/AABB.php b/src/Geo/AABB.php index f5fe296..2361423 100644 --- a/src/Geo/AABB.php +++ b/src/Geo/AABB.php @@ -213,4 +213,23 @@ public function intersectRayDistance(Ray $ray) : ?float return $tmin; } + + /** + * Returns an array of 8 Vec3 representing the corners of the AABB + * + * @return array + */ + public function getCorners() : array + { + return [ + new Vec3($this->min->x, $this->min->y, $this->min->z), + new Vec3($this->max->x, $this->min->y, $this->min->z), + new Vec3($this->max->x, $this->max->y, $this->min->z), + new Vec3($this->min->x, $this->max->y, $this->min->z), + new Vec3($this->min->x, $this->min->y, $this->max->z), + new Vec3($this->max->x, $this->min->y, $this->max->z), + new Vec3($this->max->x, $this->max->y, $this->max->z), + new Vec3($this->min->x, $this->max->y, $this->max->z), + ]; + } } diff --git a/src/System/VISUCameraSystem.php b/src/System/VISUCameraSystem.php index cbdb4df..3ee734a 100644 --- a/src/System/VISUCameraSystem.php +++ b/src/System/VISUCameraSystem.php @@ -305,6 +305,8 @@ public function updateVISUFlyingCamera(EntitiesInterface $entities, Camera $came $camera->transform->markDirty(); } + private ?Mat4 $frozenView = null; + /** * Create a camera data structure for the given render target. * @@ -325,6 +327,29 @@ public function getCameraData(EntitiesInterface $entities, RenderTarget $renderT /** @var Mat4 */ $projectionViewMatrix = $projectionMatrix * $viewMatrix; $inverseProjectionViewMatrix = Mat4::inverted($projectionViewMatrix); + + if ($this->input->isMouseButtonPressed(MouseButton::RIGHT)) { + $this->frozenView = $viewMatrix->copy(); + } elseif ($this->input->isMouseButtonPressed(MouseButton::MIDDLE)) { + $this->frozenView = null; + } + + global $showFrustum; + if ($this->frozenView) { + // // debug + // $testView = new Mat4; + // $testView->rotate(GLM::radians(45.0), new Vec3(1.0, 0.0, 0.0)); + // $testView->rotate(GLM::radians(sin(glfwGetTime()) * 90), new Vec3(0.0, 1.0, 0.0)); + + $fakeView = $this->frozenView->copy(); + $projectionViewMatrix = $projectionMatrix * $fakeView; + $inverseProjectionViewMatrix = Mat4::inverted($projectionViewMatrix); + + $showFrustum = true; + } else { + $showFrustum = false; + } + return new CameraData( frameCamera: $camera, renderCamera: $camera,