Bullet + irrlicht + GtkRadiant

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
easy163
Posts: 24
Joined: Wed Jul 10, 2013 12:50 pm

Bullet + irrlicht + GtkRadiant

Post by easy163 »

Made a map of the GtkRadiant, downloaded in irrlicht, overdose on top, added loaded map hardness. Uploaded the model of the cube and decided to test a collision with a map of the bsp, the fact is that the cube is dropped into the room created in GtkRadiant as if there is an invisible wall. Also tried with balls. What to do? Put the right pieces of code.

Image

Image

Load the map and call a function with collision

Code: Select all

 
device->getFileSystem()->addFileArchive("media/map/map.pk3");
IAnimatedMesh* mesh = smgr->getMesh("map.bsp");
IMeshSceneNode* node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
cCreate_SS_obj (btVector3(0, 0, 0), mesh, node, vector3df(1));
 
The function of creating a solid object

Code: Select all

 
void cCreate_SS_obj (const btVector3 &TPosition, IAnimatedMesh* mesh, IMeshSceneNode* node, const vector3df &scale)
{
    btScalar mass = 0;
    node->setScale(scale);
    node->setMaterialType(EMT_SOLID);
    node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
    btTransform Transform;
    Transform.setIdentity();
    Transform.setOrigin(TPosition);
    btDefaultMotionState* MotionState = new btDefaultMotionState(Transform);
    btTriangleMesh* triagle = retVertex(mesh->getMesh(0), node);
    btConvexShape* hull = new btConvexTriangleMeshShape(triagle);
    hull->setUserPointer(hull);
    btVector3 localInertia(0, 0, 0);
    hull->calculateLocalInertia(mass, localInertia);
    btRigidBody* RigidBody = new btRigidBody(mass, MotionState, hull, localInertia);
    RigidBody->setFriction(0);
    RigidBody->setUserPointer((void *)(node));
    RigidBody->setActivationState(DISABLE_DEACTIVATION);
    World->addRigidBody(RigidBody);
    Objects.push_back(RigidBody);
}
 
Function busting peaks card, called from function cCreate_SS_obj

Code: Select all

 
btTriangleMesh* retVertex (IMesh* const mesh, IMeshSceneNode* const node)
{
    btVector3 vertices[3];
    u32 i, j, k;
    s32 index, numVertices;
    u16* mb_indices;
    const vector3df &scale = node->getScale();
 
    btTriangleMesh *pTriMesh = new btTriangleMesh();
 
    for(i = 0; i < mesh->getMeshBufferCount(); i++)
    {
        irr::scene::IMeshBuffer* mb=mesh->getMeshBuffer(i);
 
        //////////////////////////////////////////////////////////////////////////
        // Extract vertex data                                                  //
        // Because the vertices are stored as structs with no common base class,//
        // We need to handle each type separately                               //
        //////////////////////////////////////////////////////////////////////////
        if(mb->getVertexType() == irr::video::EVT_STANDARD)
        {
            irr::video::S3DVertex* mb_vertices=(irr::video::S3DVertex*)mb->getVertices();
            mb_indices = mb->getIndices();
            numVertices = mb->getVertexCount();
            for(j=0;j<mb->getIndexCount();j+=3)
            { //get index into vertex list
                for (k=0;k<3;k++)
                {
                    //three verts per triangle
                    index = mb_indices[j+k];
                    if (index > numVertices) continue;
                    //convert to btVector3
                    vertices[k] = IrrToBull(mb_vertices[index].Pos * scale); // 1100
                }
                pTriMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
            }
 
        }
        else
        if(mb->getVertexType()==irr::video::EVT_2TCOORDS)
        {
            // Same but for S3DVertex2TCoords data
            irr::video::S3DVertex2TCoords* mb_vertices=(irr::video::S3DVertex2TCoords*)mb->getVertices();
            u16* mb_indices = mb->getIndices();
            s32 numVertices = mb->getVertexCount();
            for(j=0;j<mb->getIndexCount();j+=3)
            { //index into irrlicht data
                for (k=0;k<3;k++)
                {
                    s32 index = mb_indices[j+k];
                    if (index > numVertices) continue;
                    vertices[k] = IrrToBull(mb_vertices[index].Pos * scale);
                }
                pTriMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
            }
        }
 
        // Does not handle the EVT_TANGENTS type
    }
 
    return pTriMesh;
}
 
Function convert vectors

Code: Select all

 
inline static btVector3 IrrToBull(const irr::core::vector3df & toConvert)
{
    return btVector3(toConvert.X,toConvert.Y,toConvert.Z);
}
 
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Bullet + irrlicht + GtkRadiant

Post by hendu »

You asked for that behavior :)

By requesting a Convex triangle mesh, it created an enclosing mesh for your BSP. You want a BVH triangle mesh, not a convex one.
easy163
Posts: 24
Joined: Wed Jul 10, 2013 12:50 pm

Re: Bullet + irrlicht + GtkRadiant

Post by easy163 »

How to do this? :(
MrGuy
Posts: 18
Joined: Mon Oct 29, 2012 11:05 pm

Re: Bullet + irrlicht + GtkRadiant

Post by MrGuy »

btConvexShape* hull = new btConvexTriangleMeshShape(triagle);

Change that line to use a BVH, not a ConvexShape.
easy163
Posts: 24
Joined: Wed Jul 10, 2013 12:50 pm

Re: Bullet + irrlicht + GtkRadiant

Post by easy163 »

I understood it, but I don't understand how to write correctly. I write btBvhTriangleMeshShape* hull = new btBvhTriangleMeshShape(triagle); Can please write how to write this line
easy163
Posts: 24
Joined: Wed Jul 10, 2013 12:50 pm

Re: Bullet + irrlicht + GtkRadiant

Post by easy163 »

I figured out, post code, thank you :)

Code: Select all

 
btScalar mass = 0;
node->setScale(scale);
node->setMaterialType(EMT_SOLID);
node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
btTransform Transform;
Transform.setIdentity();
Transform.setOrigin(TPosition);
btDefaultMotionState* MotionState = new btDefaultMotionState(Transform);
btTriangleMesh* triagle = retVertex(mesh->getMesh(0), node);
btConcaveShape* hull = new btBvhTriangleMeshShape(triagle, true);
hull->setUserPointer(hull);
btVector3 localInertia(0, 0, 0);
hull->calculateLocalInertia(mass, localInertia);
btRigidBody* RigidBody = new btRigidBody(mass, MotionState, hull, localInertia);
RigidBody->setFriction(0);
RigidBody->setUserPointer((void *)(node));
RigidBody->setActivationState(DISABLE_DEACTIVATION);
World->addRigidBody(RigidBody);
Objects.push_back(RigidBody);
 
Post Reply