BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
chaosavy
Silver Sponsor
Silver Sponsor
Posts: 578
Joined: Mon Jun 15, 2009 8:29 pm
x 64
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by chaosavy »

Nikki, thank you very much for this great code. Currently I'm using it for collision only to create the shapes to use with bullet. I've ran into a problem that I'd like to hear some different view points on, because I think I'm missing something very simple.

I have a "carrier" type space ship and a "fighter" type space ship, the mesh for the carrier has a long tube like "landing deck" that has an opening going front to end. I'd like to fly the fighter in and out of this open tube but unfortunatley trying this triggers a collision (even though the tube is big enough to accomodate the landing ship), I'm thinking of shooting a triangle detecting ray when this happens for this particular class of ship etc to determine if the fighter should be able to move further into the carrier, but I'm wondering if I'm missing something simpler.

Another question: whenever I try to do .createTrimesh the resulting shape doesn't seem to work for me, there is no collision detected between objects. Any ideas? Is this because I'm using collision only?

anyway thanks again
Visit http://www.VoidDestroyer.com to check out my space sim project - Void Destroyer
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

Well, if .createTrimesh doesn't work for you, then you're most probably using a convex shape, and so 'holes' don't exist. You'll either have to get trimesh working, or break up the tube into smaller convex shapes.

Why doesn't timesh work anyway? How do you check collisions?
User avatar
chaosavy
Silver Sponsor
Silver Sponsor
Posts: 578
Joined: Mon Jun 15, 2009 8:29 pm
x 64
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by chaosavy »

Initializing bullet

Code: Select all

	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
	btVector3	worldAabbMin(-20000,-20000,-20000);
	btVector3	worldAabbMax(20000,20000,20000);

	btAxisSweep3*	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);

	collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
Adding collision shape

Code: Select all

	BtOgre::StaticMeshToShapeConverter converter(entity);

	btBvhTriangleMeshShape* shapeTMP=converter.createTrimesh();

	btMatrix3x3 basisA;
	basisA.setIdentity();

	newBody.btColObj = new btCollisionObject;
	newBody.btColObj->getWorldTransform().setBasis(basisA);
	newBody.btColObj->setCollisionShape(shapeTMP);
	collisionWorld->addCollisionObject(newBody.btColObj);

	//Initial position
	newBody.btColObj->getWorldTransform().setOrigin(btVector3(newBody.prevPos.x, newBody.prevPos.y, newBody.prevPos.z));


Testing for collisions

Code: Select all


	if (collisionWorld)
		collisionWorld->performDiscreteCollisionDetection();


	int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
	int i;
	for (i=0;i<numManifolds;i++)
	{
		btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

		Ogre::Entity *a=static_cast<Ogre::Entity*>(obA->getUserPointer());
		Ogre::Entity *b=static_cast<Ogre::Entity*>(obB->getUserPointer());

		int mover = findBody(a); //Need to get the previous position, entities and scene nodes
		int hit = findBody(b); //Need to get the previous position, entities and scene nodes

		//This gets collisions to be much closer
		/* Check all contacts points */
		int numContacts = contactManifold->getNumContacts();
		for (int j=0;j<numContacts;j++)
		{
			btManifoldPoint& pt = contactManifold->getContactPoint(j);

			if (pt.getDistance()<0.f)
			{
				collision(timeSinceLastFrame, mover, a, hit, b);
				break;
	      		}
		 }
	}

This works for convex shapes, but not trimesh, is there something unique/different about trimesh that I'm missing?
Visit http://www.VoidDestroyer.com to check out my space sim project - Void Destroyer
kurty
Gnoblar
Posts: 14
Joined: Thu Nov 12, 2009 1:50 am

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by kurty »

Hi i'm trying to use BtOgre, but i'm missing some samples to understand well how it is working.

How's your mesh position updated in your sample ? (i don't see any code in FrameStarted that would do that)

Anyone else tried to use heightmap with Bullet by the way ?
Communauté Francophone
#ogre3d-fr sur irc.freenode.net
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

kurty wrote:How's your mesh position updated in your sample ? (i don't see any code in FrameStarted that would do that)
BtOgre handles that. Bullet calls an internal callback in BtOgre which updates positions of objects. This way, updates are not missed. All you have to do is create the object and associate it with the SceneNode. The idea of associating the SceneNode with the RigidBody using BtOgre is to introduce this auto-update. Otherwise there's no point. :P

And chaosavy, try asking on the Bullet forums, I've never really used Bullet as an only-collision-lib myself, so I'm not sure exactly what you should do here.
kurty
Gnoblar
Posts: 14
Joined: Thu Nov 12, 2009 1:50 am

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by kurty »

nikki where is located this callback ? when we do what ?
before using btogre i was updating my player with :
mNode->translate(mTransVector * mPlayerWalkSpeed * (float)evt.timeSinceLastFrame);
i setted up btogre in my player constructor but i don't know how to move his shape.

Here is a screen :

Image

I removed all player/ennemies update in their own class, so i'm sure i don't move them with ogre3d.
As i think i can see on this debug screenshot (btogre debug), my robots mesh are floating in the air while their shape (sphere) are on the ground (terrain made with heightmap).
Communauté Francophone
#ogre3d-fr sur irc.freenode.net
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

Show me your creation code for the robot entity/scenenode/rigidbody/shape.
kurty
Gnoblar
Posts: 14
Joined: Thu Nov 12, 2009 1:50 am

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by kurty »

Ok i found my error, it was i'm creating my node like this :

Code: Select all

	mEntity = mSceneMgr->createEntity(name, meshName);
	mNode = mSceneMgr->getRootSceneNode( )->createChildSceneNode("BaseNode_"+mNodeName, ennemyPos, rot);
	meshNode = mNode->createChildSceneNode("MeshNode_"+mNodeName);
    meshNode->attachObject(mEntity);
And i was doing :

Code: Select all

BtOgre::RigidBodyState *ennemyState = new BtOgre::RigidBodyState(meshNode);
instead of

Code: Select all

BtOgre::RigidBodyState *ennemyState = new BtOgre::RigidBodyState(mNode);
Communauté Francophone
#ogre3d-fr sur irc.freenode.net
User avatar
rogerdv
Gnome
Posts: 351
Joined: Fri May 09, 2003 10:43 pm
Location: Cuba
x 1
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by rogerdv »

kurty, why do you use 2 nodes?
kurty
Gnoblar
Posts: 14
Joined: Thu Nov 12, 2009 1:50 am

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by kurty »

that's an advice i've been told to use.

I'm actually working on the sample demo made by nikki in order to learn.
I can't get my mesh moving from my keyboard entries... it would really be cool to have some more advanced code samples.

My modified class BtOgreTestApplication:

Code: Select all

class BtOgreTestApplication : public ExampleApplication
{
    protected:
	btAxisSweep3 *mBroadphase;
	btDefaultCollisionConfiguration *mCollisionConfig;
	btCollisionDispatcher *mDispatcher;
	btSequentialImpulseConstraintSolver *mSolver;

	Ogre::SceneNode *mNinjaNode;
	Ogre::Entity *mNinjaEntity;
	btRigidBody *mNinjaBody;
	btCollisionShape *mNinjaShape;

	Ogre::Entity *mGroundEntity;
	btRigidBody *mGroundBody;
	btCollisionShape *mGroundShape;

    public:

