Hello!
I'm using Bullet as a collision detection library only (for now) on my software. I'm using just box shapes, and I'm doing sweep queries so I can
translate some object against another, and make them collider right next each other. Everything works great when no rotation is applied, but when it
is, one box goes through another.
The image below describes what's happening:
The highlighted box is the one being translated. No matter which side I try to collide with the rotated box, it always enters that same amount.
I tried messing with the margins, but it seems to result in bigger errors and penetrations.
Any thoughs on what is happening?
Collision only with boxes problem
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Collision only with boxes problem
What margins were you trying to change? I do not know exactly aymore how it is done, but what you are experiencing has to do with the penetration depth before a collision is detected. If you care about such small penetrations, you should reduce the penetration depth.
Here is the discussion in a 10 years old thread, but this should still hold at least for what you want to do:
http://www.bulletphysics.org/Bullet/php ... =&f=&t=638
Here is the discussion in a 10 years old thread, but this should still hold at least for what you want to do:
http://www.bulletphysics.org/Bullet/php ... =&f=&t=638
-
- Posts: 122
- Joined: Thu May 05, 2011 11:47 am
Re: Collision only with boxes problem
Yep you need to see what collision margin is set currently. Try to give it a smaller value. Also note not to lower it to a very small value as that might cause problems. You could also deal with this with you rendering part by only rendering the cube part taking the collision margin into consideration.
-
- Posts: 6
- Joined: Mon May 23, 2016 6:53 pm
Re: Collision only with boxes problem
I tried changing the collision margin of the shape, but with no success. Where do I change the penetration depth?What margins were you trying to change? I do not know exactly aymore how it is done, but what you are experiencing has to do with the penetration depth before a collision is detected. If you care about such small penetrations, you should reduce the penetration depth.
Tried changing the collision margin of the shape to 0.004 for example (my metric is in meters), and the penetration on the rotated cube reduced (it seems to be exactly that same amount of 0.004).Yep you need to see what collision margin is set currently. Try to give it a smaller value. Also note not to lower it to a very small value as that might cause problems.
But it introduced some bugs with the collision on the normal box when using the convexSweepTest function:
Changing the drawing would not solve the problem, because then would occur drawing collision with the non-rotated box, which is colliding correctly now.You could also deal with this with you rendering part by only rendering the cube part taking the collision margin into consideration.
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Collision only with boxes problem
Sorry, I meant the collision margin in fact. You can only ask Bullet for the penetration depth of two objects by looking at the colliding objects. But this does not help you much, just tells you the depth in a number. Is it totally relevant to your project that the collision is very precise? I do not have any other idea to share. Also I am not sure what is happening after you changed your margin 0.004 m. Maybe this is one of the problems occuring when using a too small margin. Try a larger one such as 0.04m or 0.01m and see if you problems go away.
Mobeen, could increase the physics step improve the accuracy of the collision? I am not sure.
Mobeen, could increase the physics step improve the accuracy of the collision? I am not sure.
-
- Posts: 6
- Joined: Mon May 23, 2016 6:53 pm
Re: Collision only with boxes problem
Tried 0.01m, and the penetration on the non-rotated box disappeared, but the penetration with the rotated box still seems to be the same amount as the margin.Try a larger one such as 0.04m or 0.01m and see if you problems go away.
I'm afraid I'm going to need more precision than that, at least the correct millimeter (0.001m).
Don't know if this is related, but I'm not doing any physics step. I just have a btCollisionWorld with broadphase and btCollisionObjects with btBoxShapes.Mobeen, could increase the physics step improve the accuracy of the collision? I am not sure.
The movements of the objects are made with the mouse, and for each delta movement, I call the convexSweepTest function to get how far of that delta I can translate.
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Collision only with boxes problem
Oh ok, that is a different thing from doing the physics steps. Can you edit an example of the bullet example browser to reproduce your behavior? I am afraid that your needed accuracy of simulation is not possible with Bullet physics, but I am not entirely sure. However, I am still not sure why you need such a high accuracy of simulation. Do you want to share with us why you need it?
-
- Posts: 6
- Joined: Mon May 23, 2016 6:53 pm
Re: Collision only with boxes problem
Here is the Basic Example changed showing what's happening (it's the full examples folder because I had to change some other classes in order to work with btCollisionWorld):
https://dl.dropboxusercontent.com/u/474 ... roblem.zip
I just created two boxes, the second rotated. Then I simulate a movement of the first object checking whether it results in a collision, and then I move the box appropriately.
I'm working in a architecture software, that's why I need such precision. For now, only OBB collision is needed, but I intend to, later, maybe include triangle collision and even physics.
Bullet is the only library I have found that can calculate sweep collisions with position AND rotation velocities, and that also does broadphase test for that collisions.
EDIT:
Here's a screenshot of the issue in the bullet example:
https://dl.dropboxusercontent.com/u/474 ... roblem.zip
I just created two boxes, the second rotated. Then I simulate a movement of the first object checking whether it results in a collision, and then I move the box appropriately.
I'm working in a architecture software, that's why I need such precision. For now, only OBB collision is needed, but I intend to, later, maybe include triangle collision and even physics.
Bullet is the only library I have found that can calculate sweep collisions with position AND rotation velocities, and that also does broadphase test for that collisions.
EDIT:
Here's a screenshot of the issue in the bullet example:
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Collision only with boxes problem
Sorry for not writing back, but I am not sure if this can be fixed in a correct way. I think that is how much you have to deal with when simulating (simulation mismatch). Could you probably render the box dimensions smaller by the amount of the collision margin or does this make the other collision look wrong?
-
- Posts: 6
- Joined: Mon May 23, 2016 6:53 pm
Re: Collision only with boxes problem
I'm afraid I can't, because as you said, it would mess with the collisions that occurs correctly.
So, I think I need to write my own algorithm for the sweep collision, or find a library that does that in a more precise way than bullet.
Do you happen to know any?
And thanks for the help!
So, I think I need to write my own algorithm for the sweep collision, or find a library that does that in a more precise way than bullet.
Do you happen to know any?
And thanks for the help!
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Collision only with boxes problem
I just had another idea. You could keep the collision margin at 0.01 and scale up your world by a factor of 10, giving you and effective margin of 0.001m. Could you check if this helps? Sorry, I currently do not have a computer to test it with your example.
It came to my mind while I watched the video posted here on collision margins.
http://bulletphysics.org/Bullet/phpBB3/ ... php?t=8995
It came to my mind while I watched the video posted here on collision margins.
http://bulletphysics.org/Bullet/phpBB3/ ... php?t=8995
-
- Posts: 6
- Joined: Mon May 23, 2016 6:53 pm
Re: Collision only with boxes problem
I tried it in a bigger scale, and it seems to work better, although there's still a little margin (now outside, not penetrating). I couldn't measure exactly the precision of that margin yet.
I'm trying to work with the sweep test from the PhysX library, and it seems to be very precise, but it does not have rotation sweep like bullet.
So I'm still thinking on what to do (maybe do a brute force search millimeter by millimeter on the rotation and leave the translation sweep with PhysX).
I'll post here if I have any success.
Thank you for your help!
I'm trying to work with the sweep test from the PhysX library, and it seems to be very precise, but it does not have rotation sweep like bullet.
So I'm still thinking on what to do (maybe do a brute force search millimeter by millimeter on the rotation and leave the translation sweep with PhysX).
I'll post here if I have any success.
Thank you for your help!