Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Oct 11, 2017 4:55 am 
Offline

Joined: Wed Oct 11, 2017 4:45 am
Posts: 6
I'm studying Hello World example (commit e36b7e0 on Mar 14) of Bullet.
I see that I can only move the ball when the ball is falling with this code:
Code:
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[1];/*0 is the ground, 1 is the ball*/
btRigidBody* body = btRigidBody::upcast(obj);
body->translate(btVector3(0, 50, 0)); //This will try to move the ball up, but only work when the ball is falling


When the ball is on the ground, I can't move the ball anymore :( I don't understand how this thing work, please help me :cry:

Thanks for reading :)


Top
 Profile  
 
PostPosted: Wed Oct 11, 2017 5:09 am 
Offline
User avatar

Joined: Tue Sep 30, 2014 6:03 pm
Posts: 346
Location: San Francisco
You should be doing somthing this:
Code:
btTransform transform = object->getWorldTransform();
btVector3 position = transform.getOrigin();
transform.setOrigin(position + btVector3(0, 50, 0));
object->setWorldTransform(transform)

Also, you probably want to activate the ball whenever you move it, just in case it has deactivated. Otherwise it might move to the new location but not fall.
Code:
object->activate();


Top
 Profile  
 
PostPosted: Wed Oct 11, 2017 5:28 am 
Offline

Joined: Wed Oct 11, 2017 4:45 am
Posts: 6
drleviathan wrote:
You should be doing somthing this:
Code:
btTransform transform = object->getWorldTransform();
btVector3 position = transform.getOrigin();
transform.setOrigin(position + btVector3(0, 50, 0));
object->setWorldTransform(transform)


I think translate will make the object move more 'physically like'.
And I just found out that we can also use applyForce() to move the ball (the force has to be big like 1000)
Code:
body->applyForce(btVector3(0, 1000, 0), btVector3(0, 50, 0));


drleviathan wrote:
Also, you probably want to activate the ball whenever you move it, just in case it has deactivated. Otherwise it might move to the new location but not fall.
Code:
object->activate();

Thank drleviathan, it works, the method activate() for the rigid body is the answer :)
Code:
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[1];/*0 is the ground, 1 is the ball*/
btRigidBody* body = btRigidBody::upcast(obj);
/*This will try to move the ball up,
but only work when the ball is falling, not when it's on the ground*/
body->translate(btVector3(0, 50, 0));
/*After add this code, the ball can be moved up when it's on the ground*/
body->activate();


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group