Skip to content

Instantly share code, notes, and snippets.

View mmmovania's full-sized avatar

Muhammad Mobeen Movania mmmovania

  • Habib University
  • Karachi, PAKISTAN
  • 00:58 - 5h ahead
View GitHub Profile
//draw spring
glBegin(GL_LINES);
glColor3f(0,0,1);
g_pWorld->markForRead();
for(size_t i=0;i<indices.size()-4;i+=4) {
int i0 = indices[i];
int i1 = indices[i+1];
int i2 = indices[i+2];
int i3 = indices[i+3];
hkVector4f p0 = masses[i0]->getTransform().getTranslation();
//draw boxes
glEnable(GL_LIGHTING);
for(size_t i=0;i<masses.size();++i) {
glColor3f(1,1,1);
if(wasHit && gSelectedActor == masses[i])
glColor3f(1,0,0);
DrawBox(masses[i], true);
}
hkpStiffSpringConstraintData* spring= new hkpStiffSpringConstraintData();
for (l1 = 0; l1 < v; l1++) // v
for (l2 = 0; l2 < (u - 1); l2++) {
int index0 = (l1 * u) + l2;
int index1 = (l1 * u) + l2 + 1;
hkpRigidBody* r0 = masses[index0];
hkpRigidBody* r1 = masses[index1];
hkVector4f r0Pos = r0->getTransform().getTranslation();
hkVector4f r1Pos = r1->getTransform().getTranslation();
spring->setInWorldSpace(r0->getTransform(), r1->getTransform(), r0Pos, r1Pos);
//add the falling movingBox
{
hkVector4 halfExtents(boxSize,boxSize,boxSize);
hkpBoxShape* boxShape = new hkpBoxShape(halfExtents);
hkpRigidBodyCinfo ci;
ci.m_shape = boxShape;
ci.m_position = pos2;
//create the static box where the smaller box 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);
//now add springs between adjacent boxes
hkpStiffSpringConstraintData* spring = new hkpStiffSpringConstraintData();
hkpStiffSpringConstraintData* spring2 = new hkpStiffSpringConstraintData();
for(size_t i=0;i<boxes.size()-1;i++) {
hkTransform b1 = boxes[i]->getTransform();
hkTransform b2 = boxes[i+1]->getTransform();
hkVector4f t1 = b1.getTranslation();
hkVector4f t2 = b2.getTranslation();
t1.add(hkVector4f(-0.5,0.5,0));
hkVector4 halfExtents(0.5f, 0.5f, 0.125f);
hkpBoxShape* boxShape = new hkpBoxShape(halfExtents);
boxShape->setRadius(0.001f);
hkpRigidBodyCinfo ci;
ci.m_shape = boxShape;
ci.m_motionType = hkpMotion::MOTION_DYNAMIC;
const hkReal boxMass(10.0f);
hkMassProperties massProps;
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProps);
void AddRigidBodies() {
//add the falling box
{
hkVector4 halfExtents(0.5f, 0.5f, 0.125f);
hkpBoxShape* boxShape = new hkpBoxShape(halfExtents);
boxShape->setRadius(0.001f);
hkpRigidBodyCinfo ci;
ci.m_shape = boxShape;
ci.m_motionType = hkpMotion::MOTION_DYNAMIC;
//draw spring
glBegin(GL_LINES);
glColor3f(0,1,0);
glVertex3f(pos1.getComponent(0), pos1.getComponent(1), pos1.getComponent(2));
glVertex3f(pos2.getComponent(0), pos2.getComponent(1), pos2.getComponent(2));
glEnd();
//draw boxes
glEnable(GL_LIGHTING);
glColor3f(1,1,1);
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();