irrBullet 0.1.8 - Bullet physics wrapper

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
opticdrive
Posts: 7
Joined: Sun Jul 01, 2012 5:27 am

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by opticdrive »

Hey cool software so far. I'm confused about the install though. I am running on linux, and trying to make irrbullet 0.18 I get this:

Code: Select all

$ make
make: Circular ../source/collisionobjectaffector.cpp <- ../source/collisionobjectaffector.cpp dependency dropped.
make: Circular ../source/trianglemeshshape.cpp <- ../source/trianglemeshshape.cpp dependency dropped.
make: *** No rule to make target `Bullet/btBulletDynamicsCommon.h', needed by `../source/trianglemeshshape.cpp'.  Stop.
me@computer:~/Desktop/irrbullet/irrBulletSDK-0.1.8/build$ sudo make install
NO ERRORS, READY FOR (DE)INSTALLATION! :)
# docs
mkdir -p /usr/share/doc/packages/irrBullet
cp -R ../examples /usr/share/doc/packages/irrBullet
cp -R ../doc /usr/share/doc/packages/irrBullet
cp -R ../media /usr/share/doc/packages/irrBullet
cp -R ../*.txt /usr/share/doc/packages/irrBullet
# lib
cp ../lib/linux/Release/libirrBullet.so /usr/local/lib/
cp: cannot stat `../lib/linux/Release/libirrBullet.so': No such file or directory
make: *** [install_extern] Error 1
THanks!
Oster200
Posts: 60
Joined: Sun May 06, 2012 6:13 pm

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by Oster200 »

I am also having problems on how to install but i am on windows. http://irrlicht.sourceforge.net/forum/v ... =1&t=46813 That is the post i did on irrlicht forums.
Nash94
Posts: 20
Joined: Fri Aug 31, 2012 3:21 pm

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by Nash94 »

Hmm seem to be having issues running this.. So i installed the setup, then loaded up the VS2010 solution in the src, I ended up having linking errors straight away.. it seems that the linked directory did not even exist. "C:\Programming\Library" << this one so i created it myself copied irrlicht and irrbullet into it respective of the linked names and updated all the existing links.. so now there are no errors in the code, however i still cannot run anything when i click run i get...
"Unable to start program irrBullet.lib The specificed file is an unrecognized or unsupported binary format" I am totally clueless at this point
Soranne
Posts: 7
Joined: Thu Sep 30, 2010 10:17 am

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by Soranne »

Hello all,

I am encountering some problems building an irrbullet project, and I have been advised to rebuild bullet and irrbullet. Unfortunately I don't have Visual Studio or CB, I am only using g++ through batch files and command lines.
So my question is how to build the .a files for windows using g++?

Thank you very much.
Regards.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by serengeor »

Soranne wrote: So my question is how to build the .a files for windows using g++?
And don't you think that's a bit offtopic here to ask questions about the compiler :roll:
I'm sure there are hundreds of articles online how to do this.
Working on game: Marrbles (Currently stopped).
Soranne
Posts: 7
Joined: Thu Sep 30, 2010 10:17 am

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by Soranne »

I am sorry if it is off topic, but I thought it was linked with irrbullet : the given libraries don't work for me. So I would like to know if anyone has a windows "makefile" as I don't have VS or CB.

I have one more question, where are your lib files when you install irrBullet? Because I don't have the right to install on my computer, so i used the 7z file. It seems like there are absolute paths things in irrBullet causing trouble.

Regards.
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by kklouzal »

Irrlicht recently released 1.8; I notice the IrrBullet source directory only goes up to vs2010 and still uses irrlicht 1.7; When do you plan on updating the project to include vs2012 and irrlicht 1.8? I am very excited to start working with your bullet physics wrapper for irrlicht!

Direct Link to Download & Install VS2012 Express---->http://go.microsoft.com/?linkid=9816758
Dream Big Or Go Home.
Help Me Help You.
jorgerosa
Competition winner
Posts: 117
Joined: Wed Jun 30, 2010 8:44 am
Location: Portugal
Contact:

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by jorgerosa »

• I´ve updated everything in my PC (Win 7) MinGW (with GCC 4.7.2) + Code::Blocks SVN 8549 + Irrlicht 1.8 + Bullet Physics v.2.81 AND irrBullet 0.1.8, of course. (All the very lattest software and libraries versions)

• After a while (lots of compilations, coffees, and big fights with my PC) all works great... finally... except irrBullet. (starting at "static_cast" issues, etc, etc...) I have no skills to workaround this, or even help others... Every time I try, I mess even more the wrapper... (The cause seems to be the changes to the new release series GCC 4.7, different "binaries approach" (completly incompatible with GCC 4.6 series)) Can someone update irrBullet wrapper? THANKS! :)

(I tried also with Ogre3D 1.8.1 + OgreBullet + Bullet Physics, results are even worst, since Ogre3D 1.8.1 and OgreBullet were compiled with GCC 4.6 series. Devs are working on that issues for the new Ogre3D version... But still, no news about on an OgreBullet update...
So, at least at Irrlicht everything is updated (compiled with GCC 4.7 series), except irrBullet wrapper)


EDIT: Found the issues... and the solution: (Im using Code::Blocks)
http://irrlicht.sourceforge.net/forum/v ... 65#p275065
jorgerosa
Competition winner
Posts: 117
Joined: Wed Jun 30, 2010 8:44 am
Location: Portugal
Contact:

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by jorgerosa »

(To answer some requests about my vehicle project physics)
Some real code about how to apply physics to a vehicle + wheels + trailer (with joints, constrains, etc, etc) like the one, in the video:

Image
DEMO VIDEO: http://www.youtube.com/watch?v=4rUGhlNCNho
Demo Code Example: http://sites.google.com/site/jorgerosap ... hysics.cpp

IMPORTANT:
You may have a previous 3D models for: a truck body, a trailer body, a wheel (cloned 6 times), all must have joints.
You have to fit the models to the next code, and fit the code to you case too, and pay attention to joints names too (so all could work in the right way).


CODE:
  •  


    // MISSING CODE HERE (headers, variables, irrlicht stuff.......)
    // Irrlicht + IrrBullet = Vehicle + Wheels + Trailer (joints) etc... - By Jorge Rosa - http://sites.google.com/site/jorgerosaportfolio
     
    // Irrbullet stuff:
    enum ECollisionGroupTypes{
    COL_NOTHING = 0, // <-- Collide with nothing
    COL_TERRAIN = BIT(1),
    COL_WORLD_OBJECT = BIT(2),
    COL_VEHICLE = BIT(3)
    };
     
    int objectCollidesWith = COL_VEHICLE | COL_TERRAIN | COL_WORLD_OBJECT;
    int vehicleRaycastCollidesWith = COL_TERRAIN | COL_WORLD_OBJECT;
    int terrainCollidesWith = COL_VEHICLE | COL_WORLD_OBJECT;
     
    // Define Some Irrlicht Global Variables:
    IrrlichtDevice *device = 0; // Create Device
    video::IVideoDriver* driver  = 0; // Create Driver
    scene::ISceneManager* smgr   = 0; // Create Scene Manager
     
     
     
     
     
     
     
    int main(int argc, char** argv){
     
        // MISSING CODE HERE (normal irrlicht stuff.......)
     
        // INITIALIZE PHYSICS WORLD:
        irrBulletWorld* world = createIrrBulletWorld(device, true, true); //  irr::IrrlichtDevice *const Device, bool useGImpact, bool useDebugDrawer
        world->setDebugMode(EPDM_DrawAabb | EPDM_DrawContactPoints);
        world->setGravity(vector3df(0, -10, 0));
        world->registerGImpactAlgorithm();
     
        f32 sm  = 0.02;    // setMargin road only (base)
        f32 smo = 0.02;    // setMargin to all other objects
        f32 sr  = 0.01;    // setRestitution
        vector3df globalScaling = vector3df(1.0,1.0,1.0);
     
        // NODE -> TERRAIN:
        // add terrain scene node
        scene::ITerrainSceneNode* terrainNode = smgr->addTerrainSceneNode(
            "terrain_heightmap.png",                  // data: heightmap (256x256)
            0,                                        // parent node
            -1,                                       // node id
            core::vector3df(-233.f, -17.0f, -8.0f),   // position
            core::vector3df(0.0f, 0.0f, 0.0f),        // rotation
            core::vector3df(1.0f, 0.1f, 2.0f),        // scale
            video::SColor(255, 255, 255, 255 ),       // vertexColor
            10,                                       // maxLOD (simplify distant meshes)
            scene::ETPS_17,                           // patchSize (9,17,33,65)
            0                                         // smoothFactor
            );
     
        // MISSING CODE HERE (.......)
     
        // Add to physics world:
        scene::CDynamicMeshBuffer meshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT);
        terrainNode->getMeshBufferForLOD(meshBuffer, 0);
        scene::SMesh terraMesh;
        terraMesh.addMeshBuffer(&meshBuffer);
        ICollisionShape* terraShape = new IBvhTriangleMeshShape(terrainNode, &terraMesh, 0.0); // Create terrain shape
        world->addRigidBody(terraShape);
     

     
        // NODES -> VEHICLE:
        irr::scene::IAnimatedMeshSceneNode* vehicleNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("vehicle_truck.b3d"));
        vehicleNode->setPosition(vector3df(0,0,0));
     
     
        // Create impacts mesh shapes:
        IGImpactMeshShape* vshape = new IGImpactMeshShape(vehicleNode, device->getSceneManager()->getMesh("vehicle_truck_raycast.b3d"), 1000.0);
     
        vshape->setMargin(smo);
     
        IRigidBody* rigidBody = world->addRigidBody(vshape, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        vshape->setLocalScaling(globalScaling, ESP_BOTH);
        rigidBody->setLinearFactor(vector3df(0,1,1));  // Allowed positions axis (y,z)
        rigidBody->setAngularFactor(vector3df(1,0,0)); // Allowed rotations axis (x)
     
        rigidBody->getAttributes()->addBool("vehicle", true);
     
        rigidBody->includeNodeOnRemoval(false);
        // When using a raycast vehicle, we don't want this rigid body to deactivate.
        rigidBody->setActivationState(EAS_DISABLE_DEACTIVATION);
        // rigidBody->setDamping(0.000001,0.000001);
        rigidBody->setFriction(20);  // rigidBody->setFriction(7.0f);
        rigidBody->setRestitution(0); // void bouncy
        // rigidBody->setMassProps(200, vector3df(1,0,0));
        rigidBody->setDamping(0.1,0.1);
        // rigidBody->setGravity(vector3df(0, -30, 0));
     
     
        // NODES -> WHEELS:
        irr::scene::IAnimatedMeshSceneNode* rodaNode[10];
        rodaNode[1] = smgr->addAnimatedMeshSceneNode(smgr->getMesh("wheel_big.b3d"));  // right_front_wheel
        rodaNode[2] = smgr->addAnimatedMeshSceneNode(smgr->getMesh("wheel_big.b3d"));  // left_front_wheel
        rodaNode[3] = smgr->addAnimatedMeshSceneNode(smgr->getMesh("wheel_big.b3d"));  // right_back_wheel01
        rodaNode[4] = smgr->addAnimatedMeshSceneNode(smgr->getMesh("wheel_big.b3d"));  // left_back_wheel01
     
     
     
        f32 wsm   = 0.07;   // setMargin
        f32 wsf   = 10.0;   // setFriction
        f32 dap   = 0.3;    // setDamping -> Set some damping on the rigid body because the raycast vehicles tend to bounce a lot without a lot of tweaking.
        f32 wmass = 800.0;  // mass
     
     
        // IGImpactMeshShape* wShape1 = new IGImpactMeshShape(rodaNode1, device->getSceneManager()->getMesh("wheel_big.b3d"), 50.0); // IConvexHullShape* wShape1 = new IConvexHullShape(rodaNode1, device->getSceneManager()->getMesh("wheel_big.b3d"), 10.0); // IBoxShape* wShape1 = new IBoxShape(rodaNode1, 10.0, true);
        ISphereShape* wShape1 = new ISphereShape(rodaNode[1], wmass, true);
        // wShape1->calculateLocalInertia(wmass, vector3df(1000,1000,1000));
        IRigidBody *wbody1 = world->addRigidBody(wShape1, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        wShape1->setMargin(wsm);
        wbody1->setFriction(wsf);
        wbody1->setDamping(dap,dap);
        wbody1->getAttributes()->addBool("wheel", true);
        // wbody1->setActivationState(EAS_DISABLE_DEACTIVATION);
     
        // IGImpactMeshShape* wShape2 = new IGImpactMeshShape(rodaNode2, device->getSceneManager()->getMesh("wheel_big.b3d"), 50.0); // IConvexHullShape* wShape2 = new IConvexHullShape(rodaNode2, device->getSceneManager()->getMesh("wheel_big.b3d"), 10.0);
        ISphereShape* wShape2 = new ISphereShape(rodaNode[2], wmass, true);
        IRigidBody *wbody2 = world->addRigidBody(wShape2, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        wShape2->setMargin(wsm);
        wbody2->setFriction(wsf);
        wbody2->setDamping(dap,dap);
        wbody2->getAttributes()->addBool("wheel", true);
        // wbody2->setActivationState(EAS_DISABLE_DEACTIVATION);
     
        // IGImpactMeshShape* wShape3 = new IGImpactMeshShape(rodaNode3, device->getSceneManager()->getMesh("wheel_big.b3d"), 50.0); // IConvexHullShape* wShape2 = new IConvexHullShape(rodaNode2, device->getSceneManager()->getMesh("wheel_big.b3d"), 10.0);
        ISphereShape* wShape3 = new ISphereShape(rodaNode[3], wmass, true);
        IRigidBody *wbody3 = world->addRigidBody(wShape3, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        wShape3->setMargin(wsm);
        wbody3->setFriction(wsf);
        wbody3->setDamping(dap,dap);
        wbody3->getAttributes()->addBool("wheel", true);
        // wbody3->setActivationState(EAS_DISABLE_DEACTIVATION);
     
        // IGImpactMeshShape* wShape4 = new IGImpactMeshShape(rodaNode4, device->getSceneManager()->getMesh("wheel_big.b3d"), 50.0); // IConvexHullShape* wShape2 = new IConvexHullShape(rodaNode2, device->getSceneManager()->getMesh("wheel_big.b3d"), 10.0);
        ISphereShape* wShape4 = new ISphereShape(rodaNode[4], wmass, true);
        IRigidBody *wbody4 = world->addRigidBody(wShape4, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        wShape4->setMargin(wsm);
        wbody4->setFriction(wsf);
        wbody4->setDamping(dap,dap);
        wbody4->getAttributes()->addBool("wheel", true);
        // wbody4->setActivationState(EAS_DISABLE_DEACTIVATION);
     
     
     
     
        // FINISHING: Create vehicle
        IRaycastVehicle* vehicle = world->addRaycastVehicle(rigidBody); // Assuming world is pointer to your irrBullet World
        // world->addRaycastVehicle(wbody1); // Assuming world is pointer to your irrBullet World
     
        vehicle->getVehicleRaycaster()->setUseFilter(true);
        vehicle->getVehicleRaycaster()->setCollisionFilterGroup(COL_VEHICLE);
        vehicle->getVehicleRaycaster()->setCollisionFilterMask(vehicleRaycastCollidesWith);
     
     
     
     
     
     
        // WHEELS "attached" to CHASSI, the "secret" is to use "constrains":
     
        btTransform frameInA[10]; // Chassi
        btTransform frameInB[10]; // Tyre
     
        frameInA[0] = btTransform::getIdentity();
        frameInA[0].setOrigin(irrlichtToBulletVector(vehicleNode->getJointNode("01")->getPosition())); // position
        frameInB[0] = btTransform::getIdentity();
        frameInB[0].setOrigin(irrlichtToBulletVector(vector3df(0,0,0))); // rotation
     
        frameInA[1] = btTransform::getIdentity();
        frameInA[1].setOrigin(irrlichtToBulletVector(vehicleNode->getJointNode("02")->getPosition())); // position
        frameInB[1] = btTransform::getIdentity();
        frameInB[1].setOrigin(irrlichtToBulletVector(vector3df(0,0,0))); // rotation
     
        frameInA[2] = btTransform::getIdentity();
        frameInA[2].setOrigin(irrlichtToBulletVector(vehicleNode->getJointNode("03")->getPosition())); // position
        frameInB[2] = btTransform::getIdentity();
        frameInB[2].setOrigin(irrlichtToBulletVector(vector3df(0,0,0))); // rotation
     
        frameInA[3] = btTransform::getIdentity();
        frameInA[3].setOrigin(irrlichtToBulletVector(vehicleNode->getJointNode("04")->getPosition())); // position
        frameInB[3] = btTransform::getIdentity();
        frameInB[3].setOrigin(irrlichtToBulletVector(vector3df(0,0,0))); // rotation
     
        btRigidBody* bodyA = rigidBody->getPointer(); // get chassi --->  parentObject->getRigidBody()->getPointer();
     
        btRigidBody* bodyB[10];
        bodyB[0] = wbody1->getPointer(); // get wheel  --->  obj->getRigidBody()->getPointer();
        bodyB[1] = wbody2->getPointer(); // get wheel  --->  obj->getRigidBody()->getPointer();
        bodyB[2] = wbody3->getPointer(); // get wheel  --->  obj->getRigidBody()->getPointer();
        bodyB[3] = wbody4->getPointer(); // get wheel  --->  obj->getRigidBody()->getPointer();
     
        btGeneric6DofSpringConstraint* C1 = new btGeneric6DofSpringConstraint(*bodyA, *bodyB[0], frameInA[0], frameInB[0], true);
        btGeneric6DofSpringConstraint* C2 = new btGeneric6DofSpringConstraint(*bodyA, *bodyB[1], frameInA[1], frameInB[1], true);
        btGeneric6DofSpringConstraint* C3 = new btGeneric6DofSpringConstraint(*bodyA, *bodyB[2], frameInA[2], frameInB[2], true);
        btGeneric6DofSpringConstraint* C4 = new btGeneric6DofSpringConstraint(*bodyA, *bodyB[3], frameInA[3], frameInB[3], true);
     
        C1->setLinearUpperLimit(irrlichtToBulletVector(vector3df(0, 0.1,0)));    // linearUpperLimit
        C1->setLinearLowerLimit(irrlichtToBulletVector(vector3df(0,-0.1,0)));    // linearLowerLimit
     
        C2->setLinearUpperLimit(irrlichtToBulletVector(vector3df(0, 0.1,0)));    // linearUpperLimit
        C2->setLinearLowerLimit(irrlichtToBulletVector(vector3df(0,-0.1,0)));    // linearLowerLimit
     
        C3->setLinearUpperLimit(irrlichtToBulletVector(vector3df(0, 0.1,0)));    // linearUpperLimit
        C3->setLinearLowerLimit(irrlichtToBulletVector(vector3df(0,-0.1,0)));    // linearLowerLimit
     
        C4->setLinearUpperLimit(irrlichtToBulletVector(vector3df(0, 0.1,0)));    // linearUpperLimit
        C4->setLinearLowerLimit(irrlichtToBulletVector(vector3df(0,-0.1,0)));    // linearLowerLimit
     
        world->getPointer()->addConstraint(C1, true);
        world->getPointer()->addConstraint(C2, true);
        world->getPointer()->addConstraint(C3, true);
        world->getPointer()->addConstraint(C4, true);
     
     
     
     
        // Create wheel 1 - info:
        SWheelInfoConstructionInfo wheel1;
        wheel1.chassisConnectionPointCS = vehicleNode->getJointNode("01")->getPosition();
        wheel1.wheelDirectionCS = irr::core::vector3df(0.0, -0.1, 0.0);
        wheel1.wheelAxleCS = irr::core::vector3df(0.2, 0.0, 0.0);
        wheel1.suspensionRestLength = 0.3;  // 0.30;
        wheel1.wheelRadius = 8;            // wheel (node) radius (10)
        wheel1.isFrontWheel = true;
        vehicle->addWheel(wheel1);          // Add left front wheel
     
        // Create wheel 2 - info:
        SWheelInfoConstructionInfo wheel2;
        wheel2.chassisConnectionPointCS = vehicleNode->getJointNode("02")->getPosition();
        wheel2.wheelDirectionCS = irr::core::vector3df(0.0, -0.1, 0.0);
        wheel2.wheelAxleCS = irr::core::vector3df(-0.2, 0.0, 0.0);
        wheel2.suspensionRestLength = 0.3;  // 0.30;
        wheel2.wheelRadius = 8;            // wheel (node) radius (10)
        wheel2.isFrontWheel = true;
        vehicle->addWheel(wheel2);          // Add left front wheel
     
        // Create wheel 3 - info:
        SWheelInfoConstructionInfo wheel3;
        wheel3.chassisConnectionPointCS = vehicleNode->getJointNode("03")->getPosition();
        wheel3.wheelDirectionCS = irr::core::vector3df(0.0, -0.1, 0.0); // irr::core::vector3df(0.0, -1.0, 0.0);
        wheel3.wheelAxleCS = irr::core::vector3df(0.2, 0.0, 0.0);
        wheel3.suspensionRestLength = 0.3;  // 0.30;
        wheel3.wheelRadius = 8;            // wheel (node) radius (15)
        wheel3.isFrontWheel = false;
        vehicle->addWheel(wheel3);          // Add right back wheel
     
        // Create wheel 4 - info:
        SWheelInfoConstructionInfo wheel4;
        wheel4.chassisConnectionPointCS = vehicleNode->getJointNode("04")->getPosition();
        wheel4.wheelDirectionCS = irr::core::vector3df(0.0, -0.1, 0.0); // irr::core::vector3df(0.0, -1.0, 0.0);
        wheel4.wheelAxleCS = irr::core::vector3df(-0.2, 0.0, 0.0);
        wheel4.suspensionRestLength = 0.3;  // 0.30;
        wheel4.wheelRadius = 8;            // wheel (node) radius (15)
        wheel4.isFrontWheel = false;
        vehicle->addWheel(wheel4);          // Add left back wheel
     
     
     
     
     
        // Tweak wheel info a bit, tweak here more:
        // SRaycastInfo& info = vehicle->getWheelInfo(i);
        // info.contactNormalWS = irr::core::vector3df(-0.1, 0.0, 0.0);
     
        for(irr::u32 i=0; i<vehicle->getNumWheels(); i++){
        SWheelInfo& info = vehicle->getWheelInfo(i);
        info.suspensionStiffness     = 0.06f; // Vibração: tipo mola frente/trás (maior número => mais vibração)
        info.wheelDampingRelaxation  = 0.20f;
        info.wheelDampingCompression = 0.20f;
        info.frictionSlip  = 1000;
        info.rollInfluence = 0.1f; // Fluidez no rolar (colisao entre rigid bodies)
        // info.wheelSuspensionForce = 0.1f;
        // info.engineForce = 100;
        vehicle->updateWheelInfo(i);
        // vehicle->updateWheelTransform(i,true);
        };
     
     
        rigidBody->setVehicleReference(vehicle);
     
        // Set all wheels (nodes) in the right positions:
        rodaNode[1]->setPosition(wheel1.chassisConnectionPointCS);
        rodaNode[2]->setPosition(wheel2.chassisConnectionPointCS);
        rodaNode[3]->setPosition(wheel3.chassisConnectionPointCS);
        rodaNode[4]->setPosition(wheel4.chassisConnectionPointCS);
     
     
     
     
     
     
     
     
     
        // NODES -> TRAILER:
        irr::scene::IAnimatedMeshSceneNode* trailerNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("vehicle_truck_trailer.b3d")); // vehicle_traktor.b3d
        trailerNode->setPosition(vector3df(0,0,0));
     
     
        // Create impacts mesh shapes:
        // IGImpactMeshShape* vshape = new IGImpactMeshShape(emptyNode, trailerNode->getMesh(), 1000.0); // Mass
        IGImpactMeshShape* trshape = new IGImpactMeshShape(trailerNode, device->getSceneManager()->getMesh("vehicle_truck_trailer_raycast.b3d"), 500.0); // vehicle_traktor_raycast.b3d
        trshape->setMargin(smo);
        // trshape->calculateLocalInertia(800, 0);
        IRigidBody* rigidTBody = world->addRigidBody(trshape, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        trshape->setLocalScaling(globalScaling, ESP_BOTH);
        rigidTBody->setLinearFactor(vector3df(0,1,1));  // Allowed positions axis (y,z)
        rigidTBody->setAngularFactor(vector3df(1,0,0)); // Allowed rotations axis (x)
     
        rigidTBody->getAttributes()->addBool("trailer", true);
        rigidTBody->includeNodeOnRemoval(false);
        rigidTBody->setFriction(20);  // rigidBody->setFriction(7.0f);
        rigidTBody->setRestitution(0); // void bouncy
        rigidTBody->setDamping(0.1,0.1);
     
     
     
     
        // NODES -> WHEELS:
        irr::scene::IAnimatedMeshSceneNode* rodaTNode[10];
        rodaTNode[1] = smgr->addAnimatedMeshSceneNode(smgr->getMesh("wheel_big.b3d"));  // right_front_wheel
        rodaTNode[2] = smgr->addAnimatedMeshSceneNode(smgr->getMesh("wheel_big.b3d"));  // left_front_wheel
     
     
     
        // IGImpactMeshShape* wTShape1 = new IGImpactMeshShape(rodaNode1, device->getSceneManager()->getMesh("wheel_big.b3d"), 50.0); // IConvexHullShape* wShape1 = new IConvexHullShape(rodaNode1, device->getSceneManager()->getMesh("wheel_big.b3d"), 10.0); // IBoxShape* wShape1 = new IBoxShape(rodaNode1, 10.0, true);
        ISphereShape* wTShape1 = new ISphereShape(rodaTNode[1], wmass, true);
        IRigidBody *wtbody1 = world->addRigidBody(wTShape1, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        wTShape1->setMargin(wsm);
        wtbody1->setFriction(wsf);
        wtbody1->setDamping(dap,dap);
        wtbody1->getAttributes()->addBool("wheel", true);
        // wbody1->setActivationState(EAS_DISABLE_DEACTIVATION);
     
        // IGImpactMeshShape* wTShape2 = new IGImpactMeshShape(rodaNode2, device->getSceneManager()->getMesh("wheel_big.b3d"), 50.0); // IConvexHullShape* wShape2 = new IConvexHullShape(rodaNode2, device->getSceneManager()->getMesh("wheel_big.b3d"), 10.0);
        ISphereShape* wTShape2 = new ISphereShape(rodaTNode[2], wmass, true);
        IRigidBody *wtbody2 = world->addRigidBody(wTShape2, COL_VEHICLE, vehicleRaycastCollidesWith); // shape, group, mask
        wTShape2->setMargin(wsm);
        wtbody2->setFriction(wsf);
        wtbody2->setDamping(dap,dap);
        wtbody2->getAttributes()->addBool("wheel", true);
        // wbody2->setActivationState(EAS_DISABLE_DEACTIVATION);
     
     
     
        // FINISHING: Create vehicle2
        IRaycastVehicle* vehicle2 = world->addRaycastVehicle(rigidTBody); // Assuming world is pointer to your irrBullet World
        // world->addRaycastVehicle(wbody1); // Assuming world is pointer to your irrBullet World
     
        vehicle2->getVehicleRaycaster()->setUseFilter(true);
        vehicle2->getVehicleRaycaster()->setCollisionFilterGroup(COL_VEHICLE);
        vehicle2->getVehicleRaycaster()->setCollisionFilterMask(vehicleRaycastCollidesWith);
     
     
     
     
     
     
        // WHEELS "attached" to TRAILER, the secret is to use "constrains":
        btTransform frameInAA[10];
        btTransform frameInBB[10];
     
        frameInAA[0] = btTransform::getIdentity();
        frameInAA[0].setOrigin(irrlichtToBulletVector(trailerNode->getJointNode("05")->getPosition())); // position
        frameInBB[0] = btTransform::getIdentity();
        frameInBB[0].setOrigin(irrlichtToBulletVector(vector3df(0,0,0))); // rotation
     
        frameInAA[1] = btTransform::getIdentity();
        frameInAA[1].setOrigin(irrlichtToBulletVector(trailerNode->getJointNode("06")->getPosition())); // position
        frameInBB[1] = btTransform::getIdentity();
        frameInBB[1].setOrigin(irrlichtToBulletVector(vector3df(0,0,0))); // rotation
     
        btRigidBody* bodyAA = rigidTBody->getPointer(); // get chassi --->  parentObject->getRigidBody()->getPointer();
     
        btRigidBody* bodyBB[10];
        bodyBB[0] = wtbody1->getPointer(); // get wheel  --->  obj->getRigidBody()->getPointer();
        bodyBB[1] = wtbody2->getPointer(); // get wheel  --->  obj->getRigidBody()->getPointer();
     
        btGeneric6DofSpringConstraint* C11 = new btGeneric6DofSpringConstraint(*bodyAA, *bodyBB[0], frameInAA[0], frameInBB[0], true);
        btGeneric6DofSpringConstraint* C22 = new btGeneric6DofSpringConstraint(*bodyAA, *bodyBB[1], frameInAA[1], frameInBB[1], true);
     
        C11->setLinearUpperLimit(irrlichtToBulletVector(vector3df(0, 0.1,0)));    // linearUpperLimit
        C11->setLinearLowerLimit(irrlichtToBulletVector(vector3df(0,-0.1,0)));    // linearLowerLimit
     
        C22->setLinearUpperLimit(irrlichtToBulletVector(vector3df(0, 0.1,0)));    // linearUpperLimit
        C22->setLinearLowerLimit(irrlichtToBulletVector(vector3df(0,-0.1,0)));    // linearLowerLimit
     
        world->getPointer()->addConstraint(C11, true);
        world->getPointer()->addConstraint(C22, true);
     
     
     
     
        // Create wheel 1 - info:
        SWheelInfoConstructionInfo wheel11;
        wheel11.chassisConnectionPointCS = trailerNode->getJointNode("05")->getPosition();
        wheel11.wheelDirectionCS = irr::core::vector3df(0.0, -0.1, 0.0);
        wheel11.wheelAxleCS = irr::core::vector3df(-0.2, 0.0, 0.0);
        wheel11.suspensionRestLength = 0.3;  // 0.30;
        wheel11.wheelRadius = 8;            // wheel (node) radius (10)
        wheel11.isFrontWheel = false;
        vehicle2->addWheel(wheel11);          // Add left front wheel
     
        // Create wheel 2 - info:
        SWheelInfoConstructionInfo wheel22;
        wheel22.chassisConnectionPointCS = trailerNode->getJointNode("06")->getPosition();
        wheel22.wheelDirectionCS = irr::core::vector3df(0.0, -0.1, 0.0);
        wheel22.wheelAxleCS = irr::core::vector3df(0.2, 0.0, 0.0);
        wheel22.suspensionRestLength = 0.3;  // 0.30;
        wheel22.wheelRadius = 8;            // wheel (node) radius (10)
        wheel22.isFrontWheel = false;
        vehicle2->addWheel(wheel22);          // Add left front wheel
     
     
     
     
     
     
        // Tweak wheel info a bit, tweak here more:
        for(irr::u32 i=0; i<vehicle2->getNumWheels(); i++){
        SWheelInfo& info = vehicle2->getWheelInfo(i);
        info.suspensionStiffness     = 0.06f;
        info.wheelDampingRelaxation  = 0.20f;
        info.wheelDampingCompression = 0.20f;
        info.frictionSlip  = 1000;
        info.rollInfluence = 0.1f; // Fluidez no rolar (colisao entre rigid bodies)
        // info.wheelSuspensionForce = 0.1f;
        // info.engineForce = 100;
        vehicle2->updateWheelInfo(i);
        // vehicle2->updateWheelTransform(i,true);
        };
     
     
        rigidTBody->setVehicleReference(vehicle2);
     
     
        // Set all wheels (nodes) in the right positions:
        rodaTNode[1]->setPosition(wheel11.chassisConnectionPointCS);
        rodaTNode[2]->setPosition(wheel22.chassisConnectionPointCS);
     
     
     
     
     
     
        // TRAILER "attached" to VEHICLE, the secret is to use "constrains":
        btTransform frameInAAA[10];
        btTransform frameInBBB[10];
     
        frameInAAA[0] = btTransform::getIdentity();
        frameInAAA[0].setOrigin(irrlichtToBulletVector(vehicleNode->getJointNode("conn1_trailer")->getPosition()));  // VEHICLE
        frameInBBB[0] = btTransform::getIdentity();
        frameInBBB[0].setOrigin(irrlichtToBulletVector(trailerNode->getJointNode("conn2_trailer")->getPosition()));  // TRAILER
        // frameInBBB[0].setOrigin(irrlichtToBulletVector(trailerNode->getJointNode("conn2_trailer")->getPosition()));  // TRAILER
     
        btRigidBody* bodyAAA = rigidBody->getPointer();  // get chassi --->  parentObject->getRigidBody()->getPointer();
        btRigidBody* bodyBBB = rigidTBody->getPointer(); // get wheel  --->  obj->getRigidBody()->getPointer();
     
        btGeneric6DofSpringConstraint* C111 = new btGeneric6DofSpringConstraint(*bodyAAA, *bodyBBB, frameInAAA[0], frameInBBB[0], true);
        C111->setLinearUpperLimit(irrlichtToBulletVector(vector3df(0,0,0)));       // linearUpperLimit
        C111->setLinearLowerLimit(irrlichtToBulletVector(vector3df(0,0,0)));       // linearLowerLimit
        C111->setAngularUpperLimit(irrlichtToBulletVector(vector3df(0.5,0,0)));    // AngularUpperLimit ok: 0.5
        C111->setAngularLowerLimit(irrlichtToBulletVector(vector3df(-340,0,0)));   // AngularlowerLimit ok: -340
     
        world->getPointer()->addConstraint(C111, true);
     
     
     
     
     
     
     
     
        // Run all:
        int lastFPS = -1;
        while(device->run()){
     
     
     
                driver->beginScene(true, true, video::SColor(0,40,40,40));
     
                frameDeltaTime = device->getTimer()->getTime() - TimeStamp;
                TimeStamp = device->getTimer()->getTime();
     
                int fps = driver->getFPS();
                if (lastFPS != fps){
                device->setWindowCaption(L"TRUCK - By Jorge Rosa - jorge.bigarte@gmail.com");
                };
     
     
     
     
                // UPDATING PHYSICS:
                world->stepSimulation(frameDeltaTime*0.0017f, 10);
     
     
                // MISSING CODE HERE (irrlicht normal stuff .......)
     
     
                // reset FORCES:
                for(irr::u32 i=0; i<vehicle->getNumWheels(); i++){ vehicle->applyEngineForce(0,i); }; // force, wheelindex
     
                if(receiver.IsKeyDown(irr::KEY_KEY_A)){
                    force = 10000;
                    vehicle->applyEngineForce( force, 0);
                    vehicle->applyEngineForce(-force, 1);
                    vehicle->applyEngineForce( force, 2);
                    vehicle->applyEngineForce(-force, 3);
                };
     
                if(receiver.IsKeyDown(irr::KEY_KEY_D)){
                    force = 10000;
                    vehicle->applyEngineForce(-force, 0);
                    vehicle->applyEngineForce( force, 1);
                    vehicle->applyEngineForce(-force, 2);
                    vehicle->applyEngineForce( force, 3);
                };
     
     
     
     
                // WHEELS ROTATING: (Updates nodes according VELOCITY)
                // Rotate wheels (nodes) according vehicle´s (rigidbody) velocity:
                f32 velocity = vehicle->getRigidBody()->getLinearVelocity().Z;
                // ROTATING vehicle wheels:
                irr::core::matrix4 mat;
                mat.setRotationDegrees(vector3df(rotat+=(velocity * 0.12 * frameDeltaTime),0,0));
                rodaNode[1]->setRotation(mat.getRotationDegrees());   // Apply to nodes
                rodaNode[2]->setRotation(mat.getRotationDegrees());   // Apply to nodes
                rodaNode[3]->setRotation(mat.getRotationDegrees());   // Apply to nodes
                rodaNode[4]->setRotation(mat.getRotationDegrees());   // Apply to nodes
     
     
                f32 tvelocity = wtbody1->getLinearVelocity().Z;
                // ROTATING trailer wheels:
                irr::core::matrix4 mattr;
                mattr.setRotationDegrees(vector3df(trotat+=(tvelocity * 0.12 * frameDeltaTime),0,0));
                rodaTNode[1]->setRotation(mattr.getRotationDegrees());  // Apply to nodes
                rodaTNode[2]->setRotation(mattr.getRotationDegrees());  // Apply to nodes
     
     
                // WHEELS ROTATING: (Updates nodes according ENGINE FORCE)
                // Rotate wheels (nodes) according vehicle´s (rigidbody) velocity:
                f32 engine_force = wbody1->getTotalForce().Z  + wbody2->getTotalForce().Z  + wbody3->getTotalForce().Z  + wbody4->getTotalForce().Z;
                f32 totalTorque  = wbody1->getTotalTorque().Z + wbody2->getTotalTorque().Z + wbody3->getTotalTorque().Z + wbody4->getTotalTorque().Z;
     
     
     
     
     
     
     
                for(u32 i=0; i<world->getNumManifolds(); ++i){
                ICollisionCallbackInformation* info = world->getCollisionCallback(i);
     
                ICollisionObject* obj1 = info->getBody0();
                ICollisionObject* obj2 = info->getBody1();
     
                int numContacts = info->getPointer()->getNumContacts();
                SManifoldPoint point = info->getContactPoint(0);
     
     
                for(u32 i=0; i<numContacts; ++i){
                if(info->getContactPoint(0).getDistance()<0.1f && numContacts>0){
     
                // COLLISION:
                if(obj1->getAttributes()->existsAttribute("box") && obj2->getAttributes()->existsAttribute("road")){
                // Do stuff...
                };
     
                };
     
                // Clear stuff:
                info->getPointer()->clearManifold();  //<- is this the right way to clear & delete the info?
                delete info;
                };
     
     
     
     
     
     
                smgr->drawAll();
                guienv->drawAll();
                driver->endScene();
        };
     
     
        device->drop();
        return 0;
    };

     

PS: Would be nice if a moderator could replace my "quote" tags by "code" tags.
I can´t, because if I do that, the code becomes hidden to the forum (odd). Thanks and sorry for the "code spam".

For a better look at this code, please copy / past to your IDE (In my case its Code::Blocks).
Any doubts / questions / improvements / etc / etc... fell free to post them, I´ll be glad to help (if I can.......).
Last edited by jorgerosa on Mon Jan 20, 2014 9:29 am, edited 27 times in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by CuteAlien »

@ jorgerosa: Sorry, moderators have the same restrictions as users when it comes to the code flags. That's an open problem in the forum which has not been debugged so far by anyone.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Firewolf
Posts: 5
Joined: Sun Feb 03, 2013 7:08 pm

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by Firewolf »

I've been trying for quite a while to get irrBullet working, but it won't compile. Like a few other people on this topic, when running the make command, I'm getting the error:

Code: Select all

make: Circular ../source/boxshape.cpp <- ../source/boxshape.cpp dependency dropped.
make: *** No rule to make target `Bullet/btBulletDynamicsCommon.h', needed by `../source/boxshape.cpp'.  Stop.
I'm using Ubuntu 12.10, by the way. I just set up my computer to dual-boot Ubuntu and Windows 8 this week, so I'm not yet familiar with all this technical stuff like makefiles. I was previously using Dark GDK with MSVC++, and that just required me to link to a few libraries and use some header files. I'd kinda like to know why it's different here, as irrlicht, irrBullet, and Bullet (I don't know if I actually had to download Bullet as well, but a forum said so, so I tried it to see if it made a difference in getting irrBullet to work. It doesn't) have all required me to actually build from the source code. I know that might not be entirely on topic here, but I think if I knew WHY I had to do this stuff, it would help a lot in getting it to actually work. I noticed that there are already libraries for Windows (both with MSVC++ and with gcc), but just an empty folder for Linux, requiring me to create the files myself. I assume this is due to differences in Linux distributions that would somehow prevent a single library from working for all distros. If that's not the case, however--if a library for linux would work with any (or at least most) linux distros-- then I think it would be really nice if that library file could be included in the download.
I've also tried moving the Windows gcc library into the linux folder, in case that worked. It doesn't. At least, I don't think it helped. It solved one error, but made eight more.
I have also tried to open the Code::Blocks file for irrBullet, but it asks me to define the global variable "irrlicht", and I have no idea what it's supposed to be.
If anyone could offer me some advice, it would be VERY much appreciated. I enjoy solving computer issues, for an hour or two. But when I have no idea what I'm doing, and I've been doing it for several hours with no improvement, it becomes annoying.
P.S. For anyone who's going to suggest I just do it in Windows 8, yeah, I know. My plan is to have all this stuff set up such that I can do my programming in either OS. I'm planning on making a game that works with both Windows and Linux (hopefully all/most Linux, and not just Ubuntu), so I want to be able to test it in both. I'm gonna try setting it up in Windows now, but even if that works, it's not really a solution, so I'd really like to get irrBullet working in Ubuntu. Plus, I just feel like it makes more sense to do my programming in an OS for geeks.
P.P.S I'm not entirely clear on what irrBullet does, actually. So, it basically makes irrlicht stuff and Bullet stuff compatible with each other, right? So it wouldn't be possible (or easy) to use irrlicht and Bullet without a wrapper, I assume.
P.P.P.S Sorry for any and all stupid questions I've asked.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by serengeor »

P.P.S I'm not entirely clear on what irrBullet does, actually. So, it basically makes irrlicht stuff and Bullet stuff compatible with each other, right? So it wouldn't be possible (or easy) to use irrlicht and Bullet without a wrapper, I assume.
It basically wraps most of things, makes conversions between types so you could use it more or less the same as any other irrlicht stuff. Though in my opinion wrapping everything is pointless as you just write lots of bloat code that might become incompatible with new releases of bullet.

It should be enough to write custom motion states and vector, matrix conversions. What you won't get with this approach is irrlicht like physics object management.
Working on game: Marrbles (Currently stopped).
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by user-r3 »

Hello, please execuse the fact, that I did not read through all 29 pages, but a both forum and google search did not help me ;)

I recently updated Code::Blocks IDE to 12.something. This lead me to updating MinGW to the newest version - and this to recompiling pretty much everything - also irrBullet. So I thought, why not download the latest Bullet Physics and use this. And here irrBullet does no longer want to compile:

I get several cast errors, starting here:

Code: Select all

ICollisionObject* const ICollisionCallbackInformation::getBody0() const
{
    SCollisionObjectIdentification* identification =
        static_cast<SCollisionObjectIdentification*>(static_cast<btCollisionObject*>(contactManifold->getBody0())->getUserPointer());
// this call above this comment does not work, for example
 
    return identification->getCollisionObject();
 
    return 0;
}
[REMOVED PATH]\irrBullet-0.1.8\source\collisioncallbackinformation.cpp:20:113: error: static_cast from type 'const btCollisionObject*' to type 'btCollisionObject*' casts away qualifiers
I sadly do not have an idea, how to fix this, so I am asking for help. Thanks a lot in advance!

user-r3
Firewolf
Posts: 5
Joined: Sun Feb 03, 2013 7:08 pm

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by Firewolf »

user-r3 wrote:Hello, please execuse the fact, that I did not read through all 29 pages, but a both forum and google search did not help me ;)

I recently updated Code::Blocks IDE to 12.something. This lead me to updating MinGW to the newest version - and this to recompiling pretty much everything - also irrBullet. So I thought, why not download the latest Bullet Physics and use this. And here irrBullet does no longer want to compile:

I get several cast errors, starting here:

Code: Select all

ICollisionObject* const ICollisionCallbackInformation::getBody0() const
{
    SCollisionObjectIdentification* identification =
        static_cast<SCollisionObjectIdentification*>(static_cast<btCollisionObject*>(contactManifold->getBody0())->getUserPointer());
// this call above this comment does not work, for example
 
    return identification->getCollisionObject();
 
    return 0;
}
[REMOVED PATH]\irrBullet-0.1.8\source\collisioncallbackinformation.cpp:20:113: error: static_cast from type 'const btCollisionObject*' to type 'btCollisionObject*' casts away qualifiers
I sadly do not have an idea, how to fix this, so I am asking for help. Thanks a lot in advance!

user-r3
I got that error, too. To solve it, just remove the second static_cast. I think that worked, though it's been a while, and I never did get irrBullet working, so I can't guarantee the solution works. But you might as well try it, right?
Line becomes:

Code: Select all

static_cast<SCollisionObjectIdentification*>((contactManifold->getBody0())->getUserPointer());
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Re: irrBullet 0.1.8 - Bullet physics wrapper

Post by user-r3 »

Thanks buddy, that fixed it, everything works now again after some more recompiling ;)
Post Reply