Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sensors to bodies #424

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added sensors to bodies
gregmax17 committed Jul 15, 2019
commit abb87891fb67ea33d678562d641519c973567f1b
30 changes: 24 additions & 6 deletions build/cannon.demo.js
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ CANNON.Demo = function(options){
shadows: false,
aabbs: false,
profiling: false,
maxSubSteps:3
maxSubSteps: 20
};

// Extend settings with options
@@ -262,10 +262,20 @@ CANNON.Demo = function(options){

// Read position data into visuals
for(var i=0; i<N; i++){
var b = bodies[i], visual = visuals[i];
visual.position.copy(b.position);
var b = bodies[i],
visual = visuals[i];

// Interpolated or not?
var bodyPos = b.interpolatedPosition;
var bodyQuat = b.interpolatedQuaternion;
if(settings.paused){
bodyPos = b.position;
bodyQuat = b.quaternion;
}

visual.position.copy(bodyPos);
if(b.quaternion){
visual.quaternion.copy(b.quaternion);
visual.quaternion.copy(bodyQuat);
}
}

@@ -626,8 +636,10 @@ CANNON.Demo = function(options){
} else {
smoothie.start();
}*/
resetCallTime = true;
});
wf.add(settings, 'stepFrequency',60,60*10).step(60);
wf.add(settings, 'stepFrequency',10,60*10).step(10);
wf.add(settings, 'maxSubSteps',1,50).step(1);
var maxg = 100;
wf.add(settings, 'gx',-maxg,maxg).onChange(function(gx){
if(!isNaN(gx)){
@@ -701,11 +713,12 @@ CANNON.Demo = function(options){
}

var lastCallTime = 0;
var resetCallTime = false;
function updatePhysics(){
// Step world
var timeStep = 1 / settings.stepFrequency;

var now = Date.now() / 1000;
var now = performance.now() / 1000;

if(!lastCallTime){
// last call time not saved, cant guess elapsed time. Take a simple step.
@@ -715,6 +728,10 @@ CANNON.Demo = function(options){
}

var timeSinceLastCall = now - lastCallTime;
if(resetCallTime){
timeSinceLastCall = 0;
resetCallTime = false;
}

world.step(timeStep, timeSinceLastCall, settings.maxSubSteps);

@@ -777,6 +794,7 @@ CANNON.Demo = function(options){

case 112: // p
settings.paused = !settings.paused;
resetCallTime = true;
updategui();
break;

1,848 changes: 1,351 additions & 497 deletions build/cannon.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions build/cannon.min.js

Large diffs are not rendered by default.

6,547 changes: 6,547 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/objects/Body.js
Original file line number Diff line number Diff line change
@@ -368,7 +368,17 @@ function Body(options){
* @property boundingRadius
* @type {Number}
*/
this.boundingRadius = 0;
this.boundingRadius = 0;

/**
* Determines if bodies do interact. "collide" event is still triggered.
* @property sensor
* @type {Boolean}
*/
this.sensor = false;
if (options.sensor) {
this.sensor = options.sensor;
}

this.wlambda = new Vec3();

4 changes: 3 additions & 1 deletion src/solver/Solver.js
Original file line number Diff line number Diff line change
@@ -32,7 +32,9 @@ Solver.prototype.solve = function(dt,world){
*/
Solver.prototype.addEquation = function(eq){
if (eq.enabled) {
this.equations.push(eq);
if (!(eq.bi.sensor || eq.bj.sensor)) {
this.equations.push(eq);
}
}
};