-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizika.js
executable file
·46 lines (41 loc) · 1.06 KB
/
fizika.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
*
* returns reversed vector
* @returns Reversed vector
*/
Vector.prototype.Rev = function() {
this.x(-1);
};
Force = function(name, vector) {
this.name = name;
this.vector = vector;
};
Force.prototype = {
};
BasePhysics = function() {
this.Forces = [];
};
//@todo mix to sceneObject
BasePhysics.prototype = {
"addForce": function(force) {
this.Forces.push(force);
},
"applyForces": function() {
//find vector sum
if (!this.isIngame) {
return false;
}
if (this.isJumping){
return false;
}
var vec = Vector.create([this.movementParam.dx, this.movementParam.dy, 0]);
var i = 0;
for (i = 0; i < this.Forces.length; i++) {
if (undefined !== this.Forces[i].vector){
vec = vec.add(this.Forces[i].vector);
}
}
this.movementParam.dx = vec.elements[0];
this.movementParam.dy = vec.elements[1];
}
};