Physics Constraints

View previous topic View next topic Go down

Physics Constraints

Post  freakTheMighty on Tue Apr 21, 2009 5:32 pm

I have implemented physics constraints semi-successfully and thought I would share what I've learned.

First the code:

This is inside of my loading function.
Code:

SIO2object *_SIO2object = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
                                               SIO2_OBJECT,
                                               "object/Sphere" );
   
   SIO2object *_SIO2object_ancor = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
                                                   SIO2_OBJECT,
                                                   "object/ancor" );
I'm not sure if I need this to create the ConstraintSolver. It seems to work without it, but it looked like the physics init in SIO2 sets this to NULL.

Code:

   sio2->_SIO2physic->_btConstraintSolver = new btSequentialImpulseConstraintSolver();

I am implementing a btGeneric6DofConstraint. This allows you to do things like hang an object. That is you can set 3 linear constraints and 3 orientation constraints. I'm not entirely sure how frameInA works. I left those values as they were in the BulletSDK Constraint Example.

None the less, you create a btGeneric6DofConstraint by passing it two _btRigidBodies and two btTransform values.

Code:

   btGeneric6DofConstraint* hingeC;
   btTransform frameInA, frameInB;
   frameInA = btTransform::getIdentity();
   frameInA.setOrigin(btVector3(btScalar(-5.), btScalar(0.), btScalar(0.)));
   frameInB = btTransform::getIdentity();
   frameInB.setOrigin(btVector3(btScalar(5.), btScalar(0.), btScalar(0.)));

   hingeC =  new btGeneric6DofConstraint( *_SIO2object->_btRigidBody,*_SIO2object_ancor->_btRigidBody,
                                frameInA, frameInB, true );

Add the constraint to the _btSoftRigidDynamicsWorld. This threw me off a little because in the the bullet SDK example the constraint was added to a _btRigidDynamicsWorld. But it looks like those worlds are combined.

There are a number of possible constraints, including setLinearUpper and LowerLimit. These particular values keep the ball from falling more than 30 units away on the Z. . . and -5 on on the X and Y???? Experiment!

Code:
   
   sio2->_SIO2physic->_btSoftRigidDynamicsWorld->addConstraint(hingeC, true);
   hingeC->setLinearUpperLimit(btVector3(-5., -5., 30.));

I'm trying to figure out how to dynamically change the constraint. I haven't yet figured out where or how to access the hingeC object after its been added to the _btSoftRigidDynamicWorld. I'll let y'all know when I've an answer.

Thats all for now.

freakTheMighty

Posts : 12
Join date : 2009-03-05

View user profile

Back to top Go down

Re: Physics Constraints

Post  Francescu on Tue Apr 21, 2009 6:02 pm

In my case, I just save the constraint in my own variables / arrays to access it later. I use the base class btTypedConstraint for that...and then cast it back to its specialized type as to what to expect later in my logic.

To remove the constraint I just call sio2->_SIO2physic->_btSoftRigidDynamicsWorld->removeConstraint(myConstraintObj) and delete the constraint object afterwards...

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: Physics Constraints

Post  sio2interactive on Tue Apr 21, 2009 6:10 pm

this is definitely more a Bullet issue than a SIO2 one... try your luck on the Bullet forum...

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Physics Constraints

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum