Skip to content

Commit

Permalink
Added Zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-deluna authored Aug 6, 2024
1 parent 9ca8276 commit d9aab0d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Graphics/Camera.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ class Camera
*/
public float $staticWorldHeight = 100.0;

/**
* Camera Zoom
*
* Only applies to orthographic projection modes and vg contexts.
*/
public float $zoom = 1.0;

/**
* Flip the viewport on the y axis
* The camera by default uses y+ as up, this will flip the viewport to use y- as up.
Expand Down Expand Up @@ -317,17 +324,17 @@ public function getWSPointFromSS(Viewport $viewport, Vec2 $screenSpacePos) : Vec
*/
public function transformVGSpace(Viewport $viewport, VGContext $vg) : void
{
$scaleFactorY = $viewport->screenSpaceHeight / $viewport->height;
$scaleFactorX = $viewport->screenSpaceWidth / $viewport->width;

$vg->scale($scaleFactorX, $scaleFactorY);

$offsetX = -$viewport->left;
$offsetY = -$viewport->top;
$offsetX -= $this->transform->position->x;
$offsetY -= $this->transform->position->y;

$vg->translate($offsetX, $offsetY);

$scaleFactorX = $viewport->screenSpaceWidth / $viewport->width * $this->zoom;
$scaleFactorY = $viewport->screenSpaceHeight / $viewport->height * $this->zoom;

$vg->scale($scaleFactorX, $scaleFactorY);
}

/**
Expand Down

0 comments on commit d9aab0d

Please sign in to comment.