Jump to content

Volumetric raycast


Kyrah Abattoir
 Share

You are about to reply to a thread that has been inactive for 1472 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

This is something I've been wondering about since I saw Wulfie's most recent script contribution.

Is there a "cheap" way to perform a "volumetric raycast"

That is, figure out what objects are inside (or partially inside) a volume projected from the avatar's bounding box in an arbitrary direction and "depth".

EDIT: Added a visual aid.

blender_2020-06-09_15-00-23.png.4d5b1f530ba4ca17087bad63c7e9b710.png

Edited by Kyrah Abattoir
Link to comment
Share on other sites

For context: 

 

 

I don't know if my function can be made any more efficient, short of maybe replacing the LL functions with "manual math."

It works as long as the center of the target is inside the cone. For cases where an object is partially inside the cone, without the center being in the cone, there would always need to be at least one (or multiple) raycasts inside of the cone, such as finding the closest edge within the cone and firing a ray along it, in hopes that it can still hit the target.

But that would be unreliable as you could no longer assume that "if nothing is hit, there must've been line of sight." The ray would have to actually hit the target, which creates some caveats like moving targets and weirdly-shaped targets. (Imagine trying to hit the center an L-shaped target.)

You would also have to discard the arc and range checks, since the target's center could be just outside the range of the cone, but still extend into range. I think this would sacrifice performance in cases where the target is nowhere near the cone.

Edited by Wulfie Reanimator
Link to comment
Share on other sites

Oh, I could really use that. I think Havok has that function, as "cast beam".

Finding out if a space is empty takes too many ray casts. Here's what I do in my NPCs to check if an NPC-sized cylinder is empty.

    if (obstacleraycasthoriz(p0+halfheight+fwdoffset, pc + halfheight)) { return(-1.0); }// Horizontal cast at mid height, any hit is bad
    if (obstacleraycasthoriz(p0+fullheight+fwdoffset, pc + fullheight)) { return(-1.0); }// Same at full height to check for low clearances
    if (obstacleraycasthoriz(p0+halfheight+fwdoffset+sideoffset, pa + halfheight)) { return(-1.0); }// Horizontal cast at mid height, any hit is bad
    if (obstacleraycasthoriz(p0+halfheight+fwdoffset-sideoffset, pb + halfheight)) { return(-1.0); }// Horizontal cast at mid height, any hit is bad
    //  Crosswise horizontal check.
    if (obstacleraycasthoriz(pa+halfheight,pb+halfheight)) { return(-1.0); }   // Horizontal cast crosswize at mid height, any hit is bad
    //  Downward ray casts only.  Must hit a walkable.
    //  Center of cell is clear and walkable. Now check upwards at front and side.
    //  The idea is to check at points that are on a circle of diameter "gPathWidth"
    if (obstacleraycastvert(pa+fullheight,pa-mazedepthmargin) < 0) { return(-1.0); }   
    if (obstacleraycastvert(pb+fullheight,pb-mazedepthmargin) < 0) { return(-1.0); } // cast downwards, must hit walkable
    if (obstacleraycastvert(pc+fullheight,pc-mazedepthmargin) < 0) { return(-1.0); } // cast downwards, must hit walkable
    if (obstacleraycastvert(pd+fullheight,pc-mazedepthmargin) < 0) { return(-1.0); } // cast at steep angle, must hit walkable
    //  Need to do all four corners of the square. Used when testing and not coming from a known good place.
    if (obstacleraycastvert(pd+fullheight,pd-mazedepthmargin) < 0) { return(-1.0); }; // cast downwards for trailing point

10 calls to llCastRay for each square as the maze solver plans its way around an obstacle. The script doing this sometimes runs for two minutes on hard cases. There are horizontal ray casts to catch vertical obstacles, and vertical ray casts to catch horizontal obstacles. If a ray cast starts inside an obstacle, it doesn't see it, so all this is necessary. Even with all this, it can miss a thin pole.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1472 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...