Created
March 31, 2014 13:53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void AddRigidBodies() { | |
//add the falling movingBox | |
{ | |
hkVector4 halfExtents(0.5f, 0.5f, 0.5f); | |
hkpBoxShape* boxShape = new hkpBoxShape(halfExtents); | |
hkpRigidBodyCinfo ci; | |
ci.m_shape = boxShape; | |
ci.m_position = pos2; | |
ci.m_motionType = hkpMotion::MOTION_DYNAMIC; | |
boxShape->setRadius(0.001f); | |
const hkReal boxMass(10.0f); | |
hkMassProperties massProps; | |
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProps); | |
ci.setMassProperties(massProps); | |
hkpRigidBody* rigidBody = new hkpRigidBody(ci); | |
movingBox = static_cast<hkpRigidBody*>(g_pWorld->addEntity(rigidBody)); | |
rigidBody->removeReference(); | |
//create the fixed box | |
ci.m_position = pos1; | |
ci.m_motionType = hkpMotion::MOTION_FIXED; | |
rigidBody = new hkpRigidBody(ci); | |
fixedBox = static_cast<hkpRigidBody*>(g_pWorld->addEntity(rigidBody)); | |
rigidBody->removeReference(); | |
boxShape->removeReference(); | |
} | |
//create the static box where the smaller movingBox will fall | |
{ | |
hkVector4 halfExtents(20.0f, 2.0f, 20.f); | |
hkpBoxShape* boxShape = new hkpBoxShape(halfExtents); | |
hkpRigidBodyCinfo ci; | |
ci.m_shape = boxShape; | |
ci.m_position = hkVector4(0, -2, 0); | |
ci.m_motionType = hkpMotion::MOTION_FIXED; | |
boxShape->setRadius(0.001f); | |
hkpRigidBody* rigidBody = new hkpRigidBody(ci); | |
boxShape->removeReference(); | |
g_pWorld->addEntity(rigidBody)->removeReference(); | |
} | |
// | |
// CREATE STIFF SPRING CONSTRAINT | |
// | |
{ | |
hkpStiffSpringConstraintData* spring = new hkpStiffSpringConstraintData(); | |
// Create constraint | |
spring->setInWorldSpace(movingBox->getTransform(), fixedBox->getTransform(), pos2, pos1); | |
// | |
// Create and add the constraint | |
// | |
{ | |
hkpConstraintInstance* constraint = new hkpConstraintInstance(movingBox, fixedBox, spring ); | |
g_pWorld->addConstraint(constraint); | |
constraint->removeReference(); | |
} | |
spring->removeReference(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment