Ogre + Bullet, gravity

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
ENGine
Goblin
Posts: 266
Joined: Fri Jan 27, 2006 9:13 pm
Location: Belarus
x 2
Contact:

Ogre + Bullet, gravity

Post by ENGine »

Hi, all.

I'm creating wrapper for working with Ogre+Bullet for iOS platform.
I created 2 objects:
- dynamic:

Code: Select all

btVector3 inertia;
    shape->calculateLocalInertia(_mass, inertia);
	
    MyMotionState *motionState = new MyMotionState(_node.node);
    body = new btRigidBody(_mass, motionState, shape, inertia);
    body->setUserPointer((__bridge void *)_node);
	_world.world->addRigidBody(body);
- static(wall):

Code: Select all

Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
	Ogre::MeshPtr planePtr = Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
	
	Ogre::Entity *entGround = mSceneMgr.mSceneMgr->createEntity("GroundEntity", "ground");
	Ogre::SceneNode *groundNode = mSceneMgr.mSceneMgr->getRootSceneNode()->createChildSceneNode("groundNode");

	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0, -800, 0));
	
	btScalar groundMass(0.); //the mass is 0, because the ground is immovable (static)
	btVector3 localGroundInertia(0, 0, 0);
	
	btCollisionShape *groundShape = new btBoxShape(btVector3(btScalar(1400.), btScalar(50.), btScalar(1000.)));
	btDefaultMotionState *groundMotionState = new btDefaultMotionState(groundTransform);
	
	groundShape->calculateLocalInertia(groundMass, localGroundInertia);
	
	btRigidBody::btRigidBodyConstructionInfo groundRBInfo(groundMass, groundMotionState, groundShape, localGroundInertia);
	btRigidBody *groundBody = new btRigidBody(groundRBInfo);
	
	mWorld.world->addRigidBody(groundBody);
When I set gravity like (0, -9.8, 0), my dynamic object is falling very-very slowly.
Please, have a look video: http://moevideo.net/video/97940.94cc239 ... 05f0982431

I had to set gravity vector to (0, -300, 0), then object is falling ok. But I don't like this decision. Maybe size of my objects are wrong and so on.
Please, help. Thanks
NotCamelCase
Greenskin
Posts: 140
Joined: Sun Feb 03, 2013 6:32 pm
x 8

Re: Ogre + Bullet, gravity

Post by NotCamelCase »

Not a direct answer but were you unhappy with BtOgre or OgreBullet which I and others use easily as wrapper around Bullet ?
Check out my projects: https://github.com/NotCamelCase
User avatar
ENGine
Goblin
Posts: 266
Joined: Fri Jan 27, 2006 9:13 pm
Location: Belarus
x 2
Contact:

Re: Ogre + Bullet, gravity

Post by ENGine »

The thing is that I wrote the wrapper for iOS (objective-c)- iOgre3d for working with Ogre. That is why I decided to use Bullet for my wrapper without completed btOgre or OgreBullet.
NotCamelCase
Greenskin
Posts: 140
Joined: Sun Feb 03, 2013 6:32 pm
x 8

Re: Ogre + Bullet, gravity

Post by NotCamelCase »

ENGine wrote:The thing is that I wrote the wrapper for iOS (objective-c)- iOgre3d for working with Ogre. That is why I decided to use Bullet for my wrapper without completed btOgre or OgreBullet.
Got it. I can't see a problem there, how is your MotionState updating SceneNode ? That's how I create physics objects, in case you notice something wrong.

Code: Select all

   m_logger->logMessage("Setting up physics " + object->getID());
	auto params = m_godLoader->getGameObjectDefinitionByTag(object->getTag())->getParameters();
	const Real mass = StringConverter::parseReal(params["mass"]);
	const bool dynamic = mass == 0 ? false : true;
	const bool animated = StringConverter::parseBool(params["animated"]);

	const String collisionShape = params["collision-shape"];
	btVector3 inertia(0, 0, 0);
	btRigidBody* body = NULL;
	btCollisionShape* colShape = NULL;
	RigidBodyState* motionState = NULL;

	colShape = createCollisionShape(object->getEntity(), collisionShape, animated);
	motionState = new RigidBodyState(object->getNode());

	if (dynamic)
	{
		colShape->calculateLocalInertia(mass, inertia);
	}

	body = new btRigidBody(mass, motionState, colShape, inertia);
	body->setUserPointer(object);
Check out my projects: https://github.com/NotCamelCase
User avatar
ENGine
Goblin
Posts: 266
Joined: Fri Jan 27, 2006 9:13 pm
Location: Belarus
x 2
Contact:

Re: Ogre + Bullet, gravity

Post by ENGine »

It seems to me that the reason is not MotionState. Because, all scenenodes are not visible. I'm working with btRigidBody only.
there is a trouble connected with Physics only.
NotCamelCase
Greenskin
Posts: 140
Joined: Sun Feb 03, 2013 6:32 pm
x 8

Re: Ogre + Bullet, gravity

