Skip to content

Commit 24b382e

Browse files
committed
Rotation and zooming for camera
1 parent 6f19416 commit 24b382e

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

v3/src/camera/Camera-2.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var Camera = function (x, y, width, height)
1111
this.statePositionY = 0.0;
1212
this.scrollX = 0.0;
1313
this.scrollY = 0.0;
14+
this.zoom = 1.0;
15+
this.rotation = 0.0;
1416
};
1517

1618
Camera.prototype.setState = function (state)
@@ -27,10 +29,10 @@ Camera.prototype.preRender = function (interpolation, renderer)
2729
this.statePositionX = stateTransform.positionX;
2830
this.statePositionY = stateTransform.positionY;
2931

30-
stateTransform.positionX = this.x;
31-
stateTransform.positionY = this.y;
32+
stateTransform.positionX = this.statePositionX + this.x;
33+
stateTransform.positionY = this.statePositionY + this.y;
3234

33-
Transform.updateRoot(stateTransform, -this.scrollX, -this.scrollY);
35+
Transform.updateRoot(stateTransform, -this.scrollX, -this.scrollY, this.zoom, this.rotation);
3436
};
3537

3638
Camera.prototype.postRender = function ()

v3/src/components/experimental-Transform-2.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Transform.prototype.remove = function (transform)
7272
}
7373
};
7474

75-
Transform.updateRoot = function (root, globalOffsetX, globalOffsetY)
75+
Transform.updateRoot = function (root, globalOffsetX, globalOffsetY, globalScale, globalRotation)
7676
{
7777
var currentChild = null;
7878
var stackLength = 0;
@@ -119,9 +119,9 @@ Transform.updateRoot = function (root, globalOffsetX, globalOffsetY)
119119

120120
transX = child.positionX + globalOffsetX;
121121
transY = child.positionY + globalOffsetY;
122-
scaleX = child.scaleX;
123-
scaleY = child.scaleY;
124-
rotation = child.rotation;
122+
scaleX = child.scaleX * globalScale;
123+
scaleY = child.scaleY * globalScale;
124+
rotation = child.rotation + globalRotation;
125125
tcos = cos(rotation);
126126
tsin = sin(rotation);
127127

@@ -136,8 +136,8 @@ Transform.updateRoot = function (root, globalOffsetX, globalOffsetY)
136136
world[1] = l0 * p1 + l1 * p3;
137137
world[2] = l2 * p0 + l3 * p2;
138138
world[3] = l2 * p1 + l3 * p3;
139-
world[4] = transX * p0 + transY * p2 + p4;
140-
world[5] = transX * p1 + transY * p3 + p5;
139+
world[4] = transX * world[0] + transY * world[2] + p4;
140+
world[5] = transX * world[1] + transY * world[3] + p5;
141141

142142
if (child.hasChildren)
143143
{

0 commit comments

Comments
 (0)