Hi all,
Just wanted to mention a new addition to PolyVox, in order to keep you all up to date with what's going on. Over the weekend I added a new Raycast class, which can be used to fire a ray through a volume and determine what (if anything) it hits.
There's two main uses for this class. Firstly it's great for picking - I've been using it in Thermite and it's pixel-perfect when used with the the CubicSurfaceExtractor. Secondly it can be used for visibility determination between two points. This can be useful for AI, and I'm also putting it to use for CPU lighting calculations (but not sure how well that will work out yet).
I've not accuratly measured the performance, but it seems to cope with hundreds of thousands of rays being cast per second so I don't think there'll be any problems there.
I haven't tested it with the marching cubes surface extractor, but it won't work quite as well because it just finds the nearest voxel, rather than an exact point on the surface. But it will still be a useful starting point if anyone wants to investigate further.
There's no documentation yet because I'm still refining the class, but here is a snippet of code copied from Thermite (note that the interface might still change):
Code:
Vector3DFloat start(rayOrigin.x(), rayOrigin.y(), rayOrigin.z());
Vector3DFloat direction(rayDir.x(), rayDir.y(), rayDir.z());
direction.normalise();
direction *= 1000.0f; //Casts ray of length 1000
RaycastResult raycastResult;
Raycast<Material8> raycast(m_pPolyVoxVolume, start, direction, raycastResult);
raycast.execute();
if(raycastResult.foundIntersection)
{
//...
}
Hope someone finds it useful!