	void chooseSceneManager()
	{
		mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE);
	}
	BtOgreTestApplication()
	{
	    //Bullet initialisation.
	    mBroadphase = new btAxisSweep3(btVector3(-10000,-10000,-10000), btVector3(10000,10000,10000), 1024);
	    mCollisionConfig = new btDefaultCollisionConfiguration();
	    mDispatcher = new btCollisionDispatcher(mCollisionConfig);
	    mSolver = new btSequentialImpulseConstraintSolver();

	    Globals::phyWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfig);
	    Globals::phyWorld->setGravity(btVector3(0,-9.8,0));
	}

	~BtOgreTestApplication()
	{
	    //Free Bullet stuff.
	    delete mSolver;
	    delete mDispatcher;
	    delete mCollisionConfig;
	    delete mBroadphase;
	}

    protected:
	void createScene(void)
	{
	    //Some normal stuff.
	    mSceneMgr->setAmbientLight(ColourValue(0.7,0.7,0.7));
	    mCamera->setPosition(Vector3(10,50,10));
	    mCamera->lookAt(Vector3::ZERO);
	    mCamera->setNearClipDistance(0.05);
	    LogManager::getSingleton().setLogDetail(LL_BOREME);


	    //----------------------------------------------------------
	    // Debug drawing!
	    //----------------------------------------------------------

	    Globals::dbgdraw = new BtOgre::DebugDrawer(mSceneMgr->getRootSceneNode(), Globals::phyWorld);
	    Globals::phyWorld->setDebugDrawer(Globals::dbgdraw);

	    //----------------------------------------------------------
	    // Ninja!
	    //----------------------------------------------------------

	    Vector3 pos = Vector3(0,100,0);
	    Quaternion rot = Quaternion::IDENTITY;

	    //Create Ogre stuff.

	    mNinjaEntity = mSceneMgr->createEntity("ninjaEntity", "ninja.mesh");//"Player.mesh");
	    mNinjaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ninjaSceneNode", pos, rot);
		mNinjaNode->scale(0.035,0.035,0.035);
	    mNinjaNode->attachObject(mNinjaEntity);

	    //Create shape.
	    BtOgre::AnimatedMeshToShapeConverter converter(mNinjaEntity);
		mNinjaShape = converter.createConvex();

		// Scale
		btVector3 scale(0.035,0.035,0.035);
		mNinjaShape->setLocalScaling(scale);

	    //Calculate inertia.
	    btScalar mass = 5;
	    btVector3 inertia;
	    mNinjaShape->calculateLocalInertia(mass, inertia);

	    //Create BtOgre MotionState (connects Ogre and Bullet).
	    BtOgre::RigidBodyState *ninjaState = new BtOgre::RigidBodyState(mNinjaNode);

	    //Create the Body.
	    mNinjaBody = new btRigidBody(mass, ninjaState, mNinjaShape, inertia);
	    Globals::phyWorld->addRigidBody(mNinjaBody);

	    //----------------------------------------------------------
	    // Load terrain!
	    //----------------------------------------------------------
		std::string terrainFileStr = "terrain.cfg";

		mSceneMgr->setWorldGeometry( terrainFileStr );

		
		// terrainFileStr is a string, representing the file name of *.cfg file to  be used by TerrainSceneManager

		// Load the *.cfg file into a ConfigFile object
		//terrainSceneManager->setWorldGeometry(terrainFileStr);

		Ogre::DataStreamPtr configStream = Ogre::ResourceGroupManager::getSingleton().openResource(terrainFileStr, Ogre::ResourceGroupManager::getSingleton().getWorldResourceGroupName());
		Ogre::ConfigFile config;
		config.load(configStream);

		/* Load the various settings we need.
		* These are:
		* width:  Saved in the terrainFile as PageSize.  We pass width to Bullet twice, as both width and height,
		*     because heightfields in Ogre are square.
		* imgFileStr: the string representing the image from which we want to load the heightmap data.
		* heightmap: an Ogre::Image object, which contains the data itself.  A reference to this needs to be kept
		*     somewhere, because just keeps a pointer to the data, and the data itself will be deleted when the
		*     Image is deleted at the end of this block.  I found this out the hard way >.>
		* maxHeight: the heightmap will be scaled to go from zero to maxHeight
		* heightScale: this is how much each number in the heightmap (0 - 255) will translate to in Ogre/Bullet units.
		*    This number is obtained by dividing the maxHeight by 256 which is the total number of different steps in
		*    the heightmap before interpolation.
		*/
		Ogre::String widthStr = config.getSetting("PageSize");
		int width = atoi(widthStr.c_str());

		Ogre::String imgFile = config.getSetting("Heightmap.image");

		Ogre::Image* heightmap = new Ogre::Image();
		heightmap->load("terrain.png", Ogre::ResourceGroupManager::getSingleton().getWorldResourceGroupName());

		Ogre::String maxHeightStr = config.getSetting("MaxHeight");
		btScalar maxHeight = atof(maxHeightStr.c_str());
		btScalar heightScale = maxHeight / 256;

		// This code for the localScaling is taken directly from the TerrainSceneManager, adapted
		//      to a btVector3
		//EDIT: Thanks to Ripgiblet for pointing out and fixing some mistakes in this section.
		btVector3 localScaling(1, 1, 1);
		btScalar vScaleX = atof(config.getSetting("PageWorldX").c_str());
		vScaleX /= width - 1;
		btScalar vScaleZ = atof(config.getSetting("PageWorldZ").c_str());
		vScaleZ /= width - 1;
		localScaling.setX(vScaleX);
		localScaling.setZ(vScaleZ);


		// And now, we actually call Bullet.
		// I've actually used btHeightfieldTerrainShape's legacy constructor, but really, it works so well
		//      with the way Ogre used Heightmaps
		mGroundShape = new btHeightfieldTerrainShape(width, width, heightmap->getData(), heightScale, 0, maxHeight, 1, PHY_UCHAR, false);
		mGroundShape->setLocalScaling(localScaling);

		// All thats left is to line up the Ogre::SceneNode with the btHeightfieldTerrainShape.
		// We have to do it this way because of differences in how Bullet and Ogre orient the shapes.
		// In Ogre, the terrain's top left corner is at (0, 0, 0) in the local TransformSpace
		// In Bullet, not only is the center of the btHeighfield terrrain shape at (0, 0, 0), but from
		//      what I can tell, its immovable.
		btVector3 min, max;
		mGroundShape->getAabb(btTransform::getIdentity(), min, max);
		SceneNode *sNode = mSceneMgr->getSceneNode("Terrain");
		sNode->setPosition(BtOgre::Convert::toOgre(min));

		// Finally, create your btMotionState, and btRigidBody, and all the rigid body to the physics world.
		BtOgre::RigidBodyState* terrainState = new BtOgre::RigidBodyState(sNode, btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
		mGroundBody = new btRigidBody(0, terrainState, mGroundShape, btVector3(0, 0, 0));
		mGroundBody->setCollisionFlags(mGroundBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
		Globals::phyWorld->addRigidBody(mGroundBody);
		
	}

	void createFrameListener(void)
	{
	    mFrameListener = new BtOgreTestFrameListener(mWindow, mCamera, mSceneMgr, mNinjaBody);
	    mRoot->addFrameListener(mFrameListener);
	}
};
my modified BtOgreTestFrameListener :

class BtOgreTestFrameListener : public ExampleFrameListener
{
public:
BtOgreTestFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr, btRigidBody *NinjaBody)
: ExampleFrameListener(win, cam, false, false)
{
mTrans.setValue(0, 0, 0);
mNinjaBody = NinjaBody;
mSceneMgr = sceneMgr;

}

protected:
btVector3 mTrans;
SceneManager *mSceneMgr;
btRigidBody *mNinjaBody;
static const int mMove = 2;

bool frameStarted(const FrameEvent &evt)
{
if (mKeyboard->isKeyDown(OIS::KC_L))
{
//mTrans.setValue(2, 0, 0);
mTrans[0] += mMove;
}
if (mKeyboard->isKeyDown(OIS::KC_J))
{
//mTrans.setValue(-2, 0, 0);
mTrans[0] -= mMove;
}
if (mKeyboard->isKeyDown(OIS::KC_I))
{
//mTrans.setValue(0, 0, 2);
mTrans[2] += mMove;
}
if (mKeyboard->isKeyDown(OIS::KC_K))
{
//mTrans.setValue(0, 0, -2);
mTrans[2] -= mMove;
}

//pur ogre
//mNinjaNode->translate(mTrans * evt.timeSinceLastFrame);


//mNinjaBody->applyCentralForce(mTrans * evt.timeSinceLastFrame);
mNinjaBody->translate(mTrans * evt.timeSinceLastFrame);


//Update Bullet world. Don't forget the debugDrawWorld() part!
Globals::phyWorld->stepSimulation(evt.timeSinceLastFrame, 10);
Globals::phyWorld->debugDrawWorld();

//Shows debug if F3 key down.
Globals::dbgdraw->setDebugMode(mKeyboard->isKeyDown(OIS::KC_F3));
Globals::dbgdraw->step();
mTrans.setValue(0, 0, 0);
return ExampleFrameListener::frameStarted(evt);
}
};

