Page 1 of 3

bullet irrlicht demo

Posted: Mon Dec 03, 2007 2:13 am
by Jacky_J
I have created a very simple irrlicht bullet demo using the latest versions(bullet 2.64 and irrlicht 1.4).

http://www.cs.utah.edu/~witkowsk/files/irrtest.zip

The zip is self-contained with all the libraries and includes. All you have to do is set the working directory inside the project debugging properties. Tested on Windows XP / Visual C++ Express.

Posted: Mon Dec 03, 2007 6:23 pm
by jcfalcone
don't have dev-cpp files?

Posted: Mon Dec 03, 2007 10:58 pm
by GameDude
He siad Visual Express C++. You can convert them to Dev-CPP or you can get C++ Express, which is free.

Posted: Wed Dec 05, 2007 1:50 pm
by jcfalcone
why every time i trying to compile this on visual c++ 5 express,with bullet files, this show linker errors on bullet? i need to do some thing?

Posted: Wed Dec 05, 2007 5:51 pm
by Jacky_J
jcfalcone wrote:why every time i trying to compile this on visual c++ 5 express,with bullet files, this show linker errors on bullet? i need to do some thing?
Visual C++ 5? 2005?

did you follow these steps:

http://msdn2.microsoft.com/en-us/express/aa700755.aspx

Do you have another version of bullet on your computer? Post the output of your compile.

Posted: Thu Dec 06, 2007 1:17 pm
by jcfalcone
i don't know what i did but now the code compile XD.

only one question, to do the same with more complex objects like Quake 3 maps or Meshs what function i use?

Posted: Fri Dec 07, 2007 2:58 am
by Jacky_J
Take a look at irrlamb's source code:
http://irrlamb.googlecode.com/svn/trunk/source/

If you look at mesh.cpp for example, you can use a btBvhTriangleMeshShape as the shape.
http://irrlamb.googlecode.com/svn/trunk ... s/mesh.cpp

Also, look at ConvertCollisionMesh inside physics.cpp:
http://irrlamb.googlecode.com/svn/trunk ... hysics.cpp

That will show you how to convert an irrlicht mesh to a bullet mesh.

Other examples to look at are in terrain.cpp and scene.cpp

Let me know if you have other questions.

Posted: Thu Dec 20, 2007 2:00 am
by jcfalcone
Thanks Jacky_J

I see your code XD

but help me here

i try to create a class to create my meshs

but every time i try to use the functions of bullet the exe stop to work

the function

UpdateMeshs() and PhysicMesh() with EnablePhysic = true stop my exe.

Code: Select all

#ifndef MESHCLASS_CPP
#define MESHCLASS_CPP
// Change this to the path where your Irrlicht Header Files are. 
#include <irrlicht.h>
#include <btBulletCollisionCommon.h>
#include <btBulletDynamicsCommon.h>
#include "global.cpp"
#include "engine.physic.cpp"



using namespace std; 
using namespace irr; 
using namespace core; 
using namespace scene; 
using namespace video; 
using namespace io; 
using namespace gui; 

/// ============================== 
/// MastMesh
/// ============================== 
class Mastmesh
{
// Classes  
  
   ISceneNode* Node;
   //mesh
     IAnimatedMesh * Mesh;
     
   //fisica
     btRigidBody *RigidBody;
     btCollisionShape *Shape;
     btDefaultMotionState *MotionState;
   //Engine de Fisica
     PhysicEng Engine;

   void PhysicMesh(ISceneNode* &Node)
   {
		// Graphics
	  IAnimatedMesh *AnimatedMesh = smgr->getMesh(Mesh_Model);
	  Node = smgr->addOctTreeSceneNode(AnimatedMesh);
	  Node->setScale(Scale);
	  if(MeshTexture != "")
	  {
	  		Node->setMaterialTexture(0, driver->getTexture(MeshTexture));
	  }
	  if(EnablePhysic) 
      {		
		// Get the collision mesh
		btTriangleMesh *CollisionMesh = new btTriangleMesh();
		Engine.ConvertCollisionMesh(Mesh->getMesh(0), 
                             CollisionMesh, 
                             Scale);
		Shape = new btBvhTriangleMeshShape(CollisionMesh, true);

		// Orientation
		btTransform Transform;
		Engine.GetBulletTransform(Transform, TPosition, TRotation);
		MotionState = new btDefaultMotionState(Transform);
		
		// Body
		RigidBody = new btRigidBody(Mass, MotionState, Shape);
		RigidBody->setUserPointer((void *)this);
		
		World->addRigidBody(RigidBody);
	    Objects.push_back(RigidBody);
	  }
   };

