Ok, now i will not sleep for 10 days !...serengeor wrote:Well, I have my own version of this wrapper (...) I have soft body ropes implemented


Ok, now i will not sleep for 10 days !...serengeor wrote:Well, I have my own version of this wrapper (...) I have soft body ropes implemented
Hm, my implementation is not ideal, I had to hack it a bit to get it to work (because of a way my wrapper works).jorgerosa wrote:Ok, now i will not sleep for 10 days !...serengeor wrote:Well, I have my own version of this wrapper (...) I have soft body ropes implementedunless... you share it, with us!
Code: Select all
// Irrlicht stuff: #include "irrlicht.h" // Declare Used Namespaces: using namespace irr; using namespace core; using namespace video; using namespace scene; using namespace io; using namespace gui; // Bullet stuff: #include "btBulletCollisionCommon.h" #include "btBulletDynamicsCommon.h" btDiscreteDynamicsWorld *bWorld; ....... ....... ....... int main(int argc, char** argv){ ....... ....... ....... /// Adding Static nodes: scene::IMeshSceneNode* nodeA = smgr->addMeshSceneNode(smgr->getMesh("floor.obj")); scene::IMeshSceneNode* nodeB = smgr->addMeshSceneNode(smgr->getMesh("buildings1.obj")); scene::IMeshSceneNode* nodeC = smgr->addMeshSceneNode(smgr->getMesh("buildings2.obj")); scene::IMeshSceneNode* nodeD = smgr->addMeshSceneNode(smgr->getMesh("rocks.obj")); scene::IMeshSceneNode* nodeE = smgr->addMeshSceneNode(smgr->getMesh("trees.obj")); /// Adding Dynamic nodes: // IAnimatedMeshSceneNode: scene::IAnimatedMeshSceneNode* nodeF = smgr->addAnimatedMeshSceneNode(smgr->getMesh("bus_01.md3")); /// MD3 !!! // IMeshSceneNode: scene::IMeshSceneNode* nodeG = smgr->addMeshSceneNode(smgr->getMesh("bus_02.obj")); // Animator: scene::ISceneNodeAnimator* run = 0; run = smgr->createFlyCircleAnimator(core::vector3df(0,0,0),30.0f,0.00041f); nodeG->addAnimator(run); run->drop(); ....... ....... ....... /// ############################################################################################ /// /// BULLET PHYSICS WORLD: /// /// ############################################################################################ /// Bullet: Creating Main Physics World: btDbvtBroadphase* broadphase = new btDbvtBroadphase(); btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver(); bWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); /// Dynamic world creation bWorld->setGravity(btVector3(0,-9.80665,0)); // Set world gravity /// "CONVERTING" IRRLICHT NODES TO BULLET: "ALL IN ONE CODE" (Sort of...) btTriangleIndexVertexArray* staticVertexArray = new btTriangleIndexVertexArray(); core::array<scene::ISceneNode*> myNodes; /// I want to "add" these nodes to bullet physics world, ok computer? So... just do it! You little #$%$#$%&# ! :evil: myNodes.push_back(nodeA); /// Added Node: Floor myNodes.push_back(nodeB); /// Added Node: Buildings 1 myNodes.push_back(nodeC); /// Added Node: Buildings 2 myNodes.push_back(nodeD); /// Added Node: Rocks myNodes.push_back(nodeE); /// Added Node: Trees myNodes.push_back(nodeF); /// Added Node: Bus 1 (ANIMATED NODE) myNodes.push_back(nodeG); /// Added Node: Bus 2 (ANIMATED NODE) /// ############################################################################################ /// /// "ISSUE": /// All nodes are added, including the animated nodeF and nodeG, to the Bullet physics world, /// but their physics dont follow their nodes animations (positions/movements/...) /// /// ############################################################################################ /// LOOP: for(u32 N=0; N<myNodes.size(); ++N){ IMesh *mesh = NULL; // Get irrlicht node type: switch(myNodes[N]->getType()){ case scene::ESNT_ANIMATED_MESH: mesh = ((scene::IAnimatedMeshSceneNode*)myNodes[N])->getMesh(); break; default: mesh = ((scene::IMeshSceneNode*)myNodes[N])->getMesh(); break; } // Extract index and vertex data from the irrLicht mesh: const u32 cnt = mesh->getMeshBufferCount(); for(u32 i=0; i<cnt; ++i){ IMeshBuffer* buf = NULL; buf = mesh->getMeshBuffer(i); s32 idxCnt = buf->getIndexCount(); s32 vertexCnt = buf->getVertexCount(); f32* vtx3 = new f32[vertexCnt*3]; matrix4 mat; mat *= myNodes[N]->getAbsoluteTransformation(); switch(buf->getVertexType()){ case video::EVT_STANDARD: { video::S3DVertex* vtx = (video::S3DVertex*)buf->getVertices(); for(s32 j=0; j<vertexCnt; ++j){ vector3df pos = vtx[j].Pos; mat.transformVect(pos); vtx3[j*3+0] = pos.X; vtx3[j*3+1] = pos.Y; vtx3[j*3+2] = pos.Z; }} break; case video::EVT_2TCOORDS: { video::S3DVertex2TCoords* vtx = (video::S3DVertex2TCoords*)buf->getVertices(); for(s32 j=0; j<vertexCnt; ++j){ vector3df pos = vtx[j].Pos; mat.transformVect(pos); vtx3[j*3+0] = pos.X; vtx3[j*3+1] = pos.Y; vtx3[j*3+2] = pos.Z; }} break; case video::EVT_TANGENTS: { video::S3DVertexTangents* vtx = (video::S3DVertexTangents*)buf->getVertices(); for(s32 j=0; j<vertexCnt; ++j){ vector3df pos = vtx[j].Pos; mat.transformVect(pos); vtx3[j*3+0] = pos.X; vtx3[j*3+1] = pos.Y; vtx3[j*3+2] = pos.Z; }} break; } // Convert irrLicht's 'unsigned short' array of indices to an array of 'unsigned int's that bullet can use: u16* bufIndices = buf->getIndices(); u32* u32bufIndices = new u32[idxCnt]; for(s32 i=0; i<idxCnt; ++i){ u32bufIndices[i] = bufIndices[i]; } btIndexedMesh bMesh; bMesh.m_numTriangles = idxCnt / 3; bMesh.m_triangleIndexBase = (const unsigned char *) u32bufIndices; bMesh.m_triangleIndexStride = 3*sizeof(u32); bMesh.m_numVertices = vertexCnt; bMesh.m_vertexBase = (const unsigned char *)vtx3; bMesh.m_vertexStride = 3*sizeof(f32); staticVertexArray->addIndexedMesh(bMesh); } } /// Bullet: Add to the physics world: btCollisionShape* shapev = new btBvhTriangleMeshShape(staticVertexArray, false); btRigidBody* rigidBodyv = new btRigidBody(0, new btDefaultMotionState(), shapev, btVector3(0,0,0)); bWorld->addRigidBody(rigidBodyv); while(device->run()){ ....... ....... ....... /// Update physics: bWorld->stepSimulation(frameDeltaTime, 1); ....... ....... ....... } }
Thanks for share it, serengeor. I´ll try it as soon as i get home.serengeor wrote:Here's the wrapper I talked about earlier if it misses any features that you think should be in the wrapper please tell me. I'd be happy to update it because I use it myselfPS. it contains linux debug executable with sample on how to use it, though not all features are used.
serengeor wrote:Here's the wrapper I talked about earlier if it misses any features that you think should be in the wrapper please tell me. I'd be happy to update it because I use it myselfIrrBulletWrapper.tar.gz - 6.8 Mb
PS. it contains linux debug executable with sample on how to use it, though not all features are used.
I thought so, but I didn't have really that time to think of a good name for it. It doesn't really have any name in my framework.cobra wrote:serengeor wrote:Here's the wrapper I talked about earlier if it misses any features that you think should be in the wrapper please tell me. I'd be happy to update it because I use it myselfIrrBulletWrapper.tar.gz - 6.8 Mb
PS. it contains linux debug executable with sample on how to use it, though not all features are used.
Hi Serengeor,
Please note for others that this is not the original irrBullet that I developed. The name can be misleading to people who don't know.
Thanks.