Bullet physics animator

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
zet.dp.ua
Posts: 66
Joined: Sat Jul 07, 2007 8:10 am

Bullet physics animator

Post by zet.dp.ua »

This simple tutorial demonstrates integration of Bullet Physics Library with Irrlicht.
Bullet object and Irrlicht scene node are syncronized via ISceneNodeAnimator interface.
Currently i've tested convex and concave meshes, seems to work fine.

You should have latest (2.54) Bullet library and directory hierarchy like this
bullet\
irrlicht\
-examples\
--BulletAnimator
-media\
--pin.png
--pin.x

Pin object was taken from Ragdoll Monkey Bowling by Walaber (http://walaber.dbspot.com)

sources are here http://www.mediafire.com/?auzltxizpml
catron
Posts: 158
Joined: Mon Feb 19, 2007 1:54 am

Post by catron »

could you show a screen shot and/or provide a exe?
zet.dp.ua
Posts: 66
Joined: Sat Jul 07, 2007 8:10 am

Post by zet.dp.ua »

yes, but not now, i have tried sometimes to upload (~2,8Mb) with my 56k modem, but failed to do this. i'll upload it later

[img][img=http://img209.imageshack.us/img209/1937/bulletanimatorscreenif8.th.jpg][/img][/img]
catron
Posts: 158
Joined: Mon Feb 19, 2007 1:54 am

Post by catron »

nice! 56k SUCKS ive had it before :( i feel for you
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Cool snippet.
Would you mind if I added this to the irrlicht plugins svn? I can give you svn write access too if you would like to keep it up to date
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
zet.dp.ua
Posts: 66
Joined: Sat Jul 07, 2007 8:10 am

Post by zet.dp.ua »

You can find precompiled demo with sources here: http://www.mediafire.com/?2mbm4kezvzl
and only sources here http://www.mediafire.com/?auzltxizpml

2 bitplane: this is draft version, i want to test several free physics engines (with concave and convex collision support), if you think this version is enough you can add this to plugins, i'll maintain code when possible
zet.dp.ua
Posts: 66
Joined: Sat Jul 07, 2007 8:10 am

Post by zet.dp.ua »

better version of bullet animator is ready
now it supports serialization/deserialization
also scene can have several bullet worlds

http://www.mediafire.com/?7plwc9yyyhb


i'm thinking about the best way of editing physics parameters for an object.
are there a possibilities to use irrEdit for this? can irrEdit be extended via plugins to be able support custom node parameters (e.g.: i want to assign to the node some collision shape/shapes, set mass, constant force...)
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

thanks, and some questions and a request...

Post by buhatkj »

Hey I've been trying this out, snagged prolly the first rev of this code a while back and finally got around to giving it a whirl. Thanks!

Also, Zet, I was wondering what the license is on this code? can I use it in my Zlib'ed game project? Also, the mediafire link doesnt seem to be working for the most recent code rev. could somebody re-post the code somewhere?
Once again, Thanks! most useful bullet demo so far IMHOP.
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
GameDude
Posts: 498
Joined: Thu May 24, 2007 12:24 am

Post by GameDude »

Thanks, I've been looking for a bullet tutorial
Kalash
Posts: 11
Joined: Fri Nov 02, 2007 10:58 pm

Post by Kalash »

When I try to compile your example with last irrlicht and bullet, I got errors:
CBulletObjectAnimator.h:69: error: `struct irr::scene::CBulletObjectAnimatorGeometry::<anonymous union>::CSphereGeom' invalid; an anonymous union can only have non-static data members
CBulletObjectAnimator.h:74: error: `struct irr::scene::CBulletObjectAnimatorGeometry::<anonymous union>::CBoxGeom' invalid; an anonymous union can only have non-static data members
CBulletObjectAnimator.h:79: error: `struct irr::scene::CBulletObjectAnimatorGeometry::<anonymous union>::CMesh' invalid; an anonymous union can only have non-static data members
CBulletObjectAnimator.h:: In constructor `irr::scene::CBulletObjectAnimatorParams::CBulletObjectAnimatorParams()':
CBulletObjectAnimator.h:101: warning: `irr::scene::CBulletObjectAnimatorParams::centerOfMassOffset' will be initialized after
CBulletObjectAnimator.h:100: warning: `irr::core::vector3df irr::scene::CBulletObjectAnimatorParams::gravity'
CBulletObjectAnimator.h:92: warning: when initialized here
VagueNess
Posts: 15
Joined: Wed Jan 02, 2008 8:17 pm
Location: Holland

Post by VagueNess »

I get this errors:
cworldeditorgui.cpp(268) : error C2440: 'initializing' : cannot convert from 'irr::core::list<T>::ConstIterator' to 'irr::core::list<T>::Iterator'
with
[
T=irr::scene::ISceneNode *
]
No constructor could take the source type, or constructor overload resolution was ambiguous
Can someone help?
Sorry for any bad English, I'm Dutch.
gbox
Posts: 37
Joined: Mon May 01, 2006 3:41 am
Location: jeonju, korea
Contact:

bullet 2.69 complie error

Post by gbox »

is there any change?

I cant find 2.5.X bullet :(
gbox
Posts: 37
Joined: Mon May 01, 2006 3:41 am
Location: jeonju, korea
Contact:

Post by gbox »

add btDefaultCollisionConfiguration

Code: Select all

 
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
  iCollisionDispatcher = new	btCollisionDispatcher(collisionConfiguration);
btRigidBody modyfied

Code: Select all

 /*
  rigidBody = new btRigidBody(
    physicsParams.mass, 
    motionState, 
    collisionShape, 
    localInertia,
    physicsParams.linearDamping,
    physicsParams.angularDamping,
    physicsParams.friction,
    physicsParams.restitution
  );*/

  rigidBody = new btRigidBody(
    physicsParams.mass, 
    motionState, 
    collisionShape, 
    localInertia);
  rigidBody->setDamping(physicsParams.linearDamping,physicsParams.angularDamping);
  rigidBody->setFriction(physicsParams.friction);
CBullet AnimatorManager.h
modify like this

Code: Select all

// A game application wrapper class
// 1.4.1 support!

#ifndef __C_BULLET_SCENE_NODE_ANIMATOR_FACTORY_H_INCLUDED__
#define __C_BULLET_SCENE_NODE_ANIMATOR_FACTORY_H_INCLUDED__

#include "irrlicht.h"

#include "CBulletWorldAnimator.h"
#include "CBulletObjectAnimator.h"

namespace irr
{
namespace scene
{
  class  ISceneNodeAnimator;
  class  ISceneManager;

  //! An enumeration for all types of built-in scene node animators
  enum ESCENE_NODE_BULLET_ANIMATOR_TYPE
  {
    ESNAT_BULLET_WORLD = 777,
    ESNAT_BULLET_OBJECT,
    ESNAT_BULLET_UNKNOWN
  };

  //!	Interface making it possible to dynamicly create scene nodes animators 
  class CBulletAnimatorManager : public ISceneNodeAnimatorFactory
  {
  public:

    CBulletAnimatorManager(ISceneManager* mgr);
    ~CBulletAnimatorManager();

    //! Create animator
    CBulletWorldAnimator* createBulletWorldAnimator(
      ISceneManager* scenemanager,
      ISceneNode* sceneNode, 
      CBulletWorldAnimatorParams* params
    );
    //! Create animator
    CBulletObjectAnimator* createBulletObjectAnimator(
      ISceneManager* scenemanager, 
      ISceneNode* sceneNode, 
      s32 bulletWorldID,
      CBulletObjectAnimatorGeometry* geometry,
      CBulletObjectAnimatorParams* physicsParams
    );

    //! Remove world from the list
    void removeWorld(CBulletWorldAnimator* world);

    //! Get world by id
    CBulletWorldAnimator* getBulletWorldByID(s32 id);

    //! Update
    void OnUpdate(u32 timeMs);


  private:


    //! creates a scene node animator based on its type id
    /** \param type: Type of the scene node animator to add.
    \param target: Target scene node of the new animator.
    \return Returns pointer to the new scene node animator or null if not successful. You need to
    drop this pointer after calling this, see IUnknown::drop() for details. */
    virtual ISceneNodeAnimator* createSceneNodeAnimator(ESCENE_NODE_ANIMATOR_TYPE type, ISceneNode* target);

    //! creates a scene node animator based on its type name
    /** \param typeName: Type of the scene node animator to add.
    \param target: Target scene node of the new animator.
    \return Returns pointer to the new scene node animator or null if not successful. You need to
    drop this pointer after calling this, see IUnknown::drop() for details. */
    virtual ISceneNodeAnimator* createSceneNodeAnimator(const char* typeName, ISceneNode* target);

    //! returns amount of scene node animator types this factory is able to create
#ifdef  IRR_OLD_13X
    virtual s32 getCreatableSceneNodeAnimatorTypeCount();
#else
	virtual u32 getCreatableSceneNodeAnimatorTypeCount() const;
#endif

    //! returns type of a createable scene node animator type
    /** \param idx: Index of scene node animator type in this factory. Must be a value between 0 and
    getCreatableSceneNodeTypeCount() */
#ifdef  IRR_OLD_13X
    virtual ESCENE_NODE_ANIMATOR_TYPE getCreateableSceneNodeAnimatorType(s32 idx);
#else
	virtual ESCENE_NODE_ANIMATOR_TYPE getCreateableSceneNodeAnimatorType(u32 idx) const;
#endif
	

    //! returns type name of a createable scene node animator type 
    /** \param idx: Index of scene node animator type in this factory. Must be a value between 0 and
    getCreatableSceneNodeAnimatorTypeCount() */
#ifdef  IRR_OLD_13X
    virtual const c8* getCreateableSceneNodeAnimatorTypeName(s32 idx);
#else
	virtual const c8* getCreateableSceneNodeAnimatorTypeName(u32 idx) const;
#endif
	

    //! returns type name of a createable scene node animator type 
    /** \param type: Type of scene node animator. 
    \return: Returns name of scene node animator type if this factory can create the type, otherwise 0. */
#ifdef  IRR_OLD_13X
    virtual const c8* getCreateableSceneNodeAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type);
#else
	virtual const c8* getCreateableSceneNodeAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type) const;
#endif
	


    //! Create empty animators for deserialization
    CBulletWorldAnimator* createEmptyBulletWorldAnimator(
      ISceneManager* scenemanager,
      ISceneNode* sceneNode
    );
    CBulletObjectAnimator* createEmptyBulletObjectAnimator(
      ISceneManager* scenemanager, 
      ISceneNode* sceneNode
    );


    core::list<CBulletWorldAnimator*> bulletWorldAnimators;
    ISceneManager* sceneManager;
  };


} // end namespace scene
} // end namespace irr


#endif //__C_BULLET_SCENE_NODE_ANIMATOR_FACTORY_H_INCLUDED__

Code: Select all

CBulletWorldAnimator::CBulletWorldAnimator(CBulletAnimatorManager* bulletMgr)
: iBulletManager(bulletMgr), iID(-1)
{
#ifdef _DEBUG
  setDebugName("CBulletWorldAnimator");
#endif

#ifdef USE_PARALLEL_DISPATCHER
  iCollisionDispatcher = new	SpuGatheringCollisionDispatcher();
#else

  btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
  iCollisionDispatcher = new	btCollisionDispatcher(collisionConfiguration);

#endif//USE_PARALLEL_DISPATCHER

  //register algorithm
  btGImpactCollisionAlgorithm::registerAlgorithm(iCollisionDispatcher);


  btVector3 aWorldMin(-10000,-10000,-10000);
  btVector3 aWorldMax(10000,10000,10000);
  iPairCache = new btAxisSweep3(aWorldMin,aWorldMax);
  //btOverlappingPairCache* aPairCache = new btAxisSweep3(aWorldMin,aWorldMax);

  //iPairCache = new btSimpleBroadphase(); 

  iConstraintSolver = new btSequentialImpulseConstraintSolver();
  iDynamicsWorld = new btDiscreteDynamicsWorld(
	  iCollisionDispatcher, 
	  iPairCache,	  
	  iConstraintSolver,
	  collisionConfiguration
	  );

#ifdef USE_PARALLEL_DISPATCHER
  iDynamicsWorld->getDispatchInfo().m_enableSPU=true;
#endif //USE_PARALLEL_DISPATCHER
}
I successed complied with bullet 2.6.9 + irrlicht 1.4.1
Last edited by gbox on Mon Jul 28, 2008 3:57 pm, edited 1 time in total.
http://cafe.naver.com/jcga

professor of Jelabukdo Game Engine Academy
gbox
Posts: 37
Joined: Mon May 01, 2006 3:41 am
Location: jeonju, korea
Contact:

Post by gbox »

to integrate TerrainSecneNode


add code to CBulletObjectAnimator::CreateBulletCollisionShape() fuction

Code: Select all


case CBPAGT_CONCAVE_LOD_TERRAIN_MESH:
		{
			//mesh converting
			{
				btVector3 vertices[3];
				irr::u32 j,k,index,numVertices,numIndices;
				irr::u16* mb_indices;

				irr::scene::ITerrainSceneNode *pTerrain = 
					(irr::scene::ITerrainSceneNode *)pSceneManager->getSceneNodeFromName(pGeom->meshFile.c_str());

				irr::scene::SMeshBufferLightMap smb;
				pTerrain->getMeshBufferForLOD(smb,pGeom->terrain_mesh.meshLod);				

				numVertices = smb.getVertexCount ();//mb->getVertexCount();
				numIndices = smb.getIndexCount();//mb->getIndexCount();
				mb_indices = smb.getIndices();// mb->getIndices();
				irr::video::S3DVertex2TCoords* mb_vertices = 
					(irr::video::S3DVertex2TCoords*)smb.getVertices();// ->getVertices();

				{
					btTriangleMesh *pTriMesh = new btTriangleMesh();

					irr::core::vector3df scaling = pScaling;

					for(j=0;j<numIndices;j+=3)
					{ //index into irrlicht data
						for (k=0;k<3;k++) 
						{
							index = mb_indices[j+k];
							// we apply scaling factor directly to verticies
							vertices[k] = btVector3(mb_vertices[index].Pos.X*scaling.X,
								mb_vertices[index].Pos.Y*scaling.Y,
								mb_vertices[index].Pos.Z*scaling.Z);
						}
						pTriMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
					}
					triangleMesh = pTriMesh;
				}
			}
			
			bool useQuantizedAabbCompression = true;
			collisionShape = new btBvhTriangleMeshShape(triangleMesh, useQuantizedAabbCompression);
		}
		break;

Last edited by gbox on Mon Jul 28, 2008 4:00 pm, edited 1 time in total.
http://cafe.naver.com/jcga

professor of Jelabukdo Game Engine Academy
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

i just downloaded the code and will set up the bullet beside it.

thank you.
Image
Post Reply