With this code, it seems the mesh move at the beginning but it stops few seconds later...

If someone can check this code and tell me what's wrong? thx for advance.
Communauté Francophone
#ogre3d-fr sur irc.freenode.net
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

Your physics engine is handling the motion now. :D You talk with it through forces and impulses. To make the body move, do something like 'mBody->applyCentralForce(mKeyboard->isKeyDown(OIS::KC_UP) * Ogre::Vector3(0,100,0))'.

Anyway, BtOgre is just the Bullet<->Ogre connection. The physics is Bullet. To learn how to use Bullet, see Bullet examples.. BtOgre is only a thin layer. Check out the Bullet wiki and forums for some more info.
kurty
Gnoblar
Posts: 14
Joined: Thu Nov 12, 2009 1:50 am

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by kurty »

As you can see , i tried mNinjaBody->applyCentralForce(mTrans * evt.timeSinceLastFrame); but the result was that node and shape wasn't synchronised after few keyboard entries.
Communauté Francophone
#ogre3d-fr sur irc.freenode.net
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

kurty wrote:As you can see , i tried mNinjaBody->applyCentralForce(mTrans * evt.timeSinceLastFrame); but the result was that node and shape wasn't synchronised after few keyboard entries.
You don't have to multiply the force by timeSinceLastFrame.
User avatar
chaosavy
Silver Sponsor
Silver Sponsor
Posts: 578
Joined: Mon Jun 15, 2009 8:29 pm
x 64
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by chaosavy »

