irrBullet 0.1.8 - Bullet physics wrapper

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
silver.slade
Posts: 17
Joined: Fri Jan 29, 2010 8:54 am
Contact:

Post by silver.slade »

DawsonXB360 wrote:Cobra or silver.slade. Could either of you perhaps send me some source code showing how to load a .irr file and apply collision, I'm having a little trouble with it myself.
Hi DawsonXB360.

Here a little example (maybe I'll post here a complete source later):

Code: Select all

    ...
    
    // Create the irrBullet world
	world = createIrrBulletWorld(device, true, true);
	world->setDebugMode(EPDM_DrawAabb |	EPDM_DrawContactPoints);
	world->setGravity(vector3df(0,-10,0));


    // load irr file to scene
    smgr->loadScene("Scene.irr");

    // create metatriangleselector
    scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
    core::array<scene::ISceneNode *> nodes;
    
    // gets all nodes
	smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); 

	ICollisionShape *shape;
	IRigidBody* terrain;

	for (u32 i=0; i < nodes.size(); ++i)
	{
		scene::ISceneNode * node = nodes[i];
		scene::ITriangleSelector * selector = 0;

		switch(node->getType())
		{
		case scene::ESNT_CUBE:
		case scene::ESNT_ANIMATED_MESH:
			selector = smgr->createTriangleSelectorFromBoundingBox(node);
		break;

		case scene::ESNT_MESH:
		case scene::ESNT_SPHERE: 
            // output for quick debug
			printf("(SPHERE OR MESH)%s\n", node->getName());
			selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);

			shape = new IBvhTriangleMeshShape(((scene::IMeshSceneNode*)node),
					((scene::IMeshSceneNode*)node)->getMesh(),
					0.0);
        
			terrain = world->addRigidBody(shape);
			terrain->setGravity(vector3df(0,0,0));
			shape->setLocalScaling(node->getScale(), ESP_VISUAL);
			terrain->setCollisionFlags(ECF_STATIC_OBJECT);
		break;

		case scene::ESNT_TERRAIN:
            // output for quick debug
			printf("(TERRAIN)%s\n", node->getName());
			selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
        break;

		case scene::ESNT_OCTREE:
            // output for quick debug
			printf("(OCTREE)%s\n", node->getName());
			selector = smgr->createOctreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
        break;

		default:
			// Don't create a selector for this node type
			printf("%s, NO COLLISIONS!\n", node->getName());
			break;
		}


		if(selector)
		{
			// used by the camera's collisions
			meta->addTriangleSelector(selector);
			selector->drop();
		}

		// the camera
		if (strcmp(node->getName(),"Camera")==0)
        {
			printf("Found a camera...loading its parameters\n");
			camera = smgr->addCameraSceneNodeFPS(0, 60.0f, 0.008f, -1, keyMap, 8, true, 0.5f);
			camera->setFOV( ((scene::ICameraSceneNode*)node)->getFOV());
			posizione = ((scene::ICameraSceneNode*)node)->getPosition();
			camera->setPosition( posizione );
			camera->setRotation( ((scene::ICameraSceneNode*)node)->getRotation());
			camera->setScale(((scene::ICameraSceneNode*)node)->getScale());
			camera->setFarValue(((scene::ICameraSceneNode*)node)->getFarValue());
			camera->setAspectRatio(((scene::ICameraSceneNode*)node)->getAspectRatio());
			camera->setTarget(((scene::ICameraSceneNode*)node)->getTarget());
			camera->setUpVector(((scene::ICameraSceneNode*)node)->getUpVector());
			camera->setFarValue(15000);
		}
	}

	// camera not found, I'll create one
    // usually a camera is always present in .irr file
	if (camera==0){
		printf("No Camera founded: we'll create one...\n");
		camera = smgr->addCameraSceneNodeFPS(0, 40.0f, 0.008f, -1, keyMap, 8, true, 5.0f);
		camera->setFOV(0.857);
		camera->setPosition(vector3df(28.655060, 5.699696, -18.311363));
		camera->setRotation(vector3df(27.098162, -46.688389, -0.903519));
		camera->setScale(vector3df(1, 1, 1));
		camera->setNearValue(0.10);
		camera->setFarValue(100.0);
		camera->setAspectRatio(1.25);
	}


	core::rect<s32> vp = driver->getViewPort();
    camera->setAspectRatio((f32)vp.getWidth() / (f32)vp.getHeight());

    // collisions with camera and meta
	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		meta,
		camera,
		core::vector3df(1.5,posizione.Y,1.5),
		core::vector3df(0,-0.5,0),
		core::vector3df(0,0,0));
	meta->drop(); 
	camera->addAnimator(anim);
	anim->drop(); 

    u32 TimeStamp = device->getTimer()->getTime(), DeltaTime = 0;

	while(device->run())
    {
        if (device->isWindowActive())
        {
            driver->beginScene(true, true, video::SColor(0,50,50,50));

            DeltaTime = device->getTimer()->getTime() - TimeStamp;
            TimeStamp = device->getTimer()->getTime();

            // irrbullet related
            world->stepSimulation(DeltaTime*0.001f, 120);
            world->debugDrawWorld(true);
            world->debugDrawProperties(true);

            smgr->drawAll();
            guienv->drawAll();
            driver->endScene();
        }
    }
    
    delete world;
	device->drop();
	return 0;
}


