From 24b382ece0e049906d3cc7e76fd1b2114cb6819e Mon Sep 17 00:00:00 2001 From: Felipe Alfonso Date: Wed, 8 Feb 2017 14:27:12 -0300 Subject: [PATCH] Rotation and zooming for camera --- v3/src/camera/Camera-2.js | 8 +++++--- v3/src/components/experimental-Transform-2.js | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/v3/src/camera/Camera-2.js b/v3/src/camera/Camera-2.js index 507b5e24d..7dc6bec19 100644 --- a/v3/src/camera/Camera-2.js +++ b/v3/src/camera/Camera-2.js @@ -11,6 +11,8 @@ var Camera = function (x, y, width, height) this.statePositionY = 0.0; this.scrollX = 0.0; this.scrollY = 0.0; + this.zoom = 1.0; + this.rotation = 0.0; }; Camera.prototype.setState = function (state) @@ -27,10 +29,10 @@ Camera.prototype.preRender = function (interpolation, renderer) this.statePositionX = stateTransform.positionX; this.statePositionY = stateTransform.positionY; - stateTransform.positionX = this.x; - stateTransform.positionY = this.y; + stateTransform.positionX = this.statePositionX + this.x; + stateTransform.positionY = this.statePositionY + this.y; - Transform.updateRoot(stateTransform, -this.scrollX, -this.scrollY); + Transform.updateRoot(stateTransform, -this.scrollX, -this.scrollY, this.zoom, this.rotation); }; Camera.prototype.postRender = function () diff --git a/v3/src/components/experimental-Transform-2.js b/v3/src/components/experimental-Transform-2.js index 45e746fa3..e50cd6dac 100644 --- a/v3/src/components/experimental-Transform-2.js +++ b/v3/src/components/experimental-Transform-2.js @@ -72,7 +72,7 @@ Transform.prototype.remove = function (transform) } }; -Transform.updateRoot = function (root, globalOffsetX, globalOffsetY) +Transform.updateRoot = function (root, globalOffsetX, globalOffsetY, globalScale, globalRotation) { var currentChild = null; var stackLength = 0; @@ -119,9 +119,9 @@ Transform.updateRoot = function (root, globalOffsetX, globalOffsetY) transX = child.positionX + globalOffsetX; transY = child.positionY + globalOffsetY; - scaleX = child.scaleX; - scaleY = child.scaleY; - rotation = child.rotation; + scaleX = child.scaleX * globalScale; + scaleY = child.scaleY * globalScale; + rotation = child.rotation + globalRotation; tcos = cos(rotation); tsin = sin(rotation); @@ -136,8 +136,8 @@ Transform.updateRoot = function (root, globalOffsetX, globalOffsetY) world[1] = l0 * p1 + l1 * p3; world[2] = l2 * p0 + l3 * p2; world[3] = l2 * p1 + l3 * p3; - world[4] = transX * p0 + transY * p2 + p4; - world[5] = transX * p1 + transY * p3 + p5; + world[4] = transX * world[0] + transY * world[2] + p4; + world[5] = transX * world[1] + transY * world[3] + p5; if (child.hasChildren) {