Post by NotCamelCase »

Did you compare transform of the btRigidBody and your dynamic node ? Is it correct ? Scene node may not be updated accordingly if there is a problem in your motion state. I don't think there's any problem related to Bullet. What is the mass value you pass there ?
Check out my projects: https://github.com/NotCamelCase
User avatar
ENGine
Goblin
Posts: 266
Joined: Fri Jan 27, 2006 9:13 pm
Location: Belarus
x 2
Contact:

Re: Ogre + Bullet, gravity

Post by ENGine »

So, guys,

If I'm not mistaken the "motion state" class is necessary for updating graph's node by physic's body. But the thing is that I'm working with native bullet code without Ogre3d.

Static ground floor:

Code: Select all

btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0, -800, 0));
	
	btScalar groundMass(0.); //the mass is 0, because the ground is immovable (static)
	btVector3 localGroundInertia(0, 0, 0);
	
	//btCollisionShape *groundShape = new btBoxShape(btVector3(btScalar(30.), btScalar(5.), btScalar(10.)));
	btCollisionShape *groundShape = new btBoxShape(btVector3(btScalar(3000.), btScalar(50.), btScalar(1000.)));
	btDefaultMotionState *groundMotionState = new btDefaultMotionState(groundTransform);
	
	groundShape->calculateLocalInertia(groundMass, localGroundInertia);
	
	btRigidBody::btRigidBodyConstructionInfo groundRBInfo(groundMass, groundMotionState, groundShape, localGroundInertia);
	btRigidBody *groundBody = new btRigidBody(groundRBInfo);
	
	//add the body to the dynamics world
	mWorld.world->addRigidBody(groundBody);
Dynamic box:

Code: Select all

btCollisionShape* shape;
btVector3 size(276, 355, 175);
btVector3 HalfExtents(size.x*0.5f,size.y*0.5f,size.z*0.5f);
btVector3 inertia;

float _mass = 90.0f;
    shape->calculateLocalInertia(_mass, inertia);
	
_node.node->setVisible(false);
    MyMotionState *motionState = new MyMotionState(_node.node);
    body = new btRigidBody(_mass, motionState, shape, inertia);
shape = new btBoxShape(HalfExtents);

_world.world->addRigidBody(body);
MyMotionState class:

Code: Select all

#pragma once

#include "btBulletDynamicsCommon.h"
#include "Bullet-C-Api.h"
#include "btBulletCollisionCommon.h"

#include "Ogre.h"

class MyMotionState : public btMotionState
{
    public:
        MyMotionState(Ogre::SceneNode* node)
        {
                mNode = node;
                mTrans.setIdentity();
        }
        virtual ~MyMotionState()
        { }
        virtual void getWorldTransform(btTransform &worldTrans) const
        {
                worldTrans = mTrans;
        }
        virtual void setWorldTransform(const btTransform &worldTrans)
        {
                mTrans = worldTrans;
                btQuaternion ori = mTrans.getRotation();
                btVector3 pos = mTrans.getOrigin();
                mNode->setPosition(Ogre::Vector3(pos.x(),pos.y(),pos.z()));
                mNode->setOrientation(Ogre::Quaternion(ori.w(),ori.x(),ori.y(),ori.z()));
        }
 
    protected:
        Ogre::SceneNode* mNode;
        btTransform mTrans;
};
But I would like to repeat now I don't attach SceneNode to Physics body. I draw only physics primitive by

Code: Select all

debugDrawer->setDebugMode(GLDebugDrawer::DBG_DrawWireframe);
	world->setDebugDrawer(debugDrawer);
Why is my object for gravity (0, -9.8, 0) so slowed ?
User avatar
ENGine
Goblin
Posts: 266
Joined: Fri Jan 27, 2006 9:13 pm
Location: Belarus
x 2
Contact:

Re: Ogre + Bullet, gravity

Post by ENGine »

Thus, the dynamic object is:
Mass = 90
Size = (138, 177, 87)
The object is on height = 800
Gravity = (0, -9.8, 0)

It's falling so slowly (https://vimeo.com/101705551). I'm sure that it's wrong effect. Please, help.
NotCamelCase
Greenskin
Posts: 140
Joined: Sun Feb 03, 2013 6:32 pm
x 8

Re: Ogre + Bullet, gravity

Post by NotCamelCase »

Hmm yes if you're not using scene nodes then the problem must be physics world related. You can try to downsize the dynamic object, see if it falls down correctly. If so, it may be a scaling issue. I also suggest check the stepping the world docs.
Check out my projects: https://github.com/NotCamelCase
User avatar
ENGine
Goblin
Posts: 266
Joined: Fri Jan 27, 2006 9:13 pm
Location: Belarus
x 2
Contact:

Re: Ogre + Bullet, gravity

Post by ENGine »

Hi,

To my mind I'am mistaken.
S= g*t^2/2,
t = sqrt (2*S/g) = 12.7sec. The resule is right. Thanks.
I hope that scalling the world solves this trouble.
Post Reply