Hello,
I am working on a project involving physics and 3d graphics (currently Ogre). The method used is using a top class having an ogre's scene node and a bullet rigid body as members. a "frame" method update graphics in function of physics. But I'd like to know if other approaches exist. I have seen a tutorial over the PhysX devnet using OpenGL. It seems to render a new sphere each frame. Is that a way to follow when using graphics engines on the top of OpenGL? And I did not understand at all what happen in the DemoApplication used by bullet's demos.
An other question is about mass. As said in the user manual, we must minimize mass ratios. But how to get a better behavior between a tank and a bike?
Does more informations exist on the upcoming btCharacterController class?
I hope it has not been ever discussed. Thanks in advance.
Integration
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Integration
Presuming I'm understanding you right, you want a decent way for things moving around in bullet to be updated appropriately on-screen in ogre? If so, btMotionState is your friend:
and
Have fun,
Gary (-;
Code: Select all
/// Helper class so that bullet can move objects in Ogre without my help
/** btMotionState is used to set up the initial world position of the object, and later
they are used to move the object in the world in your simluation.
Basically, bullet will magically move stuff about inside ogre for me, thanks to this object */
class TWShipMotionState : public btMotionState {
public:
/// Constructor
/** \param initialpos the initial position of the object in the world. bullet will read this out later when it first adds a body to the world
\param node the ogre scene node that bullet will move using this object */
TWShipMotionState(const btTransform &initialpos, Ogre::SceneNode *node=NULL);
/// Destructor
~TWShipMotionState();
/// Set the Ogre SceneNode that this is moving around
/** \param node the node to move */
void setNode(Ogre::SceneNode *node = NULL);
/// called by bullet to grab the initial transform of a body
/**
\param worldTrans put the value of the initial transform into this
*/
virtual void getWorldTransform(btTransform &worldTrans) const;
/// called by bullet during simluation when bullet has moved an object and wants it to move on-screen
/** \param worldTrans the transform of the object as bullet sees it, this function translates it to ogre co-ods */
virtual void setWorldTransform(const btTransform &worldTrans);
protected:
/// A pointer to the node that this motionstate moves on-screen
Ogre::SceneNode *mVisibleobj;
/// The initial position of the object
btTransform mPos1;
};
Code: Select all
TWShipMotionState::TWShipMotionState(const btTransform &initialpos, Ogre::SceneNode *node) {
mVisibleobj = node;
mPos1 = initialpos;
}
TWShipMotionState::~TWShipMotionState() {
}
void TWShipMotionState::getWorldTransform(btTransform &worldTrans) const {
worldTrans = mPos1;
}
void TWShipMotionState::setNode(Ogre::SceneNode *node) {
mVisibleobj = node;
}
void TWShipMotionState::setWorldTransform(const btTransform &worldTrans) {
if(NULL == mVisibleobj) return; // silently return before we set a node
btQuaternion rot = worldTrans.getRotation();
mVisibleobj->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
btVector3 pos = worldTrans.getOrigin();
mVisibleobj->setPosition(pos.x(), pos.y(), pos.z());
// printf("X: %f, Y:%f, Z:%f\n", pos.x(), pos.y(), pos.z());
}
Gary (-;
-
- Posts: 6
- Joined: Tue Feb 05, 2008 10:15 am
Re: Integration
That's a really nice idea. Thank you.
It works for primitives but I'd like speaking about more specialized in-game stuffs. Like for example, cars and characters.
For the first one, I'll certainly have to implement an interchangeable system for wheels and more, be able to open doors, ... I think using a main basic shape in a rigid body setted as the chassis in the btRaycastVehicle class and add constraints with other elements, remove them one if explosions are part of the game. Ogre has a subMesh and subEntities system I will request in that goal on the graphics side, which mean I'll have a little bit more work than the code in the reply, even more if glasses are breackable.
Now about characters, I'd like to know other things about the not yet but soon implemented character controller. As we can see on this website (the tool make use of PhysX) http://unity3d.com/support/documentatio ... oller.html , collisions are calculated using a capsule, but it seems to use a shape for the character model itself. While firing this one, it won't die if the shape meet a bullet. But as said on Internet, the PhysX class doesn't interact with objects except the environment. And I'm a lot more hesitant on how to link blender exported to ogre mesh skeleton animations and a character controlled via this class. If each body parts are seperated rigid bodies, moving them using ogre skeleton's informations will make shapes collide between them.
A last thing, but more general, how is made the graphical link with the teared soft body represented by a carpet in a PhysX example? A similar one is a piece of wood hit by something and giving a non-precalculated result made by Havok. Does physics engine provides informations about the creation of new rigid bodies during the simulation which must be interpreted for graphics display?
And what's about shapes deformations? Is that a dynamic triangles creation?
What's done in bullet yet?

It works for primitives but I'd like speaking about more specialized in-game stuffs. Like for example, cars and characters.
For the first one, I'll certainly have to implement an interchangeable system for wheels and more, be able to open doors, ... I think using a main basic shape in a rigid body setted as the chassis in the btRaycastVehicle class and add constraints with other elements, remove them one if explosions are part of the game. Ogre has a subMesh and subEntities system I will request in that goal on the graphics side, which mean I'll have a little bit more work than the code in the reply, even more if glasses are breackable.
Now about characters, I'd like to know other things about the not yet but soon implemented character controller. As we can see on this website (the tool make use of PhysX) http://unity3d.com/support/documentatio ... oller.html , collisions are calculated using a capsule, but it seems to use a shape for the character model itself. While firing this one, it won't die if the shape meet a bullet. But as said on Internet, the PhysX class doesn't interact with objects except the environment. And I'm a lot more hesitant on how to link blender exported to ogre mesh skeleton animations and a character controlled via this class. If each body parts are seperated rigid bodies, moving them using ogre skeleton's informations will make shapes collide between them.
A last thing, but more general, how is made the graphical link with the teared soft body represented by a carpet in a PhysX example? A similar one is a piece of wood hit by something and giving a non-precalculated result made by Havok. Does physics engine provides informations about the creation of new rigid bodies during the simulation which must be interpreted for graphics display?
And what's about shapes deformations? Is that a dynamic triangles creation?
What's done in bullet yet?