	void UpdatePhysics(u32 TDeltaTime) {

		World->stepSimulation(TDeltaTime * 0.001f, 60);

		// Relay the object's orientation to irrlicht
		for(list<btRigidBody *>::Iterator Iterator = Objects.begin(); Iterator != Objects.end(); ++Iterator) 
		{

			UpdateRender(*Iterator);
		}	
	};

	void UpdateRender(btRigidBody *TObject) {
		ISceneNode *Node = static_cast<ISceneNode *>(TObject->getUserPointer());

		// Set position
		btPoint3 Point = TObject->getCenterOfMassPosition();
		Node->setPosition(vector3df((f32)Point[0], (f32)Point[1], (f32)Point[2]));

		// Set rotation
		btVector3 EulerRotation;
		Engine.QuaternionToEuler(TObject->getOrientation(), EulerRotation);
		Node->setRotation(vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]));
	};

   public:
       //textura e modelo  
       c8 *MeshTexture;
       c8 *Mesh_Model;
       //tamanho,massa e posição
       vector3df Scale;
       btScalar  Mass;
       vector3df TPosition;
	   vector3df TRotation;
       //se possui fisica ou não
       bool EnablePhysic;
	   IrrlichtDevice* device; 
	   scene::ISceneManager* smgr;
	   video::IVideoDriver* driver;
       u32 TimeStamp;
	   u32 DeltaTime;
     
	   void UpdateMeshs()
	   {

		  DeltaTime = irrTimer->getTime() - TimeStamp;
		  TimeStamp = irrTimer->getTime();

		  UpdatePhysics(DeltaTime);
	   };

       void CreateMesh()
       {
          Mesh = smgr->getMesh(Mesh_Model);
          Node = smgr->addOctTreeSceneNode(Mesh);
    	  Node->setScale(Scale);
    	 
          if (Node)	
          {
             Node->setMaterialTexture(0, driver->getTexture(MeshTexture));
          }
          PhysicMesh(Node);
       };

       ISceneNode* GetNode()
      {
             return Node;
      };

};
#endif

Get this put on the tutorial page!

Posted: Thu Dec 20, 2007 8:22 am
by mqrk
This should be on the tutorial page because there are samples for other physics engines but I didn't see one for Bullet.

Posted: Fri Dec 21, 2007 1:00 am
by jcfalcone
i see the cod again and i found the errors

but one i didn't found. in the void UpdateRender(btRigidBody *TObject) the cod stop to work in this line

Node->setPosition(vector3df((f32)Point[0], (f32)Point[1], (f32)Point[2]));


to meshs i need to do some thing more?

Posted: Thu Dec 27, 2007 8:46 pm
by Jacky_J
The problem is that you changed

Code: Select all

RigidBody->setUserPointer((void *)(Node));
to

Code: Select all

RigidBody->setUserPointer((void *)this);
but you didn't update the "receiving" side of it.

try changing

Code: Select all

ISceneNode *Node = static_cast<ISceneNode *>(TObject->getUserPointer());
to

Code: Select all

ISceneNode *Node = static_cast<Mastmesh *>(TObject->getUserPointer())->Node;
or something similar.

Posted: Sun Jan 20, 2008 10:18 pm
by trixs
I just had to let you know that this is EXTREMELY helpful.

An actual working simple example! That seems to be odd around here.

Posted: Tue Jan 22, 2008 8:18 pm
by Jacky_J
trixs wrote:I just had to let you know that this is EXTREMELY helpful.

An actual working simple example! That seems to be odd around here.
Thanks. I completely agree with you. Bullet doesn't have the best documentation/examples. There's another bullet/irrlicht demo floating around that's outdated and not really set up in a tutorial fashion.

One thing that i should have done in this tutorial is load terrain/mesh from a file. But with the links i provided above it should get you in the right direction.

Posted: Thu Jan 31, 2008 6:09 pm
by erwincoumans
This great tutorial should indeed go into the tutorial links for Irrlicht, anyone knows who to contact for this?

Just curious: how hard would it be to add real-time shadows?

Thanks,
Erwin

re

Posted: Mon Feb 04, 2008 6:00 pm
by gabdab
I use to compile all bullet files one by one in my project to avoid linkage problems ( as mentioned in bullet forums ).

Gab-