[SOLVED] Collision shape shifted from node

aj1nkya

04-03-2013 15:43:31

Hi! I am having problem with creating collison shape for node.
I have this three functions which creates mesh for ground, pillar and slab of building.
void CSceneEditorView::createPillarMesh()
{
Ogre::ManualObject* lManualObject = NULL;
{
Ogre::String lManualObjectName = "pillar";
lManualObject = m_SceneManager->createManualObject(lManualObjectName);

bool lDoIWantToUpdateItLater = false;
lManualObject->setDynamic(lDoIWantToUpdateItLater);

lManualObject->begin("", Ogre::RenderOperation::OT_TRIANGLE_LIST);
{
float cp = 10.0f;
float cm = -10.0f;

lManualObject->position(cm, 8*cp, -10);// a vertex
lManualObject->position(cp, 8*cp, -10);// a vertex
lManualObject->position(cp, cm, -10);// a vertex
lManualObject->position(cm, cm, -10);// a vertex

lManualObject->position(cm, 8*cp, 10);// a vertex
lManualObject->position(cp, 8*cp, 10);// a vertex
lManualObject->position(cp, cm, 10);// a vertex
lManualObject->position(cm, cm, 10);// a vertex

// face behind / front
lManualObject->triangle(0,1,2);
lManualObject->triangle(2,3,0);
lManualObject->triangle(4,6,5);
lManualObject->triangle(6,4,7);

// face top / down
lManualObject->triangle(0,4,5);
lManualObject->triangle(5,1,0);
lManualObject->triangle(2,6,7);
lManualObject->triangle(7,3,2);

// face left / right
lManualObject->triangle(0,7,4);
lManualObject->triangle(7,0,3);
lManualObject->triangle(1,5,6);
lManualObject->triangle(6,2,1);
}
lManualObject->end();
}
Ogre::String lNameOfTheMesh = "pillar";
Ogre::String lResourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
lManualObject->convertToMesh(lNameOfTheMesh);

}

void CSceneEditorView::createSlabMesh()
{
Ogre::ManualObject* lManualObject = NULL;
{
Ogre::String lManualObjectName = "slab";
lManualObject = m_SceneManager->createManualObject(lManualObjectName);

bool lDoIWantToUpdateItLater = false;
lManualObject->setDynamic(lDoIWantToUpdateItLater);

lManualObject->begin("", Ogre::RenderOperation::OT_TRIANGLE_LIST);
{
float cp = 10.0f;
float cm = -10.0f;

lManualObject->position(cm, cp, -10);// a vertex
lManualObject->position(8*cp, cp, -10);// a vertex
lManualObject->position(8*cp, cm, -10);// a vertex
lManualObject->position(cm, cm, -10);// a vertex

lManualObject->position(cm, cp, 80);// a vertex
lManualObject->position(8*cp, cp, 80);// a vertex
lManualObject->position(8*cp, cm, 80);// a vertex
lManualObject->position(cm, cm, 80);// a vertex

// face behind / front
lManualObject->triangle(0,1,2);
lManualObject->triangle(2,3,0);
lManualObject->triangle(4,6,5);
lManualObject->triangle(6,4,7);

// face top / down
lManualObject->triangle(0,4,5);
lManualObject->triangle(5,1,0);
lManualObject->triangle(2,6,7);
lManualObject->triangle(7,3,2);

// face left / right
lManualObject->triangle(0,7,4);
lManualObject->triangle(7,0,3);
lManualObject->triangle(1,5,6);
lManualObject->triangle(6,2,1);
}
lManualObject->end();
}
Ogre::String lNameOfTheMesh = "slab";
Ogre::String lResourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
lManualObject->convertToMesh(lNameOfTheMesh);
}

