Skip to content

Commit

Permalink
Merge pull request #247 from Artur-Sampaio/conform_camera_to_viewport
Browse files Browse the repository at this point in the history
Ortho and Perspective camera projections now properly conform to viewport boundary sizes.
  • Loading branch information
xeolabs authored May 4, 2018
2 parents d307566 + 5884c06 commit 7f98fe6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/camera/ortho.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,24 @@

_update: function () {

const WIDTH_INDEX = 2;
const HEIGHT_INDEX = 3;

var scene = this.scene;
var scale = this._scale;
var canvas = scene.canvas.canvas;
var canvasWidth = canvas.clientWidth;
var canvasHeight = canvas.clientHeight;
var halfSize = 0.5 * scale;
var aspect = canvasWidth / canvasHeight;

var boundary = scene.viewport.boundary;
var boundaryWidth = boundary[WIDTH_INDEX];
var boundaryHeight = boundary[HEIGHT_INDEX];
var aspect = boundaryWidth / boundaryHeight;

var left;
var right;
var top;
var bottom;

if (canvasWidth > canvasHeight) {
if (boundaryWidth > boundaryHeight) {
left = -halfSize;
right = halfSize;
top = halfSize / aspect;
Expand Down
7 changes: 5 additions & 2 deletions src/camera/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@

_update: function () {

var canvas = this.scene.canvas.canvas;
var aspect = canvas.clientWidth / canvas.clientHeight;
const WIDTH_INDEX = 2;
const HEIGHT_INDEX = 3;

var boundary = this.scene.viewport.boundary;
var aspect = boundary[WIDTH_INDEX] / boundary[HEIGHT_INDEX];

var fov = this._fov;
var fovAxis = this._fovAxis;
Expand Down

0 comments on commit 7f98fe6

Please sign in to comment.