Scaling: example needed

gabba
Posts: 9
Joined: Thu Mar 19, 2009 3:20 am

Scaling: example needed

Post by gabba »

I've read Scaling the world on the wiki, but could someone provide a concrete example (i.e. code) of the specific changes to make?

In the pinball game I'm making,

- everything is already modelled with centimeters as the unit, for instance the ball has a 1 cm radius. Therefore I don't need to scale my objects or the distances, as far as I understand.

- I tried changing the gravity to (0, -980, 0) so it's in cm/s^2 instead of m/s^2. However this causes objects to behave erratically, falling through the floor or bubbling up and down. This is no matter what I do with the CCD options, and switching to a different timestep than 60 Hz doesn't help, either.

- What else would I need to change to scale the whole system? I'm not applying any impulses or torque, and inertia is auto-calculated; I don't see how I could scale velocities since I don't do anything with those directly; and lastly there is the linear sleep treshold about which I'm not sure: what is it, and how does one modify it?

In an old thread, someone had success scaling everything to centimeters and showed the results with videos (which are now offline). He also posted some very incomplete code snippets. This seems to mean this scaling is possible, but I'm stumped as to how to achieve it.
If someone is able to summarize all this with code examples, I'd be very grateful.

Additional question: I understand Bullet 2.74 added support for smaller objects, with dynamic contact breaking treshold; has anyone tried dealing with spheres of 0.01 units or smaller, and what was the result?
I don't want to rescale everything (model by model...) to be in meters inside my modelling program; however if it's the only solution I could convert to meters before feeding values to Bullet, and convert back to centimeters when sending positions to the rendering engine.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Scaling: example needed

Post by Erwin Coumans »

if it's the only solution I could convert to meters before feeding values to Bullet, and convert back to centimeters when sending positions to the rendering engine.
Yes, this is the recommended solution. Use the latest version of Bullet, and feed Bullet transforms that are in meter units, in your case 0.02 spheres. Most collision shapes have way to scale (such as setScale, or btScaledBvhTriangleMeshShape). When dealing with such small objects, it is best to feed a smaller fixed simulation substep, such as 1./240.:

Code: Select all

dynamicsWorld->stepSimulation(deltaTime,10,1./240.);
With 'deltaTime' the actual deltatime in seconds. Just let Bullet do the interpolation.

We should provide some example indeed.
Hope this helps,
Erwin
gabba
Posts: 9
Joined: Thu Mar 19, 2009 3:20 am

Re: Scaling: example needed

Post by gabba »

Thanks. I guess I'll go with that approach then.

I am still curious about the other approach, though (using cm as the unit for Bullet). Apparently the guy that tried it got the exact same behavior as with using meters; I'd like to compare both approaches, which should be easy if I just have #defined multipliers at strategic places in my code. Changing the unit might also come in handy in case I decide I'm doing spaceships for my next game, or what not.

So, besides multiplying gravity by 100, anyone knows which changes are missing from my basic setup to use cm as the Bullet unit?

If this pinball game turns out well I might post it on this board, hopefully under an open-source license, if other contributors agree.