motion state and others

Post Reply
mgs_oleg
Posts: 10
Joined: Mon Jun 08, 2015 6:25 pm

motion state and others

Post by mgs_oleg »

Hi All,
I've run throught the documents but cannot understand few things clearly
- gravity - what is the proper way of setting correct value of it?
- motionState - I am using btDefaultMotionState but still have lack of understanding what is the arguments whould be passed - like where we take all numbers for tranformation, as in below example

Code: Select all

	btDefaultMotionState* motionstate = new btDefaultMotionState(btTransform(
		btQuaternion(0.0f, 0.0f, 0.0f, 1),
		btVector3(1.5f, 0.0f, -7.0f)
		));
- the rigid body - same goes here as for motion state, if you could give me a hint on understanding all of those numbers passed

Code: Select all

btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(
		0,                  // mass, in kg. 0 -> Static object, will never move.
		motionstate,
		collisionShape,  // collision shape of body
		btVector3(0, 0, 0)    // local inertia
		);
- for the convex hull looks like we adding points to it that represents our mesh. Am I correct


Please help someone with that as I am really need to understand it in the right way.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: motion state and others

Post by hyyou »

mgs_oleg wrote: Sun Apr 01, 2018 11:25 am - gravity - what is the proper way of setting correct value of it?
To avoid any issue, I set it as (0,0,0) and apply gravity impulse every time-step instead.
mgs_oleg wrote: Sun Apr 01, 2018 11:25 am btQuaternion(0.0f, 0.0f, 0.0f, 1),
I read http://www.opengl-tutorial.org/intermed ... aternions/
mgs_oleg wrote: Sun Apr 01, 2018 11:25 am btVector3(0, 0, 0) // local inertia
This one is hard.
I read http://number-none.com/blow/inertia/deriving_i.html and https://en.wikipedia.org/wiki/Sylvester ... of_inertia

The last question -> I don't know.

I can't sign-up to edit those wiki pages. I agree that some detail should be added.
mgs_oleg
Posts: 10
Joined: Mon Jun 08, 2015 6:25 pm

Re: motion state and others

Post by mgs_oleg »

Thanks that's help.
Just curious if there is someone who could update documentation (at least concepts without any strong connection to implementation) - I beleive that will help a lot to beginners to get an idea of basic things.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: motion state and others

Post by drleviathan »

There is a world-wide default gravity setting, which defaults to <0,-10,0>. To change it use:

Code: Select all

btDiscreteCollisionWorld::setGravity(const btVector3&)
There is a per-RigidBody gravity override.

Code: Select all

btRigidBody::setGravity(const btVector3&)
When a dynamic object is added to the world its gravity is set to the world gravity...

... unless its BT_DISABLE_WORLD_GRAVITY flag is set:

Code: Select all

body->setFlags(body->getFlags() | BT_DISABLE_WORLD_GRAVITY);
Note: when the the world gravity is changed then all dynamic objects get their gravity updated... except those with BT_DISABLE_WORLD_GRAVITY set.

Bodies with BT_DISABLE_WORLD_GRAVITY set use whatever gravity was manually set on them. If you DO use the BT_DISABLE_WORLD_GRAVITY flag you need to be sure to actually set the object's gravity (or else set the flag after it has been added to the world) because the btRigidBody::m_gravity data member is not initialized in the ctor.


The MotionState is a hook to facilitate trading transforms between the btRigidBody and your GameObject. Sometimes you want your GameObject to be updated by physics but sometimes you have a kinematic object whose motion is driven from outside the physics simulation: for example when it is moving along a scripted path. The way it is supposed to work is as follows:

You derive MyCustomMotionState from btMotionState and you must implement the two pure virtual methods:

Code: Select all

void getWorldTransform(btTransform& worldTrans);
void setWorldTransform(const btTransform& worldTrans);
btMotionState::getWorldTransform() is called for only two cases:

(1) When you first add a body to the world, if it has a MotionState then getWorldTransform() on that state is called to place the object within the world.

(2) For each active kinematic object that has a MotionState: getWorldTransform() is called on that state at the end of each simulaition substep. The idea here is that the MotionState is supposed to fetch or compute the correct transform according to whatever logic is moving it around within the physics engine.

btMotionState::setWorldTransform() is called for each dynamic active object at the end of each simulaition substep. You're supposed to implement that method such that it copies the body's transform into your GameObject. Note: setWorldTransform() will compute an interpolated transform when you're using fixed substeps but there is a timestep remainder: this to reduce aliasing effects between the physics substep rate and the render frame rate.

btDefaultMotionState is a minimal implementation of the pure virtual btMotionState interface.


A btTransform is a 4x4 matrix that stores a rotation and a translation, and it is used to specify an object's position and orientation in the world, or to specity a transformation from one frame to another. The translation part can be represented as a btVector3. The rotation part can be represented as a btQuaternion. Quaternions are a little complicated: best to research them online than for me to try to explain them here. However, I will point out that the identity rotation in quaternion form is: <x,y,z,w> = <0,0,0,1>, which is what is being passed to the MotionState in the above example.


Yes, a btConvexHullShape can have its points set one at a time. The shape doesn't have a "mesh" per se, but instead has a set of points that define its outer bounds. Ideally all the points supplied to the shape really are on the boundary, however the btConvexHullShape implementation can handle interior points: they are just wasteful. The number of points used in the convex hull is not bounded, but you'd be doing it wrong if you add too many. There are some utils in Bullet that can help you collapse many points down to a smaller set that has approximately the same shape.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: motion state and others

Post by hyyou »

Thank a lot, drleviathan, for very rich answer!
I gain extra knowledge from your gravity and btConvexHullShape part.
I will follow you everywhere. XD
mgs_oleg
Posts: 10
Joined: Mon Jun 08, 2015 6:25 pm

Re: motion state and others

Post by mgs_oleg »

thanks all for help.
Post Reply