I did post in the bullet forum and did a bit of searching, turns out that trimeshes can't collide with trimeshes, so I can follow my original thought of shooting a triangle detecting ray when a ship that should be able to enter the landing deck collides with the carrier, or I was thinking of creating two seperate collision objects (yet in the same position) for the carrier, one convex, and one trimesh. The trimesh shape would be for convex fighter ships attempting to dock, and the convex shapes would be for collisions between two carriers/cap ships against their convex shapes. I think that there is some flagging functionality that you can specify what the collision shape will collide with.
Visit http://www.VoidDestroyer.com to check out my space sim project - Void Destroyer
Garibalde
Halfling
Posts: 69
Joined: Thu Apr 16, 2009 2:38 am
Location: Montreal, Quebec
x 2
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by Garibalde »

Hi all,

I am using Nikki's demo and fooling around with the bullet and ogre functionality before i decide to use it in my project.
I change the object in the demo from Player.mesh to scalpel.mesh. The scalpel has the axis system to be at the tip of the
scalpel. As i read before this causes the created bounding box (i used a createbox) to be centered about the axis system
of the mesh causing the collision detection to be messed up.

Question:
Is there a way to offset the axis system for bullet? I need the axis system to be at the tip for other reasons.
The objects i use are scaled using setscale() on the node.. how do i translate this information to bullet when i create the rigid bodies?

A second question is something that was asked above also. I am trying to manually drive the scalpel object with keyboard inputs.
From what i understand i will need to set the bullet attributes such as velocity and this inturn calcualtes collision and draws the object
in ogre as necessary.

Question:
I can calculate the velocity of the inputs from the previous and current step divided by the delta t for velocity, is there any other way?
I no longer have to do setPosition and setOrientation on the Ogre SceneNode this is done automatically with btOgre and bullet? right?

If anyone has some source code examples i could use. Please let me know.

Thanks for any replies or assistance in advance.
Garibalde

P.S
Nikki great job on the wrapper for bullet-ogre. make things so much easier (well so far) :)
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

Garibalde wrote:Is there a way to offset the axis system for bullet? I need the axis system to be at the tip for other reasons.
The objects i use are scaled using setscale() on the node.. how do i translate this information to bullet when i create the rigid bodies?
Unless you have a good reason to keep the origin at the tip, why not keep the origin at the center? Usually you'd like meshes to have origin at center. If you need any offset, you create a child SceneNode.
Garibalde wrote:A second question is something that was asked above also. I am trying to manually drive the scalpel object with keyboard inputs.
From what i understand i will need to set the bullet attributes such as velocity and this inturn calcualtes collision and draws the object
in ogre as necessary.

Question:
I can calculate the velocity of the inputs from the previous and current step divided by the delta t for velocity, is there any other way?
I no longer have to do setPosition and setOrientation on the Ogre SceneNode this is done automatically with btOgre and bullet? right?
You can use body->setWorldTransform(...) or body->getMotionState()->setWorldTransform(...) to set position/orientation. If you don't really want the dynamics (bouncing around, gravity, forces), consider using collision-only Bullet or 'kinematic objects' (read more about this on the Bullet forums).

From here on it's mostly Bullet stuff. The Bullet resources linked in previous posts will help.
Champi Atomik
Kobold
Posts: 38
Joined: Thu Sep 10, 2009 3:29 pm

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by Champi Atomik »

Hello

I'm using BtOgre in my Ogre3d project, it works very well, but the "jump" doesn't work. I took a look at the library files, and the linecodes are in comments. I tried to put these lines into my project, it compile but doesn't work, it can't do the "mRigidBody->applyCentralImpulse(up)".

Did someone have this problem and can help me ?

Thank you
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

Does physics 'generally work' (bodies fall, collide etc.)? Have you tried applying a larger impulse (maybe like btVector3(0,200,0))?
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by jacmoe »

