Repository navigation
Expand file tree
/
Copy pathpoint.js
More file actions
72 lines (52 loc) · 1.54 KB
/
Copy pathpoint.js
File metadata and controls
72 lines (52 loc) · 1.54 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function vectorize(object,atrname,defaults) {
setdict = {}
var attribute = object.get(atrname)
if (!attribute) {
setdict[atrname] = makeV.apply(this,defaults).set({host: object})
return setdict
}
if (attribute.constructor == Array) {
setdict[atrname] = makeV.apply(this,attribute).set({host: object})
return setdict
}
if (attribute.constructor === Vector) {
attribute.set({host: object})
return {}
}
setdict[atrname] = makeV.apply(this,defaults).set({host: object})
return setdict
}
var Point = Vector.extend4000({
defaults: { name: 'point' },
initialize: function() {
var setdict = {}
_.extend(setdict, vectorize(this,'velocity',[0,0]))
_.extend(setdict, vectorize(this,'acceleration',[0,0]))
this.set(setdict)
},
acceleration: function() {
return this.get('acceleration')
},
velocity: function() {
return this.get('velocity')
},
accelerate: function(vector) {
this.acceleration().iadd(vector);
},
simulate: function(delta) {
this.velocity().iadd(this.acceleration().mul(delta));
//this.acceleration().zero();
this.iadd(this.velocity().mul(delta));
}
})
var Constraint = Backbone.Model.extend4000({
initialize: function() {
this.target = point1().distance(point2().position);
},
point1: function() {
return this.get(point1)
},
point2: function() {
return this.get(point2)
}
})