Skip to content

Commit

Permalink
sphere collision
Browse files Browse the repository at this point in the history
  • Loading branch information
ZIWEI authored and ZIWEI committed Dec 2, 2015
1 parent aae9b76 commit b0f7024
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Binary file added Presentation/MileStone 2.pdf
Binary file not shown.
9 changes: 7 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
var scene, camera, light, camControl, renderer;
var vbo_pos, vbo_pos2;
var originGeometry, cube, mesh, material;
var roomMesh;
var roomMesh,sphereMesh;

var data, texture, points;

Expand Down Expand Up @@ -188,7 +188,12 @@
roomMesh = new THREE.Mesh(roomGeometry, roomMaterial);
roomMesh.doubleSided = true;
scene.add(roomMesh);

var sphereMaterial = new THREE.MeshFaceMaterial(roomMaterialArray);
var sphereGeom = new THREE.SphereGeometry(0.3, 100, 100);
sphereMesh = new THREE.Mesh(sphereGeom, sphereMaterial);
sphereMesh.position.x = 0.5;
sphereMesh.position.z = 0.3;
scene.add(sphereMesh);
//
if (!isWebGL2 && !renderer.context.getExtension('OES_texture_float')) {
alert('OES_texture_float is not :(');
Expand Down
21 changes: 15 additions & 6 deletions js/gpgpu/SimulationShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ function simulationCommon() {
//UBO:
//http://www.opentk.com/node/2926
return [
'layout(std140) uniform u_tryUBO{',
' vec4 uboTry1;',
' vec4 uboTry2;',
'};',
//'layout(std140) uniform u_tryUBO{',
//' vec4 uboTry1;',
//' vec4 uboTry2;',
//'};',
'uniform float u_timer;',
'uniform float u_clothWidth;',
'uniform float u_clothHeight;',
Expand All @@ -23,6 +23,14 @@ function simulationCommon() {
'uniform sampler2D u_texPos;',
'uniform sampler2D u_texPrevPos;',
'float DAMPING = -0.0125;',
'void sphereCollision(inout vec3 x, vec3 center, float r)',
'{',
'vec3 delta = x - center;',
'float dist = length(delta);',
'if (dist < r) {',
' x = center + delta*1.01*(r / dist);',
'}',
'} ',
'vec2 getNeighbor(int n, out float ks, out float kd)',
'{',
//structural springs (adjacent neighbors)
Expand Down Expand Up @@ -100,6 +108,7 @@ function simulationCommon() {

'if(pinBoolean); else pos.xyz += vel*timestep;',
'if(pos.y<-3.0) pos.y = -3.0;',//ground
'sphereCollision(pos.xyz,vec3(0.5,0.0,0.3),0.3);',
' return pos;',
'}',
].join('\n');
Expand Down Expand Up @@ -256,7 +265,7 @@ GPGPU2.SimulationShader2 = function (renderer,c_w,c_h) {
gl.uniform2f(uniforms.Bnd, cfg.getKsBend(), -cfg.getKdBend());

gl.uniform4f(uniforms.u_pins, cfg.getPin1(), cfg.getPin2(), cfg.getPin3(), cfg.getPin4());

/*
//UBO:
//https://www.packtpub.com/books/content/opengl-40-using-uniform-blocks-and-uniform-buffer-objects
//1. get index of uniform block
Expand All @@ -275,7 +284,7 @@ GPGPU2.SimulationShader2 = function (renderer,c_w,c_h) {
var try2 = [0.5, 0.6, 0.7, 0.8];
//5. Create the OpenGL buffer object and copy data into it
//6. bind the buffer object to the uniform block
/*
'layout (std140) uniform u_tryUBO{',
' vec4 uboTry1;',
' vec4 uboTry2;',
Expand Down

0 comments on commit b0f7024

Please sign in to comment.