Collision Detection Release 0.6
Patrick Lam | 20 February, 2009 | 17:31
And so, we’re reached 0.6 release.
Visually, there’s not much to show what has been done for this release. But behind the scene, a lot has happened.
So starting off with the smaller changes/updates, two new functions were added to the Model class.
If you’re thinking that getBoundingVolume() returns an object containing a more complex object (perhaps a collada), you’re half right. What this function actually do is that, again, it takes in a number (timeStep) as a parameter. And then it gets it’s next position, so we now have both the current and next position, after, we create an object (skew sphere) and contain both the current and next position object. This basically creates a bounding sphere which encloses the path of the object from current position to next position.
The next change for this release is including “stepping”. Basically put, we take the phase of each update (timeSpan) and we break it down into smaller steps. So for example, if the timeSpan for the update is 30 seconds, instead of checking for collisions in the beginning and end of the 30 seconds, we’d check for collisions every 5 seconds (0, 5, 10, 15, 20, 25, 30 second mark). For now, I am only breaking down into 2 smaller steps, as there are some processing issues when I start increasing the step size. Until I can lower the runtime and increase code efficiency of the actual collision detection test, I will be leaving it at that.
The last change, and I would say it’s the biggest change for this release, is that I’ve extracted the code for collision detection, which I originally coded as a built-in functionality for the Scene class, and created it as a new class. With this move, it enables users to add in collision detection to their scene whenever they want to. At the same time, this allows me to pass back a list of objects which have collisions. Right now, the returning type is a simple array holding the indexes to the objects that have collision. In the future, I might be changing this return type to something else (ie. indexes of the objects that have collisions and the objects they are colliding with).
Here is an example on how to include the collision detection and get the test results back:
There’s no new demo created for this release, but if you want to look at the other ones, you can go here.
Visually, there’s not much to show what has been done for this release. But behind the scene, a lot has happened.
So starting off with the smaller changes/updates, two new functions were added to the Model class.
- getNextPosition(timeStep)
- getBoundingVolume(timeStep)
If you’re thinking that getBoundingVolume() returns an object containing a more complex object (perhaps a collada), you’re half right. What this function actually do is that, again, it takes in a number (timeStep) as a parameter. And then it gets it’s next position, so we now have both the current and next position, after, we create an object (skew sphere) and contain both the current and next position object. This basically creates a bounding sphere which encloses the path of the object from current position to next position.
The next change for this release is including “stepping”. Basically put, we take the phase of each update (timeSpan) and we break it down into smaller steps. So for example, if the timeSpan for the update is 30 seconds, instead of checking for collisions in the beginning and end of the 30 seconds, we’d check for collisions every 5 seconds (0, 5, 10, 15, 20, 25, 30 second mark). For now, I am only breaking down into 2 smaller steps, as there are some processing issues when I start increasing the step size. Until I can lower the runtime and increase code efficiency of the actual collision detection test, I will be leaving it at that.
The last change, and I would say it’s the biggest change for this release, is that I’ve extracted the code for collision detection, which I originally coded as a built-in functionality for the Scene class, and created it as a new class. With this move, it enables users to add in collision detection to their scene whenever they want to. At the same time, this allows me to pass back a list of objects which have collisions. Right now, the returning type is a simple array holding the indexes to the objects that have collision. In the future, I might be changing this return type to something else (ie. indexes of the objects that have collisions and the objects they are colliding with).
Here is an example on how to include the collision detection and get the test results back:
- Create a Scene and initialize it
scn = new Scene() - Set any necessary properties (ie. canvas tag, renderer, camera, etc)
- Create a function to be called for update callback from the scene and set it
scn.setUpdateCallback(CD);
…
…
function CD(timeElapsed) { //Code } - Create a Collision Detection and initialize it with the scene
cd = new CollisionDetection(scn); - Now, you can access it’s test results for each of it’s updates by doing so
var collisionResults = cd.result(timeElapsed, Date.now());
And for now, the result that comes back is an array. So the result is either null, or not.
function CD(timeElapsed) {
cd = new CollisionDetection(scn);
var collisionResults = cd.result(timeElapsed, Date.now());
if(collisionResults == null) {
alert("Now Collisions");
}
else {
alert("Objects with collisions: " + collisionResults);
}
}
And then you just have to remember to set this as your updateCallback for your scene.There’s no new demo created for this release, but if you want to look at the other ones, you can go here.