Erelas
Competition winner
Posts: 20
Joined: Mon Apr 18, 2011 8:40 am

Post by Erelas »

Hi Cobra,

Thanks, for creating IrrBullet and supporting it.

I was wondering if you could help us with a problem we're having.

For our game, we load several meshes to create a tank for our game (wheels/armor/turret/barrel).
When we load our wheels and add a rigidbody to it, we create a IRaycastVehicle with it. All collision works as supposed to on the wheels.

Next step would be creating collision for the body mesh of the tank, we call it armor. The problem is that I cant seem to link/join/constrain the rigidbodies of the tank wheels and armor.

Is there an example where constraints are used properly? Or is there another way to implement this?

The tanks should be build with those different meshes as we want to be able to give the player the ability to customize the tank on those levels in the future.
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

Erelas wrote:Hi Cobra,

Thanks, for creating IrrBullet and supporting it.

I was wondering if you could help us with a problem we're having.

For our game, we load several meshes to create a tank for our game (wheels/armor/turret/barrel).
When we load our wheels and add a rigidbody to it, we create a IRaycastVehicle with it. All collision works as supposed to on the wheels.

Next step would be creating collision for the body mesh of the tank, we call it armor. The problem is that I cant seem to link/join/constrain the rigidbodies of the tank wheels and armor.

Is there an example where constraints are used properly? Or is there another way to implement this?

The tanks should be build with those different meshes as we want to be able to give the player the ability to customize the tank on those levels in the future.
I use constraints in my game with irrBullet and they work fine. There is no constraints demo yet because I don't have time right now, but you have to use Bullet constraints. It's very easy to mix Bullet and irrBullet, and I found it unnecessary to include a constraints wrapper interface.

You can check the irrBullet FAQ on how to use constraints.

- Josiah
Josiah Hartzell
Image
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

Oddly enough, I'm finally running into problems getting something to compile, and have to ask for help.

I get this when I try to compile my project with Eclipse:

Code: Select all

D:\cyberBench\Infiltrator/libirrbullet.a(softbody.o):D:/lazerbladegames/irrBullet-0.1.71/source/softbody.cpp:255: undefined reference to `btSoftBody::appendAnchor(int, btRigidBody*, bool)'

And yes, I have now triple checked that my libraries are in the proper order. This was copy/pasted from the project settings:

Code: Select all

Irrlicht
irrbullet
bulletdynamics
bulletsoftbody
gimpactutils
linearmath
bulletcollision

Is there maybe another header I need to be including besides irrBullet.h? I'm pretty much stumped about this one.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
mataanjin
Posts: 19
Joined: Tue May 25, 2010 3:07 am

Post by mataanjin »

i tried to reset my raycastvehicle when the suspension fails,
i want to keep everything but the y position and x,z rotation.

but i have a problem, when the vehicle is in quadrant 2 or 3, it will rotate to other side(in quadrant 1 or 4)

Code: Select all

void RCCar::resetSpring()
{
	matrix4 mat4;
	mat4 = rBody->getWorldTransform();
	vector3df trans = mat4.getTranslation();
	trans.Y = 0;
	mat4.setTranslation( trans );
	vector3df rot = mat4.getRotationDegrees();
	rot.X = 0;
	rot.Z = 0;
	mat4.setRotationDegrees( rot );
	
	rBody->setWorldTransform(mat4);
	vehicle->resetSuspension();
}
and how to use checkCollisionWith ?
it always return true for me. is there any rule for the geometry?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Post by mongoose7 »

Whaaaaaaaaaaaaaaaaaaaaat?

What if rot.Z = 180? Setting it to 0 will cause rot.Y in effect to flip.

It's Euler angles. They can't be wrangled. Or compared.
mataanjin
Posts: 19
Joined: Tue May 25, 2010 3:07 am

Post by mataanjin »

mongoose7 wrote:Whaaaaaaaaaaaaaaaaaaaaat?

What if rot.Z = 180? Setting it to 0 will cause rot.Y in effect to flip.

It's Euler angles. They can't be wrangled. Or compared.
well, i use a plane as the ground, so rot.Z is usually 0 - 1.
the reset function is working, in quadrant 1 and 4, but not when quadrant 2 and 3.

if i don't change the z, it flip at quadrant 2 and 3.

any idea how to do this?

edit:
ah, got it.
never know about euler angle before :p

this is what i did.

Code: Select all

              if ( rot.X > 179 && rot.X < 271)
		rot.X = 180;
	else
		rot.X = 0;
	if(rot.Z < 271 && rot.Z > 179)
		rot.Z = 180;
	else
		rot.Z = 0;
thanks
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

-->!BUMP!<--

I still don't have this figured out. Even random ideas that might fix the problem would be appreciated.
lazerblade wrote:
I get this when I try to compile my project with Eclipse:

Code: Select all

D:\cyberBench\Infiltrator/libirrbullet.a(softbody.o):D:/lazerbladegames/irrBullet-0.1.71/source/softbody.cpp:255: undefined reference to `btSoftBody::appendAnchor(int, btRigidBody*, bool)'

