Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Aug 03, 2012 7:48 pm 
Offline

Joined: Fri Aug 03, 2012 2:18 pm
Posts: 3
Hi,

I have implemented collision on wall segments (single .dae model) in a game using
bullet physics. Now I want the wall to have a door, and to open and let the player through,
so basically create a hole in the shape. There is a wall model with a door that is animated already.

What would be best practice here?
- Remove the RigidBody from the collisionWorld and add a new one when door opens/closes
- track it outside the world by reference and somehow manipulate the sub shape (I'm assuming this will need a CompoundShape)

Is there some other approach that is better?

Best regards
Andreas
Hobby programmer


Top
 Profile  
 
PostPosted: Tue Aug 07, 2012 4:22 am 
Offline

Joined: Tue Aug 07, 2012 3:27 am
Posts: 6
Hello, I'm new to bullet but I did something similar in the game I'm working on so maybe I can help. (I have a door that the player can push to open/close.)

You can use a "spDoorHinge" constraint from the bullet Constraints Demo. I have the wall with the hole for the door and the door is just a btRigidbody in the shape of a door with a btHingeConstraint applied to it.

So my code to create/add the door to the dynamicsworld is something like this:

Code:
//door
      btCollisionShape* pDoorShape = new btBoxShape(btVector3(5.0f, 5.9f, 0.5f));  //the door shape
      trans.setIdentity();
      trans.setOrigin(btVector3(105.0f, 2.0f, 29.5f)); //position of the door
      motionState = new btDefaultMotionState(trans);
      pDoorBody = new btRigidBody(btScalar(1.0), motionState, pDoorShape, btVector3(1,1,1)); //mass=1.0
      const btVector3 btPivotA(4.8f , 0.0f, 0.0f ); // position of the door pivot
      btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pivot pointing up Y-axis (rotate on Y axis)
      btHingeConstraint* spDoorHinge; 
      spDoorHinge = new btHingeConstraint( *pDoorBody, btPivotA, btAxisA );//add HingeConstraint to the door
      spDoorHinge->setLimit( -PI * 0.5f, PI * 0.5f ); //set door movement limit from -90° to+90°  (PI=3.1415)
      dynamicsWorld->addConstraint(spDoorHinge);  //add door hinge constraints to the world
      dynamicsWorld->addRigidBody(pDoorBody);  //add door to the world
      //If you want to dampen the movement of the door you can do
      pDoorBody->setDamping(1.4f,0.0);   // modify the first argument to increase damping strength.
      pDoorBody->applyDamping(1.4);



Hope this helps. This is my first post here so hopefully this comes out ok. I tried adding some comments just now hopefully they aren't too confusing...lol

Check the Constraint Demo for the btHingeConstraint.


Last edited by Shogo on Fri Aug 17, 2012 1:13 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed Aug 08, 2012 11:14 pm 
Offline

Joined: Sat Nov 26, 2011 5:41 pm
Posts: 22
andreas wrote:
Hi,
What would be best practice here?
- Remove the RigidBody from the collisionWorld and add a new one when door opens/closes
- track it outside the world by reference and somehow manipulate the sub shape (I'm assuming this will need a CompoundShape)

Is there some other approach that is better?


Usually it is better to remove the body and insert a new, modified body. There are some issues/bugs with trying to change the shape of existing objects in some situations.. you'll think it works and then it'll bug out somewhere else.. :)

Or use a real simulated physical door like the other poster suggested.


Top
 Profile  
 
PostPosted: Thu Feb 21, 2013 7:55 pm 
Offline

Joined: Wed Feb 20, 2013 6:14 am
Posts: 6
how to converts an axis vector, or direction vector, from the world coordinate system to a body's local coordinate system ?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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