Skip to content

Commit

Permalink
Missing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-deluna committed Jun 6, 2024
1 parent 231d59b commit ac48ce7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Geo/AABB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec3>
*/
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),
];
}
}
25 changes: 25 additions & 0 deletions src/System/VISUCameraSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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,
Expand Down

0 comments on commit ac48ce7

Please sign in to comment.