rayTest bug (ray vs box)

User avatar
Dragonlord
Posts: 198
Joined: Mon Sep 04, 2006 5:31 pm
Location: Switzerland

rayTest bug (ray vs box)

Post by Dragonlord »

As mentioned in the demo section I did a particle system using ray testing from bullet ( using btCollisionWorld::ClosestRayResultCallback ). In a different test case I noticed though a massive problem. Ray testing is massively bugged and misses collisions in over 50% of cases.

The test setup is a simple floor represented by a box shape. The particles are emitted a bit over the floor and drop down accelerated by gravity. As this log shows well ray testing fails to see a collision as it should:

Code: Select all

II [Bullet] step particle 0: elapsedTime=0.004637 displacement=(0.00019719, -0.020583, 0.00463185)
II [Bullet] rayTest: position=(0.019133, 0.00600426, 0.44942) to(0.0193302, -0.0145788, 0.454052)
II [Bullet] no hit: pos=(0.0193302, -0.0145788, 0.454052)
"position" is the position of the particle and is used as "rayFromWorld" parameter. "to" is the "position" plus the displacement of the particle and is used as "rayToWorld". The top side border of the box is exactly at y=0. The ray test therefore travels from outside the box (y ~ 0.006) to inside the box (y ~ -0.014) but does not detect a collision. Here the geometry informations for the test situation:

Code: Select all

box shape:
- position ( 15, -0.2, -5 )
- half extends ( 26, 0.2, 26 ) // hence half the size

particle starts at:
- position ( 0, 1, 0 ) 
- gravity ( 0, -9.81, 0 )
As mentioned out of 10 particles dropped down the ray cast sees like 50% or less of the collisions causing particles to fall straight through the box.

As a counter example here the situation when the ray cast does find a collision. Same situation with the same starting position of the particle:

Code: Select all

II [Bullet] step particle 0: elapsedTime=0.005344 displacement=(-0.000382682, -0.0235808, 0.00532798)
II [Bullet] rayTest: position=(-0.0320416, 0.0178012, 0.446106) to(-0.0324243, -0.00577959, 0.451434)
II [Bullet] has hit: normal=(0.000238988, 1, -0.000162395) hitPoint=(-0.0320885, 0.014913, 0.446759) hitFraction=0.451434
What is strange is that the collision is detected at a point slightly above the box (y ~0.015 ). Maybe the ray test implementation is broken for box shapes? Right now this is a problem since I can not be sure a ray test scores correctly collisions.

EDIT:
Also for the first particle missing the box here the test around the location the second particle did score a collision for comparison:

Code: Select all

II [Bullet] step particle 0: elapsedTime=0.004646 displacement=(0.000197573, -0.0204116, 0.00464084)
II [Bullet] rayTest: position=(0.0189355, 0.0264159, 0.444779) to(0.019133, 0.00600426, 0.44942)
II [Bullet] no hit: pos=(0.019133, 0.00600426, 0.44942)
Here the ray test is roughly from y~0.26 to y~0.006 which crosses the hit position of y~0.015 from the case it did work but fails to see the collision.
fido
Posts: 14
Joined: Sun Mar 22, 2009 5:57 pm

Re: rayTest bug (ray vs box)

Post by fido »

personally, I found the same problem. Especially with large box it is terribly imprecious. Because
whole waycast test is in fact sphere-sweep test with zero radius, I found it very inefficient too,
so I rather implemented API for real ray-test and did implementation for some primitive shapes.
I have heavily modified bullet library, so I cannot offer any simple out-of-box solution.
User avatar
Dragonlord
Posts: 198
Joined: Mon Sep 04, 2006 5:31 pm
Location: Switzerland

Re: rayTest bug (ray vs box)

Post by Dragonlord »

I want to use the bullet ray test since it is faster on large cast count than my own implementation. But if I could replace the actual collision test with my own collision test it would work perfectly. I just want to take advantage of the faster broad phase testing bullet can do. Any idea how I could replace the collision test for ray-box without changing bullet? I know there are collision algorithms for shape-shape case but are there also ones for ray-shape?

EDIT: Took a quick look. Using a clever overloading of btCollisionWorld::rayTest one should be able to replace the actual ray-test with a custom version without touching any bullet source code and therefore keeping all the advantages of the ray-cast optimizations. I'll see if I get this working.