void CSceneEditorView::createFloorMesh()
{
Ogre::ManualObject* lManualObject = NULL;
{
Ogre::String lManualObjectName = "ground";
lManualObject = m_SceneManager->createManualObject(lManualObjectName);

bool lDoIWantToUpdateItLater = false;
lManualObject->setDynamic(lDoIWantToUpdateItLater);

lManualObject->begin("", Ogre::RenderOperation::OT_TRIANGLE_LIST);
{
float cp = 10.0f;
float cm = -10.0f;

lManualObject->position(cm, cp, -10);// a vertex
lManualObject->position(15*cp, cp, -10);// a vertex
lManualObject->position(15*cp, cm, -10);// a vertex
lManualObject->position(cm, cm, -10);// a vertex

lManualObject->position(cm, cp, 150);// a vertex
lManualObject->position(15*cp, cp, 150);// a vertex
lManualObject->position(15*cp, cm, 150);// a vertex
lManualObject->position(cm, cm, 150);// a vertex

// face behind / front
lManualObject->triangle(0,1,2);
lManualObject->triangle(2,3,0);
lManualObject->triangle(4,6,5);
lManualObject->triangle(6,4,7);

// face top / down
lManualObject->triangle(0,4,5);
lManualObject->triangle(5,1,0);
lManualObject->triangle(2,6,7);
lManualObject->triangle(7,3,2);

// face left / right
lManualObject->triangle(0,7,4);
lManualObject->triangle(7,0,3);
lManualObject->triangle(1,5,6);
lManualObject->triangle(6,2,1);
}
lManualObject->end();
}
Ogre::String lNameOfTheMesh = "ground";
Ogre::String lResourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
lManualObject->convertToMesh(lNameOfTheMesh);
}


Then i have created createBuilding function which takes as input name of building, number of floors and position of building
void CSceneEditorView::createBuilding(Ogre::String name, int floor, long x,long y,long z)
{ int i = 0, j = 0;

//create building
Ogre::SceneNode *building_node = m_SceneManager->getRootSceneNode()->createChildSceneNode(name, Ogre::Vector3(x,y,z));

//create floor
Ogre::SceneNode *ground_node = building_node->createChildSceneNode(Ogre::String("ground_node_"+Ogre::StringConverter::toString(groundCounter)),(Ogre::Vector3(-30,0,-30)));
Ogre::Entity *ground_entity = m_SceneManager->createEntity(Ogre::String("ground_entity_"+Ogre::StringConverter::toString(groundCounter)), "ground");
ground_node->attachObject(ground_entity);
groundCounter++;

//Create the ground shape.
BtOgre::StaticMeshToShapeConverter converter1(ground_entity);
mGroundShape[groundCounter-1] = converter1.createTrimesh();

//Create BtOgre MotionState (connects Ogre and Bullet).
groundState[groundCounter-1] = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(ground_node->_getDerivedPosition())));

//Create the Body.
mGroundBody[groundCounter-1] = new btRigidBody(0, groundState[groundCounter-1], mGroundShape[groundCounter-1], btVector3(0,0,0));
Globals::phyWorld->addRigidBody(mGroundBody[groundCounter-1]);

//mass of pillar
btScalar mass = 5;
btVector3 inertia;

for(int k=0; k<floor; k++)
{ //first pillar
Ogre::SceneNode *pillar_node_1 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)),((Ogre::Vector3(0,20,0))+k*Ogre::Vector3(0,110,0)));//,Ogre::Quaternion::IDENTITY);
Ogre::Entity *pillar_entity_1 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_1->attachObject(pillar_entity_1);
counter++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter2(pillar_entity_1);
mPillarShape[groundCounter-1] = converter2.createConvex();
//Calculate inertia.
btScalar mass = 5;
btVector3 inertia;
mPillarShape[groundCounter-1]->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
mPillarState[groundCounter-1] = new BtOgre::RigidBodyState(pillar_node_1,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pillar_node_1->_getDerivedPosition())));
mPillarState;
//Create the Body.
mPillarBody[groundCounter-1] = new btRigidBody(mass, mPillarState[groundCounter-1] , mPillarShape[groundCounter-1], inertia);

