aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrahiel <rahiel@protonmail.ch>2015-10-15 22:19:41 +0200
committerrahiel <rahiel@protonmail.ch>2015-10-15 22:19:41 +0200
commit1a070349dff56a972dcffe4f486a4f24b3155142 (patch)
tree56f6e1b4ed1cbeab6c0e501dc63ba5ccac69a84d
parentd2b940f87f642384bb98386ed46db4871276d7f9 (diff)
make collisions a system parameter
-rw-r--r--sunsistemo.es6.js28
-rw-r--r--systems.es6.js18
2 files changed, 25 insertions, 21 deletions
diff --git a/sunsistemo.es6.js b/sunsistemo.es6.js
index bafdb54..66aab51 100644
--- a/sunsistemo.es6.js
+++ b/sunsistemo.es6.js
@@ -9,24 +9,23 @@ let bodyTexture = true;
let numBodies = 100;
let sphereP = 32;
-let system
-// let system = systems.genBodiesRot(numBodies, bodyTexture);
-let bodies;
+var steps;
+let system, bodies;
let spheres;
let sysDict = {
- "Random Bodies": systems.genBodies ,
- "Solar System": systems.genSolarSystem,
+ "Random Bodies": systems.genBodies,
+ "Solar System": systems.genSolarSystem,
"Total Angular Momentum": systems.genBodiesRot,
"Three Bodies": systems.gen3Bodies
};
-var steps;
-simulate("Random Bodies")
+// simulate("Random Bodies")
+simulate("Three Bodies");
function simulate(sysID){
let sysFunc = sysDict[sysID];
- system = sysFunc(numBodies, bodyTexture)
+ system = sysFunc(numBodies, bodyTexture);
bodies = system.bodies;
if (system.hasOwnProperty("stepsPerFrame")) {
steps = system.stepsPerFrame;
@@ -127,16 +126,17 @@ function animate() {
pos = system.scalePosition(pos);
}
spheres[i].position.set(pos.x, pos.y, pos.z);
+
spheres[i].rotation.x += bodies[i].rot.x;
spheres[i].rotation.y += bodies[i].rot.y;
spheres[i].rotation.z += bodies[i].rot.z;
- for (let j = i + 1; j < bodies.length; j++) {
- if ((i !== j) && (calc.touch(bodies[i],bodies[j]))) {
- spheres[i].texture
- calc.elasticCollision(bodies[i],bodies[j]);
- // calc.mergeCollision(bodies, spheres, scene, bodies[i], bodies[j]);
-
+ if (system.collisions) {
+ for (let j = i + 1; j < bodies.length; j++) {
+ if ((i !== j) && (calc.touch(bodies[i],bodies[j]))) {
+ calc.elasticCollision(bodies[i],bodies[j]);
+ // calc.mergeCollision(bodies, spheres, scene, bodies[i], bodies[j]);
+ }
}
}
}
diff --git a/systems.es6.js b/systems.es6.js
index 2beb90b..05827fa 100644
--- a/systems.es6.js
+++ b/systems.es6.js
@@ -166,20 +166,22 @@ export function genSolarSystem() {
// scalePosition: vec => vec.multiplyScalar(1E-08),
scalePosition: vec => vec.setLength(Math.pow(vec.length(), 1/6)),
// scalePosition: vec => vec.setLength(Math.log(vec.length)/Math.log(1.4)),
- camera: {x: 0, y: 0, z: 1300}
+ camera: {x: 0, y: 0, z: 1300},
+ collisions: false
};
}
export function gen3Bodies() {
- let s1 = new Body(1E19, new Vec3(0, 0, 0), new Vec3(0, 2, 0), 8, "mercury");
- let s2 = new Body(1E18, new Vec3(200, 0, 0), new Vec3(0, 900, 0), 8, "venus");
- let s3 = new Body(1E18, new Vec3(-200, 0, 0), new Vec3(0, -900, 0), 8, "earth");
+ let s1 = new Body(1E19, new Vec3(0, 0, 0), new Vec3(0, 2, 0), 12, "sun", new Vec3(0, 0.01, 0));
+ let s2 = new Body(1E18, new Vec3(200, 0, 0), new Vec3(0, 900, 0), 8, "mars", new Vec3(0, 0.02, 0));
+ let s3 = new Body(1E18, new Vec3(-200, 0, 0), new Vec3(0, -900, 0), 8, "earth", new Vec3(0, 0.04, 0));
let bodies = [s1, s2, s3];
return {
bodies: bodies,
stepsize: 0.001,
- camera: {x: 0, y: 0, z: 400}
+ camera: {x: 0, y: 0, z: 300},
+ collisions: false
};
}
@@ -200,7 +202,8 @@ export function genBodies(n, bodyTexture) {
return {
bodies: bodies,
stepsize: 0.001,
- camera: {x: 0, y: 0, z: 400}
+ camera: {x: 0, y: 0, z: 400},
+ collisions: true
};
}
@@ -224,7 +227,8 @@ export function genBodiesRot(n, bodyTexture) {
return {
bodies: bodies,
stepsize: 0.001,
- camera: {x: 0, y: 0, z: 400}
+ camera: {x: 0, y: 0, z: 400},
+ collisions: true
};
}