Commit 49887e53 authored by amandaghassaei's avatar amandaghassaei

variable ground height in sim

parent 42b9227b
......@@ -169,15 +169,15 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
var gravityVect = this.get("gravityVector").clone().normalize().multiplyScalar(this.get("gravity"));
var groundHeight = this.get("groundHeight");
var friction = this.get("friction");
emSimLattice.setConstants(dt, gravityVect);
emSimLattice.setConstants(dt, gravityVect, groundHeight);
three.startAnimationLoop(function(){
for (var i=0;i<renderRate-1;i++){
self.time += dt;
emSimLattice.iter(dt, self.time, gravityVect, false);
emSimLattice.iter(dt, self.time, gravityVect, groundHeight, false);
}
self.time += dt;
emSimLattice.iter(dt, self.time, gravityVect, true);
emSimLattice.iter(dt, self.time, gravityVect, groundHeight, true);
//if (self._getViewMode() == "translation"){
// self.calcTranslation();
//}
......
......@@ -452,15 +452,16 @@ define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'G
return !state;
},
setConstants: function(dt, gravity){
setConstants: function(dt, gravity, groundHeight){
gpuMath.setProgram("velocityCalc");
gpuMath.setUniformForProgram("velocityCalc", "u_dt", dt, "1f");
gpuMath.setUniformForProgram("velocityCalc", "u_gravity", [gravity.x, gravity.y, gravity.z], "3f");
gpuMath.setUniformForProgram("velocityCalc", "u_groundHeight", groundHeight, "1f");
gpuMath.setProgram("positionCalc");
gpuMath.setUniformForProgram("positionCalc", "u_dt", dt, "1f");
},
iter: function(dt, time, gravity, shouldRender){
iter: function(dt, time, gravity, groundHeight, shouldRender){
gpuMath.step("quaternionCalc", ["u_lastTranslation", "u_lastQuaternion", "u_fixed", "u_neighborsXMapping",
"u_neighborsYMapping", "u_compositeKs"], "u_quaternion", "u_wires", "u_wiresMeta", time);
......@@ -620,7 +621,7 @@ define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'G
}
//simple collision detection
var zPosition = this.originalPosition[rgbaIndex+2]+translation[2]*multiplier;
var zPosition = this.originalPosition[rgbaIndex+2]+translation[2]*multiplier-groundHeight;
var collisionK = 1;
if (zPosition<0) force[2] += -zPosition*collisionK-velocity[2]*collisionK/10;
......
......@@ -9,6 +9,7 @@ uniform float u_multiplier;
uniform vec3 u_latticePitch;
uniform float u_wiresMetaLength;
uniform float u_time;
uniform float u_groundHeight;
uniform sampler2D u_lastVelocity;
......@@ -122,9 +123,9 @@ void main(){
vec3 force = u_gravity*mass;
//simple collision
float zPosition = texture2D(u_originalPosition, scaledFragCoord).z + lastTranslation.z*u_multiplier;
float zPosition = texture2D(u_originalPosition, scaledFragCoord).z + lastTranslation.z*u_multiplier - u_groundHeight;
float collisionK = 1.0;
if (zPosition < 0.0) force.z = force.z -zPosition*collisionK-lastVelocity.z*collisionK/10.0;
if (zPosition < 0.0) force.z += -zPosition*collisionK-lastVelocity.z*collisionK/10.0;
for (float i=0.0;i<2.0;i+=1.0){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment