Using Irrlicht and Bullet I'm developing a toolkit that I hope will allow novice programmers to use Irrlicht and Bullet together in a simple way
basically to load a static mesh for physics objects to collide / rest on you do
StaticMesh *sm=new StaticMesh("terrenuco2.tga",terrmesh,0,10,0);
and for a moving physics cylinder...
m=new Movable ("media/t351sml.jpg",MOV_CYL,massval);
I'm working on replacing stuff like
(scene::SMesh*)smgr->getMesh("media/testterrain/ter2.obj")->getMesh(0)
with
terrmesh=toolkit->loadMesh("media/testterrain/ter2.obj")
with as little nesting as possible
obviously some of the flexibility of Irrlicht will be lost nut this is for novices and wants to be as simple as possible!
As yet there is no public release, but if you are interested in helping out please contact chris_camacho on yahoo mail
this image shows static and moving concave mesh's with primitive objects...
hobby physic toolkit
its still early days but heres an example of use
I have addContacts callback working and I'm currently working on a scheme to allow curtom friction/restitution per object / object interaction
Comments and help most welcome
I have addContacts callback working and I'm currently working on a scheme to allow curtom friction/restitution per object / object interaction
Comments and help most welcome
Code: Select all
#include "main.h"
#define MaxEnts 40
extern int QuitFlag;
World *myWorld;
MeshData *torusdata;
int main()
{
myWorld=new World();
myWorld->setGravity(0,-9.8,0);
// load an irrlicht mesh torusmesh is a pointer to it
scene::SMesh *torusmesh=myWorld->getIrrMesh("media/torus.b3d");
// the world object contains global utilities like a simplified
// way to scale the mesh
myWorld->scaleIrrMesh(torusmesh,.25,.25,.25);
// torusdata is a pointer to mesh data that the physics library can use for
// collision data
torusdata=new MeshData(torusmesh);
MeshData *terrainData=new MeshData(myWorld->getIrrMesh("media/ter2.obj"));
// a mass of zero means a static mesh
Entity *terrain=new Entity(0,terrainData,0);
terrain->setPosition(0,8,0);
terrain->setText("terrain");
// TODO replace with camera linked to a upright constrained physics capsule driven with the mouse
// add creation routine to world object
scene::ISceneNode *camnode=myWorld->smgr->addCameraSceneNodeFPS(0,100,10);
camnode->setPosition( core::vector3df(0,32.00,0));
// TODO add a world object routine to add lights to the world
scene::ISceneNode *lightnode = myWorld->smgr->addLightSceneNode(0, core::vector3df(10,60,10),video::SColorf(1.0f, 1.0f, 1.f, 1.0f), 100.0f);
printf("entering main loop\n");
int nextadd=0;
int numEnts=0;
srand(time(0));
while( !QuitFlag) {
if (numEnts<MaxEnts) nextadd++;
if (nextadd>60) {
// every 60 frames add a new mesh
chooseNewObject();
numEnts++;
nextadd=0;
}
// update physics and visual objects
myWorld->update();
}
return 0;
}
void chooseNewObject() {
float height=11;
// first find the height of the heighest entity in the world
// an EntityIterator allows us to move through the global list of
// all the entities in the world
EntityIterator i;
for( i=myWorld->firstEntity(); i!=myWorld->lastEntity(); i++) {
Entity* Ent=(*i);
// entity->getPosition returns a btVector3 (3 float values
// we get its Y component by calling its getY() method
float y=Ent->getPosition().getY();
if ((y+1.5)>height) height=y+2;
}
Entity *m;
// choose a random size and an approximate mass
float ssx,ssy,ssz,massval;
ssx=float(rand())/(RAND_MAX)+0.5;
ssy=float(rand())/(RAND_MAX)+0.5;
ssz=float(rand())/(RAND_MAX)+0.5;
massval=sqrt((ssx*ssx)+(ssy*ssy)+(ssz*ssz))*2;
int r=rand()%70+1;
// randomly select 1 of 4 entity types
if (r<21) {
int r2=rand()%2+1;
// you can override the texture of the irrlicht mesh
// E_BOX is the shape type
if (r2==1) m=new Entity ("media/t351sml.jpg",E_BOX,massval);
if (r2==2) m=new Entity ("media/wcrate.jpg",E_BOX,massval);
m->setText("box");
}
if (r>20 && r<41) {
int r2=rand()%2+1;
if (r2==1) m=new Entity ("media/wcrate.jpg",E_SPHERE,massval);
if (r2==2) m=new Entity ("media/planet.jpg",E_SPHERE,massval);
m->setText("sphere");
}
if (r>40 && r<61) {
// specifying 0 for the override texture uses the mesh's texture
m=new Entity (0,E_CYLINDER,massval);
m->setText("box");
}
if (r>60 && r<71) {
// specifying mesh collision data (MeshData object) for entity type
// gives a static or moving physics trimesh
m=new Entity (0,torusdata,massval);
m->setText("torus mesh");
}
float x=(float(rand())/(RAND_MAX/32.f))-16.f;
float z=(float(rand())/(RAND_MAX/32.f))-16.f;
m->setPosition(x,height,z);
m->setScale(ssx,ssy,ssz);
}
Hm, interesting... Do you also want to create a physix editor
or is this lib (you are working on) that what you mean by toolkit?
Because I thought about making physix editor earlier...
But its too much work for a person doing both lib and editor...
PS: Are there actually slider joints in Bullet?
What does Bullet make so specially?
or is this lib (you are working on) that what you mean by toolkit?
Because I thought about making physix editor earlier...
But its too much work for a person doing both lib and editor...
PS: Are there actually slider joints in Bullet?
What does Bullet make so specially?
My Irrlicht&ODE-Project: http://www.lofing.de/myworld/
Bullet can do nice things like moving concave mesh (ode's build system is still problematic)
basically its a toolkit that allows you to compile code like above, it simplifies using irrlicht and bullet intergrating them into one set of easy to use classes
At some point it might be useful to have an editor for building compound physics shapes round meshes
basically its a toolkit that allows you to compile code like above, it simplifies using irrlicht and bullet intergrating them into one set of easy to use classes
At some point it might be useful to have an editor for building compound physics shapes round meshes