Page 1 of 1

Updating mesh position based on rigidBody position?

Posted: Mon Mar 06, 2017 7:41 pm
by jimjamjack
I'm doing some simple falling physics, nothing special, but I'm not quite sure how to make my model fall instead of just the rigidBody.

I've essentially got:
A floor model with a box collision shape, loaded in
A bullet model with a box collision shape, loaded in
When the program starts, I can see that the rigidBody for the bullet slowly drops to the floor (I have a debug drawer set up), as I've given that rigidBody the same mass, inertia etc as the Bullet wiki's first falling sphere example

However, I'm not sure how to make my bullet model fall along with the rigidBody and make it bounce along the floor like a bullet would in real life. How can I achieve this? Thanks.

Re: Updating mesh position based on rigidBody position?

Posted: Tue Mar 07, 2017 6:43 pm
by erbisme4@yahoo.com
In your graphics update call you have to get the rigidbody transform and apply it to your graphics object.
rigidbody->getMotionState()->getWorldTransform(transform);

Re: Updating mesh position based on rigidBody position?

Posted: Tue Mar 07, 2017 9:14 pm
by jimjamjack
Thanks, that works fine, but it seems odd to me that the I can see the rigidBody shape moving first and then the bullet moving afterwards at each step. Is that okay?

Also, would you happen to know how to simulating the bullet bouncing on the floor on impact? Currently my bullet just sort of drops to the floor and stops.

Thanks.

Re: Updating mesh position based on rigidBody position?

Posted: Wed Mar 08, 2017 9:45 am
by S1L3nCe
"Bouncing" is the restitution.
You can find it in btCollisionObject class.
http://bulletphysics.org/Bullet/BulletF ... bject.html

Re: Updating mesh position based on rigidBody position?

Posted: Thu Mar 09, 2017 2:24 am
by hyyou
jimjamjack wrote:it seems odd to me that the I can see the rigidBody shape moving first and then the bullet moving afterwards at each step. Is that okay?

Yes, it is ok.
I do that for more than a year without any problem.
If I manage "order of update" well enough, I will not suffer 1-frame-lag that you concern.

No one will notice that you use this ugly trick, hee heee (except you).

Re: Updating mesh position based on rigidBody position?

Posted: Thu Mar 09, 2017 6:29 pm
by jimjamjack
S1L3nCe wrote:"Bouncing" is the restitution.
You can find it in btCollisionObject class.
http://bulletphysics.org/Bullet/BulletF ... bject.html
Great, not quite sure how to set it up but at least Bullet takes care of it, thanks.
hyyou wrote:
jimjamjack wrote:it seems odd to me that the I can see the rigidBody shape moving first and then the bullet moving afterwards at each step. Is that okay?

Yes, it is ok.
So long as someone else is doing the same without issue, then it's fine by me :)

Re: Updating mesh position based on rigidBody position?

Posted: Fri Apr 14, 2017 2:32 pm
by erbisme4@yahoo.com
I'm not sure what you mean by you can see the physics object moving before and the graphics following? Are you talking about the debug drawing that bullet does? Sounds to me like the physics object is rendered first, followed by your graphics object.

Re: Updating mesh position based on rigidBody position?

Posted: Fri Apr 14, 2017 3:55 pm
by jimjamjack
Sorry, yeah it was the debug drawing that Bullet did that was moving first. It's not even noticeable after changing how I was stepping the simulation to use delta time :)

Re: Updating mesh position based on rigidBody position?

Posted: Mon Apr 17, 2017 1:55 am
by rebirth
Are you doing it like this?

Update() <--update to desired position
Physics()
Apply() <-- apply to actual position/build matrix etc
Draw()

You could take advantage of the userdata() pointer Bullet offers and set up an automatic callback, or just create pointers to the rigid's world position/quat/etc.

As for restitution, if I recall you have to set the restitution in both bodies. E.G. the wall and the ball.

Re: Updating mesh position based on rigidBody position?

Posted: Mon Apr 17, 2017 4:41 pm
by jimjamjack
Yes, I followed that structure. It's no longer an issue, I was more curious about whether or not that's how it's usually done, but thanks for the suggestions as I'm sure it'll help others.