I am using True Axis Physics SDK 1.2.0.3 and vc++ 2008.
1)First create a folder ‘Physics’ in solution Explorer in vc++ and copy all the cpp (only cpp) files from \TA\TA\Physics.
2) create a folder ‘Common’ as above and copy all cpp file from \TA\TA\Common
3) Go to Tools->options->vc++ directories in include files select \TA\TA\Physics and \TA\TA\Common
4) Add your source and header file as u need.
I add 2 examples 1st example is a basic rotation,2nd one is a ration with matrix so that we can get 100% perfect rotation and collision and also it can hold more no. of boxes
// You can download all needed files at http://groups.google.com/group/mur_games
Code: Select all
#include<CollisionObjectAABBMesh.h>
#include<Physics.h>
#include<DynamicObject.h>
#include<StaticObject.h>
using namespace TA;
#include<Irrlicht.h>
#pragma comment(lib,"Irrlicht.lib")
using namespace irr;
void main()
{
//Irrlicht Initialization.
IrrlichtDevice *device=createDevice(video::EDT_DIRECT3D9,core::dimension2d<irr::s32>(800,640),16);
video::IVideoDriver *driver=device->getVideoDriver();
scene::ISceneManager *smgr=device->getSceneManager();
gui::IGUIEnvironment *guienv=device->getGUIEnvironment();
//loading max created 3ds mesh file from local disk
scene::IAnimatedMesh *planemesh=smgr->getMesh("G:/GameCoder/irrlicht-1.3.1/media/plane1.3ds");
scene::ISceneNode *node=smgr->addAnimatedMeshSceneNode(planemesh);
node->setMaterialTexture(0,driver->getTexture("G:/GameCoder/irrlicht-1.3.1/media/stones.jpg"));
node->setMaterialType(video::EMT_LIGHTMAP);
node->setMaterialFlag(video::EMF_LIGHTING,false);
//adding to TA::physics
core::aabbox3df abbox=planemesh->getBoundingBox();
AABB aabb;
aabb.Initialise(Vec3(abbox.getCenter().X,abbox.getCenter().Y,abbox.getCenter().Z),
Vec3(abbox.getExtent().X,abbox.getExtent().Y,abbox.getExtent().Z));
Physics::CreateInstance(aabb);
Physics& physics = TA::Physics::GetInstance();
//creating static object and collision object
StaticObject *pStaticObject=StaticObject::CreateNew();
TA::CollisionObjectAABBMesh *pStaticCollisionObject=TA::CollisionObjectAABBMesh::CreateNew();
//Add polygon mesh into collision object by vertices and indices
scene::IMeshBuffer *mb;
int i;
for(i=0;i<(int)planemesh->getMesh(0)->getMeshBufferCount();i++)
{
mb=(scene::IMeshBuffer*)planemesh->getMesh(0)->getMeshBuffer(i);
}
//initialise to collision object
pStaticCollisionObject->Initialise(
mb->getVertexCount(),
mb->getIndexCount()/3,
mb->getIndexCount());
//add vertex
video::S3DVertex *mb_vertices=(irr::video::S3DVertex*)mb->getVertices();
for(i=0;i<(int)mb->getVertexCount();i++)
{
pStaticCollisionObject->AddVertex(Vec3(mb_vertices[i].Pos.X,mb_vertices[i].Pos.Y,mb_vertices[i].Pos.Z));
}
//add polygon
irr::u16 *mb_indices=mb->getIndices();
int polygonList[3];
for(i=0;i<(int)mb->getIndexCount();i+=3)
{
polygonList[0]=mb_indices[i+2];
polygonList[1]=mb_indices[i+1];
polygonList[2]=mb_indices[i];
pStaticCollisionObject->AddPolygon(3,polygonList);
}
pStaticCollisionObject->FinishedAddingGeometry();
//release collision object
pStaticObject->Initialise(pStaticCollisionObject);
pStaticCollisionObject->Release();
//release static object
physics.AddStaticObject(pStaticObject);
pStaticObject->Release();
//create dynamic object
TA::DynamicObject *pDynamicObject=TA::DynamicObject::CreateNew();
aabb.Initialise(TA::Vec3(0.0f, 0.0f, 0.0f),TA::Vec3(5.0f,5.0f, 5.0f));
pDynamicObject->InitialiseAsABox(aabb);
pDynamicObject->SetPosition(TA::Vec3(100.0f, 100.0f, 0.0f));
// these are optionals
pDynamicObject->SetMass(5.0f);
pDynamicObject->SetRestitution(0.5f);
pDynamicObject->SetLinearVelocity(Vec3(0.0f,-10.0f,0.0f));
pDynamicObject->SetAngularVelocity(Vec3(8.5f,2.5f,2.5f));
// these are optionals
physics.AddDynamicObject(pDynamicObject);
//create a irrlicht cube and add it to a node
scene::ISceneNode *node1= smgr->addCubeSceneNode(5.0f);
node1->setPosition(core::vector3df(100,100,0));
node1->setMaterialTexture(0,driver->getTexture("G:/GameCoder/irrlicht-1.3.1/media/wood.jpg"));
node1->setMaterialFlag(video::EMF_LIGHTING,false);
//create a camera
scene::ICameraSceneNode *cam=smgr->addCameraSceneNodeMaya();
device->getCursorControl()->setVisible(false);
cam->setPosition(core::vector3df(0,80,50));
TA::Vec3 pos=pDynamicObject->GetPosition();
cam->setTarget(core::vector3df(pos.x,pos.y-20,pos.z));
float fDt = 1.0f/60.0f;
core::matrix4 matrix;
//main Loop
while(device->run())
{
driver->beginScene(true,true,video::SColor(0,255,255,255));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
physics.Update(fDt);//update TA
TA::MFrame frame=pDynamicObject->GetFrame();
TA::Mat33 rot=frame.m33Rotation;
//matrix rotation
matrix.setRotationRadians(core::vector3df(TA::EulerAngles(rot).x,TA::EulerAngles(rot).y,TA::EulerAngles(rot).z));
node1->setRotation(matrix.getRotationDegrees());
node1->setPosition(core::vector3df(frame.v3Translation.x,frame.v3Translation.y,frame.v3Translation.z));
//to camera target u can remove if want
TA::Vec3 pos=pDynamicObject->GetPosition();
cam->setTarget(core::vector3df(pos.x,pos.y-20,pos.z));
}
Physics::DestroyInstance();
driver->drop();
}