code review fixes

This commit is contained in:
Philip Rosedale 2017-04-25 22:14:03 -07:00
parent 663e682f23
commit c69d064cc3
4 changed files with 33 additions and 35 deletions

View file

@ -34,7 +34,7 @@ var sword1 = Entities.addEntity({
grabbable:true grabbable:true
} }
}) })
}) });
var sword2 = Entities.addEntity({ var sword2 = Entities.addEntity({
type: "Box", type: "Box",
@ -50,7 +50,7 @@ var sword2 = Entities.addEntity({
grabbable:true grabbable:true
} }
}) })
}) });
Script.scriptEnding.connect(function scriptEnding() { Script.scriptEnding.connect(function scriptEnding() {
Entities.deleteEntity(sword1); Entities.deleteEntity(sword1);

View file

@ -31,8 +31,7 @@
angularTimeScale: timescale, angularTimeScale: timescale,
ttl: ACTION_TTL ttl: ACTION_TTL
}; };
var success = Entities.updateAction(_this.copy, _this.actionID, props); Entities.updateAction(_this.copy, _this.actionID, props);
return;
} }
function createSpringAction(timescale) { function createSpringAction(timescale) {
@ -46,7 +45,6 @@
ttl: ACTION_TTL ttl: ACTION_TTL
}; };
_this.actionID = Entities.addAction("spring", _this.copy, props); _this.actionID = Entities.addAction("spring", _this.copy, props);
return;
} }
function createCopy() { function createCopy() {
@ -69,7 +67,7 @@
grabbable:false grabbable:false
} }
}) })
} };
_this.copy = Entities.addEntity(props); _this.copy = Entities.addEntity(props);
} }

View file

@ -111,7 +111,6 @@
ttl: ACTION_TTL ttl: ACTION_TTL
}; };
var success = Entities.updateAction(_this.copy, _this.actionID, props); var success = Entities.updateAction(_this.copy, _this.actionID, props);
return;
} }
function createSpringAction(timescale) { function createSpringAction(timescale) {
@ -148,7 +147,7 @@
grabbable:false grabbable:false
} }
}) })
} };
_this.copy = Entities.addEntity(props); _this.copy = Entities.addEntity(props);
} }

View file

@ -28,39 +28,40 @@ var COLOR3 = { red: 51, green: 51, blue: 255 };
var inFront = Vec3.sum(Camera.getPosition(), Vec3.multiply(radius * 20, Quat.getFront(Camera.getOrientation()))); var inFront = Vec3.sum(Camera.getPosition(), Vec3.multiply(radius * 20, Quat.getFront(Camera.getOrientation())));
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
bodies.push(Entities.addEntity({ bodies.push(Entities.addEntity({
type: "Model", type: "Model",
modelURL: (i == 0) ? EARTH : MOON, modelURL: (i == 0) ? EARTH : MOON,
shapeType: "sphere", shapeType: "sphere",
dimensions: { x: radius * 2, y: radius * 2, z: radius * 2}, dimensions: { x: radius * 2, y: radius * 2, z: radius * 2},
position: Vec3.sum(inFront, { x: 0, y: i * 2 * radius, z: 0 }), position: Vec3.sum(inFront, { x: 0, y: i * 2 * radius, z: 0 }),
gravity: { x: 0, y: 0, z: 0 }, gravity: { x: 0, y: 0, z: 0 },
damping: 0.0, damping: 0.0,
angularDamping: 0.0, angularDamping: 0.0,
dynamic: true dynamic: true
})); }));
} }
Script.update.connect(function(dt) { Script.update.connect(function(dt) {
var props = []; var props = [];
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
props.push(Entities.getEntityProperties(bodies[i])); props.push(Entities.getEntityProperties(bodies[i]));
}
for (var i = 0; i < n; i++) {
if (props[i].dynamic) {
var dv = { x: 0, y: 0, z: 0};
for (var j = 0; j < n; j++) {
if (i != j) {
dv = Vec3.sum(dv, Vec3.multiply(G * dt / Vec3.distance(props[i].position, props[j].position), Vec3.normalize(Vec3.subtract(props[j].position, props[i].position))));
}
}
Entities.editEntity(bodies[i], { velocity: Vec3.sum(props[i].velocity, dv)});
} }
} for (var i = 0; i < n; i++) {
if (props[i].dynamic) {
var dv = { x: 0, y: 0, z: 0};
for (var j = 0; j < n; j++) {
if (i != j) {
dv = Vec3.sum(dv, Vec3.multiply(G * dt / Vec3.distance(props[i].position, props[j].position),
Vec3.normalize(Vec3.subtract(props[j].position, props[i].position))));
}
}
Entities.editEntity(bodies[i], { velocity: Vec3.sum(props[i].velocity, dv)});
}
}
}); });
Script.scriptEnding.connect(function scriptEnding() { Script.scriptEnding.connect(function scriptEnding() {
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
Entities.deleteEntity(bodies[i]); Entities.deleteEntity(bodies[i]);
} }
}); });