bullet irrlicht demo

A forum to store posts deemed exceptionally wise and useful
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

bullet irrlicht demo

Post 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.
jcfalcone
Posts: 37
Joined: Wed Nov 28, 2007 10:04 pm

Post by jcfalcone »

don't have dev-cpp files?
GameDude
Posts: 498
Joined: Thu May 24, 2007 12:24 am

Post by GameDude »

He siad Visual Express C++. You can convert them to Dev-CPP or you can get C++ Express, which is free.
jcfalcone
Posts: 37
Joined: Wed Nov 28, 2007 10:04 pm

Post 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?
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

Post 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.
jcfalcone
Posts: 37
Joined: Wed Nov 28, 2007 10:04 pm

Post 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?
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

Post 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.
jcfalcone
Posts: 37
Joined: Wed Nov 28, 2007 10:04 pm

Post 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
mqrk
Posts: 16
Joined: Mon Dec 10, 2007 5:55 am

Get this put on the tutorial page!

Post 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.
jcfalcone
Posts: 37
Joined: Wed Nov 28, 2007 10:04 pm

Post 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?
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

Post 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.
trixs
Posts: 26
Joined: Fri Jan 11, 2008 5:19 am
Location: Georgia
Contact:

Post 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.
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

Post 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.
erwincoumans
Posts: 46
Joined: Tue Oct 02, 2007 6:46 am
Contact:

Post 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
gabdab
Posts: 42
Joined: Fri May 12, 2006 5:11 pm

re

Post 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-
Post Reply