FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Physics Constraints

3 posters

Go down

Physics Constraints Empty Physics Constraints

Post  freakTheMighty 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

Back to top Go down

Physics Constraints Empty Re: Physics Constraints

Post  Francescu 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

Back to top Go down

Physics Constraints Empty Re: Physics Constraints

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

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

http://sio2interactive.com

Back to top Go down

Physics Constraints Empty Re: Physics Constraints

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


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