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

View file

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

View file

@ -111,7 +111,6 @@
ttl: ACTION_TTL
};
var success = Entities.updateAction(_this.copy, _this.actionID, props);
return;
}
function createSpringAction(timescale) {
@ -148,7 +147,7 @@
grabbable:false
}
})
}
};
_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())));
for (var i = 0; i < n; i++) {
bodies.push(Entities.addEntity({
type: "Model",
modelURL: (i == 0) ? EARTH : MOON,
shapeType: "sphere",
dimensions: { x: radius * 2, y: radius * 2, z: radius * 2},
position: Vec3.sum(inFront, { x: 0, y: i * 2 * radius, z: 0 }),
gravity: { x: 0, y: 0, z: 0 },
damping: 0.0,
angularDamping: 0.0,
dynamic: true
bodies.push(Entities.addEntity({
type: "Model",
modelURL: (i == 0) ? EARTH : MOON,
shapeType: "sphere",
dimensions: { x: radius * 2, y: radius * 2, z: radius * 2},
position: Vec3.sum(inFront, { x: 0, y: i * 2 * radius, z: 0 }),
gravity: { x: 0, y: 0, z: 0 },
damping: 0.0,
angularDamping: 0.0,
dynamic: true
}));
}
Script.update.connect(function(dt) {
var props = [];
for (var i = 0; i < n; 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)});
var props = [];
for (var i = 0; i < n; 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)});
}
}
});
Script.scriptEnding.connect(function scriptEnding() {
for (var i = 0; i < n; i++) {
Entities.deleteEntity(bodies[i]);
}
for (var i = 0; i < n; i++) {
Entities.deleteEntity(bodies[i]);
}
});