Updating mesh position based on rigidBody position?

Post Reply
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Updating mesh position based on rigidBody position?

Post 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.
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: Updating mesh position based on rigidBody position?

Post 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);
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Updating mesh position based on rigidBody position?

Post 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.
S1L3nCe
Posts: 50
Joined: Thu Mar 24, 2016 10:22 am
Location: France

Re: Updating mesh position based on rigidBody position?

Post by S1L3nCe »

"Bouncing" is the restitution.
You can find it in btCollisionObject class.
http://bulletphysics.org/Bullet/BulletF ... bject.html
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: Updating mesh position based on rigidBody position?

Post 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).
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Updating mesh position based on rigidBody position?

Post 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 :)
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: Updating mesh position based on rigidBody position?

Post 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.
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Updating mesh position based on rigidBody position?

Post 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 :)
rebirth
Posts: 24
Joined: Thu Jul 24, 2014 2:48 am

Re: Updating mesh position based on rigidBody position?

Post 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.
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Updating mesh position based on rigidBody position?

Post 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.
Post Reply