Skip to content

Commit

Permalink
Prevent fly camera from moving on first event (which can be very larg…
Browse files Browse the repository at this point in the history
…e if mouse was out of the window)
  • Loading branch information
daredevildave committed Feb 18, 2015
1 parent ecf57f8 commit 279c8ba
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions extras/camera/camera_fly.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pc.script.create('flyCamera', function (app) {
var eulers = this.entity.getLocalEulerAngles()
this.ex = eulers.x;
this.ey = eulers.y;
this._moved = false;

// Disabling the context menu stops the browser displaying a menu when
// you right-click the page
Expand Down Expand Up @@ -44,6 +45,11 @@ pc.script.create('flyCamera', function (app) {

onMouseMove: function (event) {
// Update the current Euler angles, clamp the pitch.
if (!this._moved) {
// first move event can be very large
this._moved = true;
return;
}
this.ex -= event.dy / 5;
this.ex = pc.math.clamp(this.ex, -90, 90);
this.ey -= event.dx / 5;
Expand Down

0 comments on commit 279c8ba

Please sign in to comment.