Custom collision shape class

Post Reply
zbuffer
Posts: 8
Joined: Sat Jan 05, 2013 11:13 am

Custom collision shape class

Post by zbuffer »

Hello!

I want to write my own collision shape class to handle a torus shape (without the hole, like a cylinder with rounded edges). I have also thought about extending it to an arbitrary polynomial profile instead of a circular one. I need it to model a (bike) tyre geometry. It has to be as accurate as possible (analytic calculation) and that is why I don't want to use a triangle mesh.

Can someone explain me how collision shapes work?
I suppose I have to implement my version of supporting vertex calculation by I don't know what it does exactly.
Maybe there is some explanation you can point me to, best with some drawings?

Best!
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Custom collision shape class

Post by Basroil »

If you want a half circle torus (flat inside) it might be a bit easier to just use two cylinders and some collision masking if you need performance, or convex decomposition if you don't want to deal with triangles. Just understand that bullet wasn't meant for FEM replacement, and simple representations generally give you good enough results that don't improve drastically as long as your representation describes the things you are seeking.
zbuffer
Posts: 8
Joined: Sat Jan 05, 2013 11:13 am

Re: Custom collision shape class

Post by zbuffer »

I don't want to model a deforming tyre but a rigid one.
It is important to me to get precise collision with the half circle profile.
If you want to model a sphere you don't exchange it for a box ;) Especially that it would be more expensive ;P
If there is a possibility to get exact collision with primitives such as a cylinder or sphere there should also be no problem with a half circle torus.
I just need some help to understand how primitives collision work in bullet. Otherwise I will just have to do it in a blind way, reverse engineering bullet...

EDIT:
Ok. I just did it. It turned out to be quite easy. I had to reverse engineer cylinder shape to understand what is exactly the meaning of the supporting vertex and the vector given.

To let everyone know:
The methods getLocalSupportingVertex and getLocalSupportingVertexWithoutMargin just calculate the contact point based on the direction vector passed to the method. The result has to be a contact point in the local frame so you can just treat the direction vector as pointing from the local center to the surface of the collision shape.
In fact the supporting vertex is a point where a plane would touch your collision shape.
All other methods are straightforward and can be mostly copied from other shapes.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Custom collision shape class

Post by Flix »

Now I commonly use a cylinder shape with a bigger collision margin to get a wheel shape for all my rigid-body-based wheeled vehicles.

No need to create a custom shape for it (the Bullet library is very good at making various shapes by default). I suggest you watch the video RBD posted some time ago if you'd like further hints (http://www.bulletphysics.org/Bullet/php ... =17&t=8995).
zbuffer
Posts: 8
Joined: Sat Jan 05, 2013 11:13 am

Re: Custom collision shape class

Post by zbuffer »

First, I already did it :D It was no rocket science and the calculations are not much more complicated than for a cylinder.

Second, I really need a precise contact with the round profile. I am simulating a monowheel vehicle which has to balance itself when stopped and the tyre lateral rotation and the resulting contact with the round profile is essential.

I have noticed some strange behaviour when I increase the iteration counts.
If it is above about 200 i/s then the body is getting some strange acceleration when close to laying flat on the ground. I suppose it has something to do with the moment where the contact point moves from the round profile to the flat side. Fortunately it is not important to me because I am simulating a vehicle which is always close to vertical.
Anyway, do you have any idea what could be the problem exactly?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Custom collision shape class

Post by Flix »

zbuffer wrote:Anyway, do you have any idea what could be the problem exactly?
Nope, the vehicles I've made so far are not self-balancing at all (I use poor realistic physic, at 60 Hz, trying to minimize the number of iterations of the constraints: I usually keep them vertical through some fake constraint).

My settings are only good for toy-like vehicles, not for real simulations :| .
rraallvv
Posts: 30
Joined: Thu Feb 09, 2012 2:39 am

Re: Custom collision shape class

Post by rraallvv »

@zbuffer Wow! that is what I need, a torus primitive shape... Would you mind sharing the code?
Post Reply