Skip to content

Commit 7f89470

Browse files
committed
math
1 parent 17c17b2 commit 7f89470

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

Applications/Level/Sensor.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function drawHorizon(roll, pitch) {
2222

2323
ctx.beginPath();
2424
ctx.fillStyle = "green";
25-
// ctx.lineWidth = 5;
2625
ctx.moveTo(-horizon.width, pitchOffset);
2726
ctx.lineTo(horizon.width, pitchOffset);
2827
ctx.lineTo(horizon.width, horizon.height);
@@ -37,7 +36,6 @@ if (typeof ondevicemotion !== "undefined") {
3736
var g = e.accelerationIncludingGravity;
3837
var acceleration = new Vector3D(g.x, g.y, g.z);
3938
acceleration.normalize();
40-
// console.log("Acceleration norma:", acceleration);
4139

4240
var roll = Math.atan2(acceleration.x, acceleration.z);
4341
var pitch = acceleration.y;

Scripts/physics.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ function Vector3D(x, y, z) {
4040
}
4141
}
4242

43+
Vector3D.prototype.div = function (amount) {
44+
this.x /= amount, this.y /= amount, this.z /= amount;
45+
return this;
46+
}
47+
4348
Vector3D.prototype.normalize = function () {
44-
var thing = this.x + this.y + this.z;
45-
this.x /= thing;
46-
this.y /= thing;
47-
this.z /= thing;
49+
var sum = this.x + this.y + this.z;
50+
this.div(sum);
51+
return this;
4852
}
4953

5054
function Rectangle(x, y, width, height) {

0 commit comments

Comments
 (0)