BtOgre doesn't have a wiki page yet? :)
If it doesn't, I'll make one.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

No, AFAIK, it doesn't.

You're gonna make one? Cool! :D But I won't be able to contribute much until end of January. We've got exams and stuff, really busy these days. :(
Champi Atomik
Kobold
Posts: 38
Joined: Thu Sep 10, 2009 3:29 pm

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by Champi Atomik »

Yes the collisions and fall work very well.

The code compile, but when I try to jump, I have a "violated access error" , that come from the lines :

in btVector3.h

Code: Select all

SIMD_FORCE_INLINE btVector3 
operator*(const btVector3& v1, const btVector3& v2) 
{
	return btVector3(v1.m_floats[0] * v2.m_floats[0], v1.m_floats[1] * v2.m_floats[1], v1.m_floats[2] * v2.m_floats[2]);
}
in btRigidBody.h

Code: Select all

void applyCentralImpulse(const btVector3& impulse)
	{
		m_linearVelocity += impulse *m_linearFactor * m_inverseMass;
	}
To make the character jump i do "mPlayerBody->applyCentralImpulse(upDir);"

But when I add the line "btScalar magnitude = (btScalar(1.0)/mPlayerBody->getInvMass()) * btScalar(8.0);" before,
the code compile but I have another error in btRigidBody.h

Code: Select all

btScalar		getInvMass() const { return m_inverseMass; }
Maybe it is because of the m_inverseMass, that is also used in the "applyCentralImpulse" function ?

Or perhaps do you have another method do make a character jump using btOgre ?

Thanks

Edit : Here is the code about the character's creation into Bullet

Code: Select all

btTransform startTransform;
	startTransform.setIdentity ();
	startTransform.setOrigin (btVector3(0.0,100.0,0.0));
	mPlayerGhost = new btPairCachingGhostObject();
	mPlayerGhost->setWorldTransform(startTransform);
	mPhyWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
	mPlayerShape = new btCapsuleShape(mPlayerEntity->getBoundingRadius()/4,mPlayerEntity->getBoundingRadius()/4);
	mPlayerState = new BtOgre::RigidBodyState(mPlayerNode);
	mPlayerGhost->setCollisionShape (mPlayerShape);
	mPlayerGhost->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);
	btScalar stepHeight = btScalar(0.25);
	mPlayerController = new btKinematicCharacterController (mPlayerGhost,mPlayerShape,stepHeight);

	mPhyWorld->addCollisionObject(mPlayerGhost,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
	mPhyWorld->addAction(mPlayerController);
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

I don't think it's a BtOgre problem. You should try asking on the Bullet forums (I don't have much time these days to help :( ).
Champi Atomik
Kobold
Posts: 38
Joined: Thu Sep 10, 2009 3:29 pm

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by Champi Atomik »

Ok thanks, i'll try, but someone doesn't have any idea about another way to make a character jumping ?

I tried to add "mPlayerShape->calculateLocalInteria()" but it still doesn't work.

Edit : Maybe it is because it is a Kinematic controller and not a dynamic, that's why i can't apply an impulse on it ?
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by nikki »

Champi Atomik wrote:Edit : Maybe it is because it is a Kinematic controller and not a dynamic, that's why i can't apply an impulse on it ?
Aha! Yup, that's it. :P You'll have to manuall do a 'jump' move by calculating the positions yourself.
Champi Atomik
Kobold
Posts: 38
Joined: Thu Sep 10, 2009 3:29 pm

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Post by Champi Atomik »

Ok, thanks for your quick answers !

Should I use dynamic character controller (if it exists) or make it jump by myself ?

Because now I tried to do it on my own, but when the character is in the air, he's fall speed is really really slow, even if I use "setFallSpeed" or if I increase the gravity. Does someone have any idea about this ?

Thanks

Edit : Here is my Bullet initialisation code

Code: Select all

mBroadphase = new btAxisSweep3(btVector3(-10000,-10000,-10000), btVector3(10000,10000,10000), 1024);
	    mCollisionConfig = new btDefaultCollisionConfiguration();
	    mDispatcher = new btCollisionDispatcher(mCollisionConfig);
	    mSolver = new btSequentialImpulseConstraintSolver();

	    Globals::phyWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfig);
	    Globals::phyWorld->setGravity(btVector3(0,-9.81,0));
Post Reply