How To Apply Gravity To An Actor On A Spherical Plane

User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

How To Apply Gravity To An Actor On A Spherical Plane

Post by KKlouzal »

Hello! This is my first post on the bullet forums and I've been doing a lot of research lately, specifically research on how to apply gravity to an actor on a sphere.
I've done numerous Google searches on the topic and have found not a single topic that covers this.
I was hoping someone could shed some light on a few things for me.

Is it possible to have a bullet dynamic world in the shape of a sphere, if so is it possible to apply gravity to actors in such a way that they can traverse the sphere?

If these things are possible could I be pointed in the proper direction to get started.

Thank you all for your time, I really appreciate it.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by Basroil »

KKlouzal wrote:Is it possible to have a bullet dynamic world in the shape of a sphere,
Short answer is probably not with the way bullet is set up using Euclidean spaces with (mostly) Cartesian coordinates. Longer answer is: What you are looking for is NOT a dynamic world with spherical shape, rather a dynamic object (or kinematic) with a spherical shape which acts as the point of gravity for some other object.
KKlouzal wrote: if so is it possible to apply gravity to actors in such a way that they can traverse the sphere?
Assuming you are still talking about a world with a sphere inside that uses gravity, you can simulate gravity as a force in the vector from the object to the sphere. Just remember to set external gravity to zero (unless you know you want it non-zero).
User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by KKlouzal »

Thank you for the quick response!

I figured I would need to have the entire world zero gravity and apply forces to simulate gravity. How do you suggest this will effect performance? Constantly applying a force to simulate gravity on objects would mean they would never go into their sleep state wasting valuable CPU?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by xexuxjy »

From a quick glance through I don't believe it would make any difference. The world gravity value is assigned to newly added objects, theres nothing stopping you applying a new gravity value to each rigid body on each step (ok thats a minor change) . It will then be updated as a normal force through applyGravity if the object is active.
User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by KKlouzal »

Thank you for your response. From what I'm understanding, during stepping, presumably before physics calculation begins, I can calculate the gravity value for each actor individually and instead of applying forces I can actually define each actor's gravity value?

For example if I have a sphere rolling around the outside of another larger sphere I can calculate the gravity which would keep the smaller sphere touching the shell of the larger sphere for that simulation step and set the smaller spheres gravity value then let the simulation step with this information?

This sounds like the best solution however say there were 10,000 actors, 90-95% of them were always in their sleep states, it does not make sense to calculate and reapply the gravity for these actors?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by xexuxjy »

Yes, setting gravity at the world level is just a convenient way of passing it on to each of the collision objects, you can change this on a per object basis. I guess you could check the activity state of each object before doing it's gravity calculation - would be a bit annoying though.
User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by KKlouzal »

For the potential amount of physics objects I have this sounds really demanding. I may try and figure out a way to do it in a separate thread unless that sounds too disastrous.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by Basroil »

KKlouzal wrote:Constantly applying a force to simulate gravity on objects would mean they would never go into their sleep state wasting valuable CPU?
Yes, but plenty of ways around that. For one, you can spawn in objects only when needed (you don't need to add objects a million miles away right now if you're moving at non-relativistic speeds). You can also just change the gravity direction for each object, which should be bypassed if the object is sleeping.
KKlouzal wrote: For example if I have a sphere rolling around the outside of another larger sphere I can calculate the gravity which would keep the smaller sphere touching the shell of the larger sphere for that simulation step and set the smaller spheres gravity value then let the simulation step with this information?
Why bother feeding that back into your physics engine if you already calculated it?
KKlouzal wrote:This sounds like the best solution however say there were 10,000 actors, 90-95% of them were always in their sleep states, it does not make sense to calculate and reapply the gravity for these actors?
Bullet already has sleeping code built in, once deactivated only external forces (or manual activation) will activate it, so if you reset the gravity vector each active state it shouldn't actually do anything to stationary objects.

If your engine relies on non-uniform gravity often, you should change your btRigidBody::applyGravity() code and add your calculation code before the applyCentralForce(m_gravity) line. For what you want, it would be far easier to edit the source code for btRigidBody than to slap massive chunks of code on top.
User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by KKlouzal »

Thank you very much basroli for the insight. My goal here is to figure out the best way to have one very large sphere orbit a central point with a smaller sphere rotating around the bigger sphere all the while both of the spheres rotating on their axis(like planets in orbit around their sun). Players can leave the large sphere and travel through a zero gravity environment to the smaller sphere then walk around on that as well.

The players can build a contraption out of different sized rigid bodies then weld them together to traverse from the large sphere to the smaller sphere. Players don't have to leave the large sphere if they don't want to but will still have the option to build other contraptions which is why there could be thousands of rigid bodies at any point in time but most of them stationary.

I think I've almost gotten my head wrapped around everything I need to do here thanks to everyone's help!

The last thing I'm confused on at the moment is about the part where you said:
Basroil wrote:Bullet already has sleeping code built in, once deactivated only external forces (or manual activation) will activate it, so if you reset the gravity vector each active state it shouldn't actually do anything to stationary objects.
If say a player creates a rigid body on either of the spheres, both of these spheres are orbiting around some point in space and they themselves are rotating on their axis, how would you suggest still allowing the objects to sleep in this case due to the fact that they are basically always in a state of motion. I have read it is not wise to manually set the position and rotation of an object.

I suppose if it were absolutely necessary I could disable the orbiting and have the spheres stationary but only if it were absolutely necessary.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by Flix »

No time for reading all the posts, so please forgive me it the anwer is not appropriate :oops:

Anyway:
KKlouzal wrote:Is it possible to have a bullet dynamic world in the shape of a sphere, if so is it possible to apply gravity to actors in such a way that they can traverse the sphere?
Well, if that means a spherical world, I posted a small demo about it recently http://www.bulletphysics.org/Bullet/php ... emo#p32672. Not sure if this is enough for your needs, but you can try it.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How To Apply Gravity To An Actor On A Spherical Plane

Post by Basroil »

KKlouzal wrote:My goal here is to figure out the best way to have one very large sphere orbit a central point with a smaller sphere rotating around the bigger sphere all the while both of the spheres rotating on their axis(like planets in orbit around their sun). Players can leave the large sphere and travel through a zero gravity environment to the smaller sphere then walk around on that as well.
Sounds like you just need the two rigid bodies representing the worlds be kinematic. From that you can apply transforms based on very simple (to implement) math to rotate the bodies on their axis and around each other. No need to simulate the bodies physically. The rest can be as described earlier.