Using Bresenham's line algorithm, I calculate all of the points along the ray and then test the objects within the model against those points. If an object is determined to be colliding with the point, another test is performed. The test is supplied to the ray casting method, but can also be excluded. Excluding the test function will return a CollisionData structure for the first object that the ray collides with. If the test is provided, only the first object which satisfies the test will be returned. Otherwise the method returns null.
Querying the collision model is a way to look at all of the objects in the model and determine if they satisfy a certain condition. Objects which satisfy the condition will be returned in an array. This general method is used by the more specific method "queryNear" which will look for objects within a specified distance of a point. Neither of these querying methods is particularly fast because it requires testing the entire set of objects in the model.
Further improvement can be made to ray casting when looking at the method from the perspective of the SpatialGrid. In the future I hope to implement some of these improvements because it will result in extremely fast testing using ray casting. Overall the current ray casting method isn't slow when there aren't a lot of objects to test against as only nodes which fall along the ray have their objects tested.
No comments:
Post a Comment