Skip to content

Commit 2966c68

Browse files
committed
camera origin
1 parent 9ed1216 commit 2966c68

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

v3/src/camera/Camera.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ var Camera = function (x, y, width, height)
3232
this._flashGreen = 1.0;
3333
this._flashBlue = 1.0;
3434
this._flashAlpha = 0.0;
35+
36+
// origin
37+
this._follow = null;
3538
};
3639

3740
Camera.prototype.constructor = Camera;
@@ -163,13 +166,36 @@ Camera.prototype = {
163166

164167
preRender: function ()
165168
{
169+
var width = this.width;
170+
var height = this.height;
166171
var zoom = this.zoom;
172+
var matrix = this.matrix;
173+
var originX = width / 2;
174+
var originY = height / 2;
175+
var follow = this._follow;
176+
177+
if (follow != null)
178+
{
179+
if (follow.originX)
180+
{
181+
originX = follow.x + follow.originX;
182+
originY = follow.y + follow.originY;
183+
}
184+
else
185+
{
186+
originX = follow.x;
187+
originY = follow.y;
188+
}
189+
190+
originX = -this.scrollX - originX;
191+
originY = -this.scrollY - originY;
192+
}
167193

168-
this.matrix.applyITRS(
169-
this.x + this._shakeOffsetX, this.y + this._shakeOffsetY,
170-
this.rotation,
171-
zoom, zoom
172-
);
194+
matrix.loadIdentity();
195+
matrix.translate(this.x + originX, this.y + originY);
196+
matrix.rotate(this.rotation);
197+
matrix.scale(zoom, zoom);
198+
matrix.translate(-originX + this._shakeOffsetX, -originY + this._shakeOffsetY);
173199
},
174200

175201
destroy: function ()

0 commit comments

Comments
 (0)