And yes, I have now triple checked that my libraries are in the proper order. This was copy/pasted from the project settings:

Code: Select all

Irrlicht
irrbullet
bulletdynamics
bulletsoftbody
gimpactutils
linearmath
bulletcollision

Is there maybe another header I need to be including besides irrBullet.h? I'm pretty much stumped about this one.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Post by user-r3 »

Hi, I only see undefined references when I forget to link something...

Here's my problem:

I want to use Irrbullet Shapes with an Irrlicht FPSCamera, but I have no idea how to get it working.

I managed my camera attaching to a shape and flying around (mass of the body = 0), but this was there is no collision and as soon as I use any mass for the body, I can no longer control my camera...

Any ideas/tips/tutorials for me?

Thanks,

user-r3
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Post by RdR »

lazerblade wrote:-->!BUMP!<--

I still don't have this figured out. Even random ideas that might fix the problem would be appreciated.
lazerblade wrote:
I get this when I try to compile my project with Eclipse:

Code: Select all

D:\cyberBench\Infiltrator/libirrbullet.a(softbody.o):D:/lazerbladegames/irrBullet-0.1.71/source/softbody.cpp:255: undefined reference to `btSoftBody::appendAnchor(int, btRigidBody*, bool)'

And yes, I have now triple checked that my libraries are in the proper order. This was copy/pasted from the project settings:

Code: Select all

Irrlicht
irrbullet
bulletdynamics
bulletsoftbody
gimpactutils
linearmath
bulletcollision

Is there maybe another header I need to be including besides irrBullet.h? I'm pretty much stumped about this one.
Did you include the Bullet Physics dlls ?
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

Did you include the Bullet Physics dlls?
I compiled Bullet myself, and am using static libs. Are there DLL's I need? I didn't get any "cannot find -lwhatever" errors.

I do have .a files for all the ones I listed.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

lazerblade wrote:
Did you include the Bullet Physics dlls?
I compiled Bullet myself, and am using static libs. Are there DLL's I need? I didn't get any "cannot find -lwhatever" errors.

I do have .a files for all the ones I listed.
are you really sure its the correct order?
I assume that you use code::blocks (because of .a files)
In that case I think your order is wrong.
First thing that needs to be linked is soft body library, then dynamics, then collision, then vector math.
Working on game: Marrbles (Currently stopped).
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

Oh, I should note that that problem went away. I solved it by recompiling bullet and IrrBullet with my version of GCC.

Now i'm getting good old fashion __gxx_personality_sj0 not found errors and stuff like that. I'm guessing that makes this a problem with the standard library or my projects lack of ability to find the standard library, and not an IrrBullet problem.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

I'll try changing the order, thank you. BTW, I'm using Eclipse + MinGW.


--> A few moment later <--


Okay, I now have way less standard library errors, but a bunch of bullet lib errors like before. Apparently the link order that the ReadMe file recommends isn't quite right. Does anybody know of a working lib order I can try? That way we can narrow the problem down by eliminating that possibility.
Last edited by lazerblade on Thu May 19, 2011 4:29 pm, edited 1 time in total.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Oh, yes I intended to say gcc compilers.

Anyways, It should be like this:

Code: Select all

Irrlicht 
irrbullet
bulletsoftbody 
bulletdynamics 
bulletcollision
linearmath 
As for gimpact utils I don't really know but it should go above at least collision library.
Working on game: Marrbles (Currently stopped).
Post Reply