I'd like an object to always stay vertical. It can translate freely in all directions, but the rotation should be constrained only on the Y axis.
For now, I have this code:
Code: Select all
btBoxShape
* box_shape;
btVector3
half_extent,
local_intertia( 0, 0, 0 );
half_extent = //...
box_shape = new btBoxShape( half_extent );
if ( mass != 0.0f )
{
box_shape->calculateLocalInertia( mass, local_intertia );
}
btRigidBody::btRigidBodyConstructionInfo
construction_info( mass, &MotionState, box_shape, local_intertia );
Object = new btRigidBody( construction_info );
Object->setRestitution( 0.8f );
Object->setFriction( 3.0f );
Object->setDamping( 0.02f, 0.1f );
btVector3
aabb_min,
aabb_max,
pivot;
Object->getAabb( aabb_min, aabb_max );
pivot = ( aabb_min + aabb_max ) / 2;
pivot.setY( aabb_max.y() - aabb_min.y() );
btHingeConstraint
* constraint = new btHingeConstraint( *Object, pivot, btVector3( 0, 1, 0 ) );
ConstraintsTable.AddLastItem( constraint );
Object->addConstraintRef( constraint );
Object->setCcdMotionThreshold( motion_threshold );
Object->setCcdSweptSphereRadius( motion_threshold / 2.0f );
Is the Hinge constraint what I need? If not, how should I do that?
Thanks in advance