It is currently Sat Aug 22, 2020 4:14 am


All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Raycast class for picking and visibility checks.
PostPosted: Tue Jan 11, 2011 10:24 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Raycast class for picking and visibility checks.
PostPosted: Sun Apr 17, 2011 3:43 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
For anyone intersted, I just added another raycasting class called RaycastWithCallback. This one simply calls a callback function for each voxel along the ray. Note that this version does not stop when it finds an intersection, instead it decides whether to continue based on the return value from the callback.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net