BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
-
- Gnoblar
- Posts: 8
- Joined: Sat Apr 11, 2009 8:59 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Great job on this small binding, its very easy to use and simple to understand.
I would like to know, however, how you would turn a camera into a rigid body. I thought I could do this by passing camera in as a renderable (but that ended up with a runtime error). Should I just create a simple sphere shape to act as a bounding box around the camera?
I would like to know, however, how you would turn a camera into a rigid body. I thought I could do this by passing camera in as a renderable (but that ended up with a runtime error). Should I just create a simple sphere shape to act as a bounding box around the camera?
- 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!)
Thanks!CodeNewt wrote:Great job on this small binding, its very easy to use and simple to understand.
You could attach the Camera to a SceneNode, and use this SceneNode the same way as you would for any graphical objects. The shape would be a sphere with whatever radius you want.I would like to know, however, how you would turn a camera into a rigid body. I thought I could do this by passing camera in as a renderable (but that ended up with a runtime error). Should I just create a simple sphere shape to act as a bounding box around the camera?
-
- Gnoblar
- Posts: 8
- Joined: Sat Apr 11, 2009 8:59 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Code: Select all
mSceneNode = mSceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");
mSceneNode->attachObject(mCamera);
btCollisionShape *shape = new btSphereShape(1.2);
btScalar mass = 5;
btVector3 inertia;
shape->calculateLocalInertia(mass, inertia);
BtOgre::RigidBodyState *state = new BtOgre::RigidBodyState(mSceneNode);
mRigidBody = new btRigidBody(mass, state, shape, inertia);
mWorld->addRigidBody(mRigidBody)
Thanks
-
- Kobold
- Posts: 38
- Joined: Thu Sep 10, 2009 3:29 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Hello,
I try to use BtOgre that seems to be easy to use. My code compile but I have this error 15 times
1>main.obj : error LNK2019: symbole externe non résolu "public: __thiscall btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(class btDispatcher *,class btBroadphaseInterface *,class btConstraintSolver *,class btCollisionConfiguration *)" (??0btDiscreteDynamicsWorld@@QAE@PAVbtDispatcher@@PAVbtBroadphaseInterface@@PAVbtConstraintSolver@@PAVbtCollisionConfiguration@@@Z) référencé dans la fonction "public: __thiscall Jeu::Jeu(void)" (??0Jeu@@QAE@XZ)
I added this folder "C:\OgreSDK\include\bullet-2.75\src" and "C:\OgreSDK\include\btOgre\include" into the include repertories
I'm using VC 2008 Express, Ogre 1.6
I hope someone can help me
I try to use BtOgre that seems to be easy to use. My code compile but I have this error 15 times
1>main.obj : error LNK2019: symbole externe non résolu "public: __thiscall btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(class btDispatcher *,class btBroadphaseInterface *,class btConstraintSolver *,class btCollisionConfiguration *)" (??0btDiscreteDynamicsWorld@@QAE@PAVbtDispatcher@@PAVbtBroadphaseInterface@@PAVbtConstraintSolver@@PAVbtCollisionConfiguration@@@Z) référencé dans la fonction "public: __thiscall Jeu::Jeu(void)" (??0Jeu@@QAE@XZ)
I added this folder "C:\OgreSDK\include\bullet-2.75\src" and "C:\OgreSDK\include\btOgre\include" into the include repertories
I'm using VC 2008 Express, Ogre 1.6
I hope someone can help me
- nikki
- Old One
- Posts: 2730
- Joined: Sat Sep 17, 2005 10:08 am
- Location: San Francisco
- x 13
- Contact:
-
- Kobold
- Posts: 38
- Joined: Thu Sep 10, 2009 3:29 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Ok thanks, i built these libs, linked "libbulletcollision.lib" and "libbulletdynamics.lib".
But there is not linearMath library, only libbulletmath.lib. I linked this one but I still have 7 errors LNK2019
I put my links in this order :
" libbulletdynamics.lib libbulletcollision.lib libbulletmath.lib OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib OIS_d.lib"
Edit : Here are the errors if it can help. I use Bullet 2-75
But there is not linearMath library, only libbulletmath.lib. I linked this one but I still have 7 errors LNK2019
I put my links in this order :
" libbulletdynamics.lib libbulletcollision.lib libbulletmath.lib OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib OIS_d.lib"
Edit : Here are the errors if it can help. I use Bullet 2-75
Code: Select all
1>main.obj : error LNK2019: symbole externe non résolu "public: __thiscall BtOgre::StaticMeshToShapeConverter::~StaticMeshToShapeConverter(void)" (??1StaticMeshToShapeConverter@BtOgre@@QAE@XZ) référencé dans la fonction "protected: virtual void __thiscall Jeu::createScene(void)" (?createScene@Jeu@@MAEXXZ)
1>main.obj : error LNK2019: symbole externe non résolu "public: class btSphereShape * __thiscall BtOgre::VertexIndexToShape::createSphere(void)" (?createSphere@VertexIndexToShape@BtOgre@@QAEPAVbtSphereShape@@XZ) référencé dans la fonction "protected: virtual void __thiscall Jeu::createScene(void)" (?createScene@Jeu@@MAEXXZ)
1>main.obj : error LNK2019: symbole externe non résolu "public: __thiscall BtOgre::StaticMeshToShapeConverter::StaticMeshToShapeConverter(class Ogre::Entity *,class Ogre::Matrix4 const &)" (??0StaticMeshToShapeConverter@BtOgre@@QAE@PAVEntity@Ogre@@ABVMatrix4@3@@Z) référencé dans la fonction "protected: virtual void __thiscall Jeu::createScene(void)" (?createScene@Jeu@@MAEXXZ)
1>main.obj : error LNK2019: symbole externe non résolu "public: __thiscall BtOgre::DynamicLines::DynamicLines(enum Ogre::RenderOperation::OperationType)" (??0DynamicLines@BtOgre@@QAE@W4OperationType@RenderOperation@Ogre@@@Z) référencé dans la fonction "public: __thiscall BtOgre::DebugDrawer::DebugDrawer(class Ogre::SceneNode *,class btDynamicsWorld *)" (??0DebugDrawer@BtOgre@@QAE@PAVSceneNode@Ogre@@PAVbtDynamicsWorld@@@Z)
1>main.obj : error LNK2019: symbole externe non résolu "public: void __thiscall BtOgre::DynamicLines::addPoint(class Ogre::Vector3 const &)" (?addPoint@DynamicLines@BtOgre@@QAEXABVVector3@Ogre@@@Z) référencé dans la fonction "public: virtual void __thiscall BtOgre::DebugDrawer::drawLine(class btVector3 const &,class btVector3 const &,class btVector3 const &)" (?drawLine@DebugDrawer@BtOgre@@UAEXABVbtVector3@@00@Z)
1>main.obj : error LNK2019: symbole externe non résolu "public: void __thiscall BtOgre::DynamicLines::clear(void)" (?clear@DynamicLines@BtOgre@@QAEXXZ) référencé dans la fonction "public: virtual void __thiscall BtOgre::DebugDrawer::setDebugMode(int)" (?setDebugMode@DebugDrawer@BtOgre@@UAEXH@Z)
1>main.obj : error LNK2019: symbole externe non résolu "public: void __thiscall BtOgre::DynamicLines::update(void)" (?update@DynamicLines@BtOgre@@QAEXXZ) référencé dans la fonction "public: void __thiscall BtOgre::DebugDrawer::step(void)" (?step@DebugDrawer@BtOgre@@QAEXXZ)
-
- Gnoblar
- Posts: 8
- Joined: Sat Apr 11, 2009 8:59 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Do you have the latest version of bullet? I don't see BulletMath as anything on my computer. I'm using version 2.75
- nikki
- Old One
- Posts: 2730
- Joined: Sat Sep 17, 2005 10:08 am
- Location: San Francisco
- x 13
- Contact:
-
- Kobold
- Posts: 38
- Joined: Thu Sep 10, 2009 3:29 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Yeah it works, thanks for your answers ^^
I didn't find any tutorial about BtOgre, is the bullet doc enough ? For now, I just want to detect collision and not to have physic (maybe later).
I have a character with a sword and an ennemy and I don't know what to do to detect collisions between the characters and the sword
I didn't find any tutorial about BtOgre, is the bullet doc enough ? For now, I just want to detect collision and not to have physic (maybe later).
I have a character with a sword and an ennemy and I don't know what to do to detect collisions between the characters and the sword
- 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!)
BtOgre is just the Bullet-Ogre connection. There's very little BtOgre to know apart from what you see in the first post. Everything else is handled under the hood. It's meant to be that way: Simple, no extra interface to bolt on to Bullet, just use Bullet directly.Champi Atomik wrote:I have a character with a sword and an ennemy and I don't know what to do to detect collisions between the characters and the sword
So from here, it's Bullet. Consult the Bullet documentation, forums etc.
-
- Gnoblar
- Posts: 8
- Joined: Sat Apr 11, 2009 8:59 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
LAST EDIT::
I solved it. =) Ogre::String(); does not inheritely convert int's to string (I guess I'm spoiled by C# a bit in this case), I had to use Ogre::StringConverter::toString(myInt) to generate the entity name. Created 360 rigidbodies, no lag. Woohoo!
I don't know if this is a Bullet problem, Ogre problem or a BtOgre problem, but whenever I create more then 10 of your Player.mesh in your demo, my application crashes. Would you happen to know if theres a limit anywhere programmed in, in BtOgre or Bullet? Like a setting I have to change?
Edit: Now it seems anything thats 17 or more, it crashes. This is frustrating! :O
Heres the error:
Another Edit:
Does Ogre::String() not convert ints to the equivalent character, but instead into what the ASCII/Unicode is? (Like if I did an Ogre::String(new int(65)), it would come out as A?)
I solved it. =) Ogre::String(); does not inheritely convert int's to string (I guess I'm spoiled by C# a bit in this case), I had to use Ogre::StringConverter::toString(myInt) to generate the entity name. Created 360 rigidbodies, no lag. Woohoo!
I don't know if this is a Bullet problem, Ogre problem or a BtOgre problem, but whenever I create more then 10 of your Player.mesh in your demo, my application crashes. Would you happen to know if theres a limit anywhere programmed in, in BtOgre or Bullet? Like a setting I have to change?
Edit: Now it seems anything thats 17 or more, it crashes. This is frustrating! :O
Code: Select all
void sWorld::button_GenerateMouseUp(const QuickGUI::EventArgs &args)
{
c_Counter++;
printf("Entity : %d\n", c_Counter);
Ogre::Entity *newEntity = c_SceneManager->createEntity(Ogre::String(c_Counter + "NewEntity"), "Player.mesh");
Ogre::SceneNode *newNode = c_SceneManager->getRootSceneNode()->createChildSceneNode(Ogre::String(c_Counter + "NewNode"), Ogre::Vector3(0,10,0));
newNode->attachObject(newEntity);
BtOgre::StaticMeshToShapeConverter converter(newEntity);
btCollisionShape *newShape = converter.createSphere();
btScalar mass = 1;
btVector3 inertia;
newShape->calculateLocalInertia(mass, inertia);
BtOgre::RigidBodyState *newState = new BtOgre::RigidBodyState(newNode);
btRigidBody *newRigidBody = new btRigidBody(mass, newState, newShape, inertia);
c_World->addRigidBody(newRigidBody);
}
Code: Select all
Texture: Player.png: Loading 1 faces(PF_R8G8B8,256x256x1) with 8 hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,256x256x1.
terminate called after throwing an instance of 'Ogre::ItemIdentityException'
what(): OGRE EXCEPTION(4:ItemIdentityException): An object of type 'Entity' with name '' already exists. in SceneManager::createMovableObject at /Users/steve/projects/Shoggoth_clean/ogre/Mac/Ogre/../../OgreMain/src/OgreSceneManager.cpp (line 6136)
Another Edit:
Does Ogre::String() not convert ints to the equivalent character, but instead into what the ASCII/Unicode is? (Like if I did an Ogre::String(new int(65)), it would come out as A?)
- 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!)
CodeNewt wrote:Does Ogre::String() not convert ints to the equivalent character, but instead into what the ASCII/Unicode is? (Like if I did an Ogre::String(new int(65)), it would come out as A?)
Consider improving your C++ skills first.
-
- Gnoblar
- Posts: 8
- Joined: Sat Apr 11, 2009 8:59 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Doing the best I can with the knowledge I have. =)
-
- Gnoblar
- Posts: 16
- Joined: Sun Jul 19, 2009 8:55 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Hi Nikki,
Firstly btOgre is a nice tool, bit rough but direct access to the physics library is definitely the way to go.
Ok, one thing the centre of the Node should be automatically created from the mesh, below is some code on how I do it... it works but I lose the centre if I change the transform.
Ok firstly code to automatically set the Physics centre to the the mesh centre, basically it just gets the Movable object, then gets the Ogre World bounding box and from this works out the offset. The first 1 assumes that the attached object[0] has the world bounding box, the second 1 lets you specify the Entity.
Now this works, and works for the objects falling... but when I call set World transform it loses the offset... for example.
Any Ideas?
SUMMARY:
Some code to automatically find the mCenterOfMassOffset.
GetWorldTransform Then SetWorldTransform loses the mCenterOfMassOffset.
Firstly btOgre is a nice tool, bit rough but direct access to the physics library is definitely the way to go.
Ok, one thing the centre of the Node should be automatically created from the mesh, below is some code on how I do it... it works but I lose the centre if I change the transform.
Ok firstly code to automatically set the Physics centre to the the mesh centre, basically it just gets the Movable object, then gets the Ogre World bounding box and from this works out the offset. The first 1 assumes that the attached object[0] has the world bounding box, the second 1 lets you specify the Entity.
Code: Select all
RigidBodyState(Ogre::SceneNode *node)
: mNode(node),
mTransform(((node != NULL) ? BtOgre::Convert::toBullet(node->getOrientation()) : btQuaternion(0,0,0,1)),
((node != NULL) ? BtOgre::Convert::toBullet(node->getPosition()) : btVector3(0,0,0)))
{
mCenterOfMassOffset = btTransform::getIdentity();
const Ogre::AxisAlignedBox &vAxisBox = mNode->getAttachedObject(0)->getWorldBoundingBox(true);
Ogre::Vector3 vNodePos = mNode->getPosition();
Ogre::Vector3 vNodeCenter = vAxisBox.getCenter();
Ogre::Vector3 vOffset = vNodePos - vNodeCenter;
mCenterOfMassOffset = btTransform(btQuaternion(0,0,0,1),Convert::toBullet(vOffset));
}
RigidBodyState(Ogre::SceneNode* node, Ogre::MovableObject* vEntity)
: mNode(node),
mTransform(((node != NULL) ? BtOgre::Convert::toBullet(node->getOrientation()) : btQuaternion(0,0,0,1)),
((node != NULL) ? BtOgre::Convert::toBullet(node->getPosition()) : btVector3(0,0,0)))
{
mCenterOfMassOffset = btTransform::getIdentity();
const Ogre::AxisAlignedBox &vAxisBox = vEntity->getWorldBoundingBox(true);
Ogre::Vector3 vNodePos = mNode->getPosition();
Ogre::Vector3 vNodeCenter = vAxisBox.getCenter();
Ogre::Vector3 vOffset = vNodePos - vNodeCenter;
mCenterOfMassOffset = btTransform(btQuaternion(0,0,0,1),Convert::toBullet(vOffset));
}
Code: Select all
btTransform vTransform;
btRigidBody* vBody;
//<...Setup body etc.....>
vBody->getMotionState()->getWorldTransform(vTransform);
vBody->getMotionState()->setWorldTransform(vTransform);
SUMMARY:
Some code to automatically find the mCenterOfMassOffset.
GetWorldTransform Then SetWorldTransform loses the mCenterOfMassOffset.
- 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!)
Show me your 'setWorldTransform' code. Are you using the latest BtOgre code from git? It has a constructor that takes the centre of mass transform.
Code: Select all
RigidBodyState(Ogre::SceneNode *node, const btTransform &transform, const btTransform &offset = btTransform::getIdentity())
: mNode(node),
mTransform(transform),
mCenterOfMassOffset(offset)
{
}
/* ... */
virtual void getWorldTransform(btTransform &ret) const
{
ret = mCenterOfMassOffset.inverse() * mTransform;
}
virtual void setWorldTransform(const btTransform &in)
{
if (mNode == NULL)
return;
mTransform = in;
btTransform transform = in * mCenterOfMassOffset;
btQuaternion rot = transform.getRotation();
btVector3 pos = transform.getOrigin();
mNode->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
mNode->setPosition(pos.x(), pos.y(), pos.z());
}
-
- Gnoblar
- Posts: 16
- Joined: Sun Jul 19, 2009 8:55 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Yeah I use the same code as you posted. (Latest version from git...)
Also I added, support for capsules... might do the rest of the Bullet shapes as well... if I get the time...(Not that is is very difficult.. but still:])
Any ideas on why the centre of mass keeps moving back?
PS-How can I add some additional stuff for this? Some code updates etc... also since sooo painful to get started in this, and it is fairly simple, might do a quick wiki for how to use btOgre...
Also I added, support for capsules... might do the rest of the Bullet shapes as well... if I get the time...(Not that is is very difficult.. but still:])
Code: Select all
//------------------------------------------------------------------------------------------------
btCapsuleShape* VertexIndexToShape::createCapsule()
{
const Ogre::Vector3 sz = getSize();
assert((sz.x > 0.0) && (sz.y > 0.0) && (sz.y > 0.0) &&
("Size of Cylinder must be greater than zero on all axes"));
btScalar vRadius = (std::max(sz.x,sz.z))/2;
btScalar vHeight = sz.y;
btCapsuleShape* shape = new btCapsuleShape(vRadius,vHeight);
return shape;
}
PS-How can I add some additional stuff for this? Some code updates etc... also since sooo painful to get started in this, and it is fairly simple, might do a quick wiki for how to use btOgre...
-
- Gnoblar
- Posts: 16
- Joined: Sun Jul 19, 2009 8:55 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
PS- the create capsule code is not an example of my coding ability l.. maybe I should have fixed up the assert etc:] and added comments:]
- 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!)
No ideas yet, I'll look into it now.Ripgiblet wrote:Any ideas on why the centre of mass keeps moving back?
Use 'git diff' and send me the output.PS-How can I add some additional stuff for this? Some code updates etc... also since sooo painful to get started in this, and it is fairly simple, might do a quick wiki for how to use btOgre...
- Dynad
- Gnoblar
- Posts: 21
- Joined: Sun Sep 13, 2009 2:53 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Hey Nikki tnx alot i really needed this for my project
i had some compile errors to deal with:
Solution to those problems are:
If u change in BtOgreGP.h on line 27
to:
U will fix the coversion problem.
Second problem with the LIBCMT.... if u change Runtime library to Multi-threaded (/MT) or (/MTd) for debug in Properties of your project -> C/C++ -> code generation will fix that problem..
Cheers,
~Dynad
i had some compile errors to deal with:
Code: Select all
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility(57) : warning C4244: 'initializing' : conversion from 'const unsigned short' to 'const unsigned char', possible loss of data
..\BtOgre.cpp(147) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<unsigned short,BtOgre::Vector3Array*>(const std::pair<unsigned short,_Ty2> &)' being compiled
with
[
_Ty1=const unsigned char,
_Ty2=std::vector<Ogre::Vector3> *
]
Generating Code...
Linking...
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
If u change in BtOgreGP.h on line 27
Code: Select all
typedef std::pair<unsigned short, Vector3Array*> BoneKeyIndex;
Code: Select all
typedef std::pair<unsigned int, Vector3Array*> BoneKeyIndex;
Second problem with the LIBCMT.... if u change Runtime library to Multi-threaded (/MT) or (/MTd) for debug in Properties of your project -> C/C++ -> code generation will fix that problem..
Cheers,
~Dynad
- Dynad
- Gnoblar
- Posts: 21
- Joined: Sun Sep 13, 2009 2:53 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
Ive only 1 problem left...
I use the NGF framework and when im implementing this Demo in the framework the character just fell trough the terrain...
I use the NGF framework and when im implementing this Demo in the framework the character just fell trough the terrain...
Code: Select all
#include "OgreNode.h"
#include <NgfBullet.h>
class LevelGeometry : public NGF::Bullet::BulletGameObject
{
protected:
SceneNode *mNode;
Entity *mEntity;
btRigidBody *mGroundBody;
btCollisionShape *mGroundShape;
public:
LevelGeometry(Ogre::Vector3 pos, Ogre::Quaternion rot, NGF::ID id, NGF::PropertyList properties, String name) : NGF::GameObject(pos, rot, id , properties, name)
{
String idStr = StringConverter::toString(id);
addFlag("LevelGeometry");
//Create Ogre stuff.
String brushMeshFile = properties.getValue("brushMeshFile", 0, "Player.mesh");
mEntity = Globals::smgr->createEntity(idStr + "-levelGeometryEntity", brushMeshFile);
mEntity->setQueryFlags(QF_LEVELGEOMETRY);
mNode = Globals::smgr->getRootSceneNode()->createChildSceneNode(idStr + "levelGeometrySceneNode", pos, rot);
mNode->attachObject(mEntity);
mNode->setScale(25.0f, 25.0f, 25.0f);
//Create the ground shape.
BtOgre::StaticMeshToShapeConverter converter(mEntity);
mGroundShape = converter.createTrimesh();
//Create MotionState (no need for BtOgre here, you can use it if you want to though).
btDefaultMotionState* groundState = new btDefaultMotionState(
btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
//Create the Body.
mGroundBody = new btRigidBody(0, groundState, mGroundShape, btVector3(0,0,0));
Globals::phyWorld->addRigidBody(mGroundBody);
BtOgre::RigidBodyState *state = new BtOgre::RigidBodyState(mNode);
NGF::Bullet::BulletGameObject::setBulletObject(mGroundBody);
}
~LevelGeometry()
{
//Destroy Ogre stuff.
mNode->detachAllObjects();
Globals::smgr->destroyEntity(mEntity);
Globals::smgr->destroySceneNode(mNode->getName());
//Destory physics stuff.
delete mGroundShape;
delete mGroundBody->getMotionState();
delete mGroundBody;
Globals::phyWorld->removeRigidBody(mGroundBody);
}
void unpausedTick(const Ogre::FrameEvent &evt)
{
}
void pausedTick(const Ogre::FrameEvent &evt)
{
}
NGF::MessageReply receiveMessage(NGF::Message msg)
{
return false;
}
void collide(GameObject *other, btCollisionObject *otherPhysicsObject, btManifoldPoint &contact)
{
LogManager::getSingleton().logMessage("We collided!");
}
};
- 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!)
This problem has been mentioned before somewhere in this thread. The poster was able to fix it.Dynad wrote:I use the NGF framework and when im implementing this Demo in the framework the character just fell trough the terrain...
- Dynad
- Gnoblar
- Posts: 21
- Joined: Sun Sep 13, 2009 2:53 pm
Re: BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)
ok i fixed the falling down problem but now when i move the sceneNode it moves very weird.... it doesnt walk but teleports instead..
here is the code is use for movement. I dont really understand how to move the btRigidBody and sceneNode @ the same time...
here is the code is use for movement. I dont really understand how to move the btRigidBody and sceneNode @ the same time...
Code: Select all
if (nextLocation() || mDirection != Vector3::ZERO){
mDistance -= move;
if (mDistance <= 0.0f)
{
mNode->setPosition(mDestination);
mDirection = Vector3::ZERO;
}
else
{
if(mRotating)// Process timed rotation
{
mRotProgress += mRotFactor;
if(mRotProgress>1)
{
mRotating = false;
}
else
{
Quaternion delta = Quaternion::Slerp(mRotProgress, mOrientSrc, mOrientDest, true);
mNode->setOrientation(delta);
}
} // if mRotating
mBody->getMotionState()->getWorldTransform(vTransform);
mNode->translate(mDirection * move);
mBody->getMotionState()->setWorldTransform(vTransform);
} // else
- 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!)
Do not move the SceneNode yourself! You only move the RigidBody. You talk about position/orientation through the physics engine now, not Ogre. The idea behind BtOgre is to inform the graphics about physics updates. If you're having to move the SceneNode and btRigidBody yourself, then there's no point.
If it's a free (ie. not static/kinematic) body, then apply forces, or impulses. If you want to do a direct translate/rotate, then get the transform, transform it however you want, then set the transform back. If you're looking to have animated movement (what it seems you're doing) on a btRigidBody, make it kinematic.
If it's a free (ie. not static/kinematic) body, then apply forces, or impulses. If you want to do a direct translate/rotate, then get the transform, transform it however you want, then set the transform back. If you're looking to have animated movement (what it seems you're doing) on a btRigidBody, make it kinematic.
- 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!)
Im trying to implement collision detection for a blender exported scene (basically, it is just a group of meshes), the idea is to have a ground mesh, a few boxes and make a character walk on the ground. I have a problem when I try to use the robot mesh: if I create it as a cylinder, it starts spinning and it pulled to a side, out of the ground mesh. If I use convex, then I cant move it. I dont see any other shape for animated meshes. The rest of the meshes are created as static, so, they are trimesh with mass 0.
This is my init code:
This is the code to create static meshes:
This is the code to create animated meshes:
Just in case, this is the class definition:
Can somebody see what Im doing wrong here?
This is my init 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();
phyWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfig);
phyWorld->setGravity(btVector3(0,-9.8,0));
dbgdraw = new BtOgre::DebugDrawer(smgr->getRootSceneNode(), phyWorld);
dbgdraw->setDebugMode(true);
Code: Select all
void btPhysics::createStaticShape(Ogre::String name, Ogre::Entity *mesh, Ogre::SceneNode *node)
{
stConvert[name] = new BtOgre::StaticMeshToShapeConverter(mesh);
shapes[name] = stConvert[name]->createTrimesh();
//Calculate inertia.
btScalar mass = 0;
BtOgreStates[name] = new BtOgre::RigidBodyState(node);
btBodies[name] = new btRigidBody(mass, BtOgreStates[name], shapes[name], btVector3(0,0,0));
phyWorld->addRigidBody(btBodies[name]);
}
Code: Select all
void btPhysics::createAnimatedShape(Ogre::String name, Ogre::Entity *mesh, Ogre::SceneNode *node)
{
anConvert[name] = new BtOgre::AnimatedMeshToShapeConverter(mesh);
shapes[name] = anConvert[name]->createTrimesh();
//Calculate inertia.
btScalar mass = 0;
//btVector3 inertia;
//shapes[name]->calculateLocalInertia(mass, inertia);
BtOgreStates[name] = new BtOgre::RigidBodyState(node);
btBodies[name] = new btRigidBody(mass, BtOgreStates[name], shapes[name], btVector3(0,0,0));
phyWorld->addRigidBody(btBodies[name]);
}
Code: Select all
class btPhysics: public Ogre::Singleton<btPhysics> {
public:
btPhysics(Ogre::SceneManager *smgr);
~btPhysics();
static btPhysics& getSingleton();
static btPhysics* getSingletonPtr();
void update(float ms);
void createStaticShape(Ogre::String name, Ogre::Entity *mesh, Ogre::SceneNode *node);
void createAnimatedShape(Ogre::String name, Ogre::Entity *mesh, Ogre::SceneNode *node);
protected:
btDynamicsWorld *phyWorld;
btAxisSweep3 *mBroadphase;
btDefaultCollisionConfiguration *mCollisionConfig;
btCollisionDispatcher *mDispatcher;
btSequentialImpulseConstraintSolver *mSolver;
std::map<std::string,BtOgre::StaticMeshToShapeConverter*> stConvert;
std::map<std::string,BtOgre::AnimatedMeshToShapeConverter*> anConvert;
std::map<std::string,btCollisionShape*> shapes;
std::map<std::string,BtOgre::RigidBodyState*> BtOgreStates;
std::map<std::string,btRigidBody*> btBodies;
BtOgre::DebugDrawer *dbgdraw;
btRigidBody *terrainBody;
};
- 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!)
Can you post some basic sample code to do this?nikki wrote:Do not move the SceneNode yourself! You only move the RigidBody. You talk about position/orientation through the physics engine now, not Ogre. The idea behind BtOgre is to inform the graphics about physics updates. If you're having to move the SceneNode and btRigidBody yourself, then there's no point.
If it's a free (ie. not static/kinematic) body, then apply forces, or impulses. If you want to do a direct translate/rotate, then get the transform, transform it however you want, then set the transform back. If you're looking to have animated movement (what it seems you're doing) on a btRigidBody, make it kinematic.