Physics Constraints
3 posters
Physics Constraints
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.
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.
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!
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.
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" );
- 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
Re: Physics Constraints
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...
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
Re: Physics Constraints
this is definitely more a Bullet issue than a SIO2 one... try your luck on the Bullet forum...
Similar topics
» SIO2 Architecture and Bullet Physics integration
» Constraints and soft bodies
» Handling Bullet constraints, advice?
» physics object inside another physics object
» Bouncing ball physics
» Constraints and soft bodies
» Handling Bullet constraints, advice?
» physics object inside another physics object
» Bouncing ball physics
Permissions in this forum:
You cannot reply to topics in this forum