Ogre and Bullet (No OgreBullet)

calsmurf2904
Posts: 6
Joined: Sun Sep 21, 2008 4:39 pm

Ogre and Bullet (No OgreBullet)

Post by calsmurf2904 »

Hello,
I am currently learning how to use Ogre (I already have some stuff) and I want to implement Physics.
I thought Bullet is a good choice for this so I downloaded and compiled it.
No errors while compiling.
So I started to implement it in my code.
The main problem is that I cannot bind a SceneNode from Ogre to a RigidBody.
So I manually have to insert the positions from the RigidBody into the SceneNode.
But I couldn't find a way to get the position from the rigidbody.
Is there a way to get this ?
(I tryed getOrientation but then the SceneNode wouldn't move while there is Gravity)



PS:I put the mWorld->stepSimulation(time); in the frameStarted function.
robtherich
Posts: 6
Joined: Thu Apr 03, 2008 7:39 pm

Re: Ogre and Bullet (No OgreBullet)

Post by robtherich »

create a class that extends btMotionState add it to your rigid body. will probably contain a pointer to your ogre::scenenode.

Code: Select all

btRigidBody *body = new btRigidBody(mass, motionState, shape, localInertia);
in the setWorldTransform method, do something like this:

Code: Select all

void setWorldTransform(const btTransform& worldTrans)
{
  btVector3 pos = worldTrans.getOrigin();
  sceneNode->setPosition(pos.x, pos.y, pos.z);
  btQuaternion q = worldTrans.getRotation();
  sceneNode->setOrientation(q.w, q.x, q.y, q.z);
}
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Ogre and Bullet (No OgreBullet)

Post by chunky »

With a concrete example on the wiki here

Gary (-;
calsmurf2904
Posts: 6
Joined: Sun Sep 21, 2008 4:39 pm

Re: Ogre and Bullet (No OgreBullet)

Post by calsmurf2904 »

thanks....i was using the default MotionState from Bullet for it.
Now I have a other (Non-Ogre related) question.
(This may sound stupid but)What is a kinematic body ?
What does it do ?
(I thought they where objects or points that attract objects.)
rusty
Posts: 25
Joined: Fri Sep 19, 2008 10:23 am

Re: Ogre and Bullet (No OgreBullet)

Post by rusty »

A kinematic object is something thats velocity is modified without using forces. A good example is say, an animated character in a game. You wouldn't move it using forces, but by modifying the velocities yourself, based on inputs from the player.

Having a rigid body as a kinematic object is a nice shortcut (as far as I can tell, only just started using Bullet myself) to hooking into the dynamics and collision world, so that everything responds to the objects movement in a mostly proper manner.
calsmurf2904
Posts: 6
Joined: Sun Sep 21, 2008 4:39 pm

Re: Ogre and Bullet (No OgreBullet)

Post by calsmurf2904 »

Ok...so I need to give my character a Kinematic Body.
Uhmm....next question (I have alot of questions lol) :
I need to get the position of the terrain (x,y,z) and then create a Polygon shape out of it for Bullet Collision.I am using a compound shape and TriangleShape for this. (Adding the TraingleShape as Child in the Compound Shape).Is there a more efficient way of doing this ?
(If the player moves it just creates the triangle....not when the game is started to reduce long waiting times.)
rusty
Posts: 25
Joined: Fri Sep 19, 2008 10:23 am

Re: Ogre and Bullet (No OgreBullet)

Post by rusty »

I wouldn't use a triangle shape for your player character. Instead, using something like a capsule/lozenge or even a box. Most, if not all 3d character based games use this technique for colliing the player against the world.

If you use a compund shape, and you think that a single capsule or box is maybe too low detail, add a several shapes such as capsules, spheres ans boxes. That way, you could say, construct the arms out of capsules and sych their position/orientation to your characters animations.
calsmurf2904
Posts: 6
Joined: Sun Sep 21, 2008 4:39 pm

Re: Ogre and Bullet (No OgreBullet)

Post by calsmurf2904 »

i am using the compound shape for the terrain...not player character ^^
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Ogre and Bullet (No OgreBullet)

Post by chunky »

(If the player moves it just creates the triangle....not when the game is started to reduce long waiting times.)
Premature optimization is the root of all evil.

Just build a trimesh, to try it. If you're running into load time problems, then build the large trimesh and serialize it to disk [the function calls to do it elude me, but they do exist already I believe]. If you're still running into load time problems, then bust it up into smaller pieces. But one-triangle-at-a-time-and-only-when-necessary is a universe of pain you probably want to avoid.

Gary (-;
calsmurf2904
Posts: 6
Joined: Sun Sep 21, 2008 4:39 pm

Re: Ogre and Bullet (No OgreBullet)

Post by calsmurf2904 »

Whats a trimesh (TriangleMesh ?) (I am kinda new to 3d programming etc.)
The gravity in my game works but I can't walk or stand on the terrain...the player just goes through it.
Maybe someone could help me with this ?
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Ogre and Bullet (No OgreBullet)

Post by chunky »

A triangle mesh is what you described yourself using as your terrain; a big bunch of triangles joined together into a big ol' mesh. There's a description on the wiki

There's also a code snippet showing how to build one on the wiki
The gravity in my game works but I can't walk or stand on the terrain...the player just goes through it.
If you're asking what a trimesh is and then saying you can't stand on the terrain, I'm guessing it's because you simply haven't put the terrain into bullet at all. Use the code snippet on the wiki to build the terrain as a triangle mesh and put it into bullet [keep in mind that once you've build the mesh, you'll still need to actually create a body with it [zero mass, the mesh as the collision shape] and put it into bullet].

Gary (-;
calsmurf2904
Posts: 6
Joined: Sun Sep 21, 2008 4:39 pm

Re: Ogre and Bullet (No OgreBullet)

Post by calsmurf2904 »

i was using a btCompoundShape and added the triangles as childs.
This doesn't work.However when i use the trimesh the loading time is beyond like 20min

The triangles are added like this :
forloop x < 513
forloop z < 513
pos1 = getposition(x,z); // Returns the btVector3 of the x,y,z
pos2 = getposition(x+1,z);
pos3 = getposition(x+1,z+1);
pos4 = getposition(x,z+1);
addtriangle(pos4,pos2,pos1);
addtriangle(pos4,pos3,pos2);
This is very time consuming...so is there a more efficient way of doing this ?
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Ogre and Bullet (No OgreBullet)

Post by chunky »

If you're running into load time problems, then build the large trimesh and serialize it to disk [the function calls to do it elude me, but they do exist already I believe].
Those functions are actually listed on the wiki pages. Specifically on one of the pages that I linked. The idea is that you build it once and it takes as long as it needs, and in future it reads the already-prepped data structures off disk.
However when i use the trimesh the loading time is beyond like 20min

The triangles are added like this :
forloop x < 513
forloop z < 513
Half a million triangles seems like a lot. So assuming the serialise thing doesn't give acceptable performance, I posted a third suggestion
If you're still running into load time problems, then bust it up into smaller pieces.
Gary (-;