RayCast with less details/probably noob question

Hi i wanted to ask if there is any way to cast a ray without cheking all triangles and stuff.
What i need is to check if my Ray (line ) hits geom,to any point ,lets even say if it passes close to it,
but not just get closest geom (or node) to starting point.I need it to be the closest to ray that has a direction.
Soo lets say i have a sphere with a radius and want to check if a stick hits it without cheking where ,i know its
at (20,20,20) i know its 5 large soo i start a ray at (20,0,20) and send it up ,soo when ray goes to (20.16.20) it should say hey the sphere in next to me.

And yes i could just increment starting location Vector3f by direction and check local translation of sphere each time
± 5 to X,Y,Z … but i wanted to know if there was a better way, or and if some 1 has allready did a clean nice method for that ? (i have some probs on directions rotations and stuff)
Thnx for any help :slight_smile:

Without knowing more about what you are actually trying to accomplish, this is the best I can do:


What i try to do is lets say check if my ray hits lets say a Ball a huge big ball with alot of dettails,in a world with alot of balls with a lot of dettails without cheking each dettail of each ball ,but just by cheking all the balls and their area lets say

Oh soo from what i read on link it actually does not check all dots in all meshes ,but firstly check its area(bounding volume) , and only if hits goes for dettails? ok that must be fine then ,its just i opend collideWith and found this .
soo i’m a bit confused on if it does it or not

public int collideWith(Collidable other, CollisionResults results){
int total = 0;
// optimization: try collideWith BoundingVolume to avoid possibly redundant tests on children
// number 4 in condition is somewhat arbitrary. When there is only one child, the boundingVolume test is redundant at all.
// The idea is when there are few children, it can be too expensive to test boundingVolume first.
I’m removing this change until some issues can be addressed and I really
think it needs to be implemented a better way anyway.
First, it causes issues for anyone doing collideWith() with BoundingVolumes
and expecting it to trickle down to the children. For example, children
with BoundingSphere bounding volumes and collideWith(BoundingSphere). Doing
a collision check at the parent level then has to do a BoundingSphere to BoundingBox
collision which isn’t resolved. (Having to come up with a collision point in that
case is tricky and the first sign that this is the wrong approach.)
Second, the rippling changes this caused to ‘optimize’ collideWith() for this
special use-case are another sign that this approach was a bit dodgy. The whole
idea of calculating a full collision just to see if the two shapes collide at all
is very wasteful.
A proper implementation should support a simpler boolean check that doesn’t do
all of that calculation. For example, if ‘other’ is also a BoundingVolume (ie: 99.9%
of all non-Ray cases) then a direct BV to BV intersects() test can be done. So much
faster. And if ‘other’ is a Ray then the BV.intersects(Ray) call can be done.
I don’t have time to do it right now but I’ll at least un-break a bunch of peoples’
code until it can be ‘optimized’ properly. Hopefully it’s not too late to back out
the other dodgy ripples this caused. -pspeed (hindsight-expert ;))
Note: the code itself is relatively simple to implement but I don’t have time to
a) test it, and b) see if ‘> 4’ is still a decent check for it. Could be it’s fast
enough to do all the time for > 1.
if (children.size() > 4)
BoundingVolume bv = this.getWorldBound();
if (bv==null) return 0;

      // collideWith without CollisionResults parameter used to avoid allocation when possible
      if (bv.collideWith(other) == 0) return 0;
    for (Spatial child : children.getArray()){
        total += child.collideWith(other, results);
    return total;

Would calling the .intersect() method on a ball’s’ bounding volumes work for what you’re trying to do?

Something like this would return true if the ball’s bounding volume intersects the ray.

1 Like

seems pretty similar to what i’m looking for thnx :slight_smile: will try it tomorrow :slight_smile: 2 am here :smiley: