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

Fix: avoid error while emitting 'EndShapeContact' events. #408

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 1 addition & 7 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ Just include [cannon.js](https://github.com/schteppe/cannon.js/releases/download
Install the cannon package via NPM:

```bash
npm install --save cannon
```

Alternatively, point to the Github repo directly to get the very latest version:

```bash
npm install --save schteppe/cannon.js
npm install --save cannon-dtysky
```

### Example
Expand Down
30 changes: 24 additions & 6 deletions build/cannon.demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CANNON.Demo = function(options){
shadows: false,
aabbs: false,
profiling: false,
maxSubSteps:3
maxSubSteps: 20
};

// Extend settings with options
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)){
Expand Down Expand Up @@ -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.
Expand All @@ -715,6 +728,10 @@ CANNON.Demo = function(options){
}

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

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

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

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

Expand Down
Loading