Globals::phyWorld->addRigidBody(mPillarBody[groundCounter-1]);
i++;
//second pillar
Ogre::SceneNode *pillar_node_2 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(70,20,0)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *pillar_entity_2 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_2->attachObject(pillar_entity_2);
counter++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter3(pillar_entity_2);
mPillarShape[groundCounter-1] = converter3.createConvex();
//Calculate inertia.
mPillarShape[groundCounter-1]->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
mPillarState[groundCounter-1] = new BtOgre::RigidBodyState(pillar_node_2,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pillar_node_2->_getDerivedPosition())));
//Create the Body.
mPillarBody[groundCounter-1] = new btRigidBody(mass, mPillarState[groundCounter-1], mPillarShape[groundCounter-1], inertia);
Globals::phyWorld->addRigidBody(mPillarBody[groundCounter-1]);
i++;
//third pillar
Ogre::SceneNode *pillar_node_3 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(0,20,70)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *pillar_entity_3 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_3->attachObject(pillar_entity_3);
counter++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter4(pillar_entity_3);
mPillarShape[groundCounter-1] = converter4.createConvex();
//Calculate inertia.
mPillarShape[groundCounter-1]->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
mPillarState[groundCounter-1] = new BtOgre::RigidBodyState(pillar_node_3,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pillar_node_3->_getDerivedPosition())));
//Create the Body.
mPillarBody[groundCounter-1] = new btRigidBody(mass, mPillarState[groundCounter-1], mPillarShape[groundCounter-1], inertia);
Globals::phyWorld->addRigidBody(mPillarBody[groundCounter-1]);
i++;
//fourth pillar
Ogre::SceneNode *pillar_node_4 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(70,20,70)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *pillar_entity_4 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_4->attachObject(pillar_entity_4);
counter++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter5(pillar_entity_4);
mPillarShape[groundCounter-1] = converter5.createConvex();
//Calculate inertia.
mPillarShape[groundCounter-1]->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
mPillarState[groundCounter-1] = new BtOgre::RigidBodyState(pillar_node_4,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pillar_node_4->_getDerivedPosition())));
//Create the Body.
mPillarBody[groundCounter-1] = new btRigidBody(mass, mPillarState[groundCounter-1], mPillarShape[groundCounter-1], inertia);
Globals::phyWorld->addRigidBody(mPillarBody[groundCounter-1]);
i++;
//slab
Ogre::SceneNode *slab_node = building_node->createChildSceneNode(Ogre::String("slab_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(0,110,0)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *slab_entity = m_SceneManager->createEntity(Ogre::String("slab_entity_"+Ogre::StringConverter::toString(counter)),"slab");
slab_node->attachObject(slab_entity);
counter++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter(slab_entity);
mSlabShape[groundCounter-1][j] = converter.createConvex();
//Calculate inertia.
btScalar mass1 = 10;
btVector3 inertia1;
mSlabShape[groundCounter-1][j]->calculateLocalInertia(mass1, inertia1);
//Create BtOgre MotionState (connects Ogre and Bullet).
mSlabState[groundCounter-1][j] = new BtOgre::RigidBodyState(slab_node,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(slab_node->_getDerivedPosition())));
//Create the Body.
mSlabBody[groundCounter-1][j] = new btRigidBody(mass, mSlabState[groundCounter-1][j], mSlabShape[groundCounter-1][j], inertia1);
Globals::phyWorld->addRigidBody(mSlabBody[groundCounter-1][j]);
j++;
}
}


first i have used BtOgre::RigidBodyStare(node) but it was giving wrong output because it was taking local position with respect to building node. So used _getDerivedPosition() to get position of node in world.

It works correctly. But node get shifted from shape.
Here are two images
this one is with building positioned at 0,0,0. Output of it is correct. Both node and shape are in correct position.

This one is with building at 400,0,0. Here shape is correctly at 400,0,0 but building node is at 800,0,0.

I dont know why. But i think building node gets shifted twice.
Any idea what is wrong with code or it's other problem?

aj1nkya

05-03-2013 18:23:18

Got it!
Why it was not working?
Answer:
Lets say you have root node and you have set it at 400,0,0.
Then you have node which child of root node. Lets say its at 20,0,0 with respect to root node. So its world position is 420,0,0.
now i converted child node to collision shpe with
BtOgre::StaticMeshToShapeConverter converter(entity);
mShape = converter.createConvex();

Then i attached created rigid body state to connect child node and bullet

//Create BtOgre MotionState (connects Ogre and Bullet).
mState = new BtOgre::RigidBodyState(child_node,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(child_node->_getDerivedPosition())));

i used _getDerivedPosition because if i wont use it. My collision shape will be at 20,0,0 and not at 420,0,0. Hence getDerivedPosition will shift shape to 420,0,0.
But what was happening here is that. As child_node is child of root node. So basically my child node gets automatically shifted to 420,0,0 in world position.
but in BtOgre::RigidBodyState shifts node again by 420,0,0. Hence my shape will be at correct position i.e 420,0,0 but my child_node will be at 840,0,0 (420,0,0 + 420,0,0).
For just now i have removed two lines from setWorldTransform() in RigidBodyState which was causing this
now by function looks like this

virtual void setWorldTransform(const btTransform &in)
{
if (mNode == NULL)
return;

mTransform = in;
btTransform transform = in * mCenterOfMassOffset;

btQuaternion rot = transform.getRotation();
btVector3 pos = transform.getOrigin();
//mNode->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
//mNode->setPosition(pos.x(), pos.y(), pos.z());
}

aj1nkya

06-03-2013 13:34:06

commenting those two lines solved my problem but it can no longer get updated by bullet. Only shape gets shifted not node.
So i made it like this. IF i want node at 400,0,0 then i first shifted building_node to 0,0,0. Then while applying rigid body state i gave 400,0,0 + node of position.
Now it works correctly. :)

and also i shifted making node rigid body from createBuilding() to new function.

void CSceneEditorView::createBuilding(Ogre::String name, int floor, long x,long y,long z)
{
//Store the data to be exported to xml
bname[index]=name.c_str ();
floors[index]=floor;
xpos[index]=x;
ypos[index]=y;
zpos[index]=z;
counter_pos[index] = counter;
index++;

//create building
Ogre::SceneNode *building_node = m_SceneManager->getRootSceneNode()->createChildSceneNode(name,Ogre::Vector3(x,y,z));

//create floor
Ogre::SceneNode *ground_node = building_node->createChildSceneNode(Ogre::String("ground_node_"+Ogre::StringConverter::toString(counter)),Ogre::Vector3(-30,0,-3));
Ogre::Entity *ground_entity = m_SceneManager->createEntity(Ogre::String("ground_entity_"+Ogre::StringConverter::toString(counter)), "ground");
ground_node->attachObject(ground_entity);
counter++;

for(int k=0; k<floor; k++)
{ //first pillar
Ogre::SceneNode *pillar_node_1 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)),((Ogre::Vector3(0,20,0))+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *pillar_entity_1 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_1->attachObject(pillar_entity_1);
counter++;

//second pillar
Ogre::SceneNode *pillar_node_2 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(70,20,0)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *pillar_entity_2 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_2->attachObject(pillar_entity_2);
counter++;

//third pillar
Ogre::SceneNode *pillar_node_3 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(0,20,70)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *pillar_entity_3 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_3->attachObject(pillar_entity_3);
counter++;

//fourth pillar
Ogre::SceneNode *pillar_node_4 = building_node->createChildSceneNode(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(70,20,70)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *pillar_entity_4 = m_SceneManager->createEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(counter)), "pillar");
pillar_node_4->attachObject(pillar_entity_4);
counter++;

//slab
Ogre::SceneNode *slab_node = building_node->createChildSceneNode(Ogre::String("slab_node_"+Ogre::StringConverter::toString(counter)), (Ogre::Vector3(0,110,0)+k*Ogre::Vector3(0,110,0)));
Ogre::Entity *slab_entity = m_SceneManager->createEntity(Ogre::String("slab_entity_"+Ogre::StringConverter::toString(counter)),"slab");
slab_node->attachObject(slab_entity);
counter++;
}
}


OnRunESim() contains code for converting from node to body
void CSceneEditorView::OnRunEsim()
{
int bodyCounter = 0;
//convert 3d building to physical building
for(int i=0;i<index;i++)
{
//get building
Ogre::SceneNode *building_node = m_SceneManager->getSceneNode(Ogre::String(bname[i]));
building_node->setPosition(Ogre::Vector3(0,0,0));
int c = counter_pos[i];
Ogre::Vector3 pos(xpos[i],ypos[i],zpos[i]);
//get floor
Ogre::SceneNode *ground_node = (Ogre::SceneNode *)building_node->getChild(Ogre::String("ground_node_"+Ogre::StringConverter::toString(c)));
Ogre::Entity *ground_entity = m_SceneManager->getEntity(Ogre::String("ground_entity_"+Ogre::StringConverter::toString(c)));
c++;
ground_node->setPosition(pos+ground_node->getPosition());
//Create the ground shape.
BtOgre::StaticMeshToShapeConverter converter1(ground_entity);
mGroundShape = converter1.createTrimesh();

//Create BtOgre MotionState (connects Ogre and Bullet).
btDefaultMotionState *groundState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(ground_node->_getDerivedPosition())));
//Create the Body.
mGroundBody = new btRigidBody(0, groundState, mGroundShape, btVector3(0,0,0));
Globals::phyWorld->addRigidBody(mGroundBody);
//mass of pillar
btScalar mass = 5;
btVector3 inertia;

for(int k=0; k<floors[i]; k++)
{
//first pillar
Ogre::SceneNode *pillar_node_1 = (Ogre::SceneNode *)building_node->getChild(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(c)));
Ogre::Entity *pillar_entity_1 = m_SceneManager->getEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(c)));
c++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter2(pillar_entity_1);
mPillarShape = converter2.createConvex();
//Calculate inertia.
btScalar mass = 5;
btVector3 inertia;
mPillarShape->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
BtOgre::RigidBodyState* mPillarState = new BtOgre::RigidBodyState(pillar_node_1,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pos+pillar_node_1->getPosition())));
mPillarState;
//Create the Body.
mBody[bodyCounter] = new btRigidBody(mass, mPillarState, mPillarShape, inertia);
Globals::phyWorld->addRigidBody(mBody[bodyCounter]);
bodyCounter++;

//second pillar
Ogre::SceneNode *pillar_node_2 = (Ogre::SceneNode *)building_node->getChild(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(c)));
Ogre::Entity *pillar_entity_2 = m_SceneManager->getEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(c)));
c++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter3(pillar_entity_2);
mPillarShape = converter3.createConvex();
//Calculate inertia.
mPillarShape->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
mPillarState = new BtOgre::RigidBodyState(pillar_node_2,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pos+pillar_node_2->getPosition())));
//Create the Body.
mBody[bodyCounter] = new btRigidBody(mass, mPillarState, mPillarShape, inertia);
Globals::phyWorld->addRigidBody(mBody[bodyCounter]);
bodyCounter++;

//third pillar
Ogre::SceneNode *pillar_node_3 = (Ogre::SceneNode *)building_node->getChild(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(c)));
Ogre::Entity *pillar_entity_3 = m_SceneManager->getEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(c)));
c++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter4(pillar_entity_3);
mPillarShape = converter4.createConvex();
//Calculate inertia.
mPillarShape->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
mPillarState = new BtOgre::RigidBodyState(pillar_node_3,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pos+pillar_node_3->getPosition())));
//Create the Body.
mBody[bodyCounter] = new btRigidBody(mass, mPillarState, mPillarShape, inertia);
Globals::phyWorld->addRigidBody(mBody[bodyCounter]);
bodyCounter++;

//fourth pillar
Ogre::SceneNode *pillar_node_4 = (Ogre::SceneNode *)building_node->getChild(Ogre::String("pillar_node_"+Ogre::StringConverter::toString(c)));
Ogre::Entity *pillar_entity_4 = m_SceneManager->getEntity(Ogre::String("pillar_entity_"+Ogre::StringConverter::toString(c)));
c++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter5(pillar_entity_4);
mPillarShape = converter5.createConvex();
//Calculate inertia.
mPillarShape->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
mPillarState = new BtOgre::RigidBodyState(pillar_node_4,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pos+pillar_node_4->getPosition())));
//Create the Body.
mBody[bodyCounter] = new btRigidBody(mass, mPillarState, mPillarShape, inertia);
Globals::phyWorld->addRigidBody(mBody[bodyCounter]);
bodyCounter++;

//slab
Ogre::SceneNode *slab_node = (Ogre::SceneNode *)building_node->getChild(Ogre::String("slab_node_"+Ogre::StringConverter::toString(c)));
Ogre::Entity *slab_entity = m_SceneManager->getEntity(Ogre::String("slab_entity_"+Ogre::StringConverter::toString(c)));
c++;

//Create shape.
BtOgre::StaticMeshToShapeConverter converter(slab_entity);
mSlabShape = converter.createConvex();
//Calculate inertia.
btScalar mass1 = 10;
btVector3 inertia1;
mSlabShape->calculateLocalInertia(mass1, inertia1);
//Create BtOgre MotionState (connects Ogre and Bullet).
BtOgre::RigidBodyState* mSlabState = new BtOgre::RigidBodyState(slab_node,btTransform(btQuaternion(0,0,0,1),BtOgre::Convert::toBullet(pos+slab_node->getPosition())));
//Create the Body.
mBody[bodyCounter] = new btRigidBody(mass, mSlabState, mSlabShape, inertia1);
Globals::phyWorld->addRigidBody(mBody[bodyCounter]);
bodyCounter++;
}
}