Ogre and Bullet (No OgreBullet)
-
- Posts: 6
- Joined: Sun Sep 21, 2008 4:39 pm
Ogre and Bullet (No OgreBullet)
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.
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.
-
- Posts: 6
- Joined: Thu Apr 03, 2008 7:39 pm
Re: Ogre and Bullet (No OgreBullet)
create a class that extends btMotionState add it to your rigid body. will probably contain a pointer to your ogre::scenenode.
in the setWorldTransform method, do something like this:
Code: Select all
btRigidBody *body = new btRigidBody(mass, motionState, shape, localInertia);
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);
}
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
-
- Posts: 6
- Joined: Sun Sep 21, 2008 4:39 pm
Re: Ogre and Bullet (No OgreBullet)
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.)
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.)
-
- Posts: 25
- Joined: Fri Sep 19, 2008 10:23 am
Re: Ogre and Bullet (No OgreBullet)
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.
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.
-
- Posts: 6
- Joined: Sun Sep 21, 2008 4:39 pm
Re: Ogre and Bullet (No OgreBullet)
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.)
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.)
-
- Posts: 25
- Joined: Fri Sep 19, 2008 10:23 am
Re: Ogre and Bullet (No OgreBullet)
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.
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.
-
- Posts: 6
- Joined: Sun Sep 21, 2008 4:39 pm
Re: Ogre and Bullet (No OgreBullet)
i am using the compound shape for the terrain...not player character ^^
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Ogre and Bullet (No OgreBullet)
Premature optimization is the root of all evil.(If the player moves it just creates the triangle....not when the game is started to reduce long waiting times.)
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 (-;
-
- Posts: 6
- Joined: Sun Sep 21, 2008 4:39 pm
Re: Ogre and Bullet (No OgreBullet)
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 ?
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 ?
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Ogre and Bullet (No OgreBullet)
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
Gary (-;
There's also a code snippet showing how to build one on the wiki
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].The gravity in my game works but I can't walk or stand on the terrain...the player just goes through it.
Gary (-;
-
- Posts: 6
- Joined: Sun Sep 21, 2008 4:39 pm
Re: Ogre and Bullet (No OgreBullet)
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 ?
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 ?
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Ogre and Bullet (No OgreBullet)
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.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].
Half a million triangles seems like a lot. So assuming the serialise thing doesn't give acceptable performance, I posted a third suggestionHowever when i use the trimesh the loading time is beyond like 20min
The triangles are added like this :
forloop x < 513
forloop z < 513
Gary (-;If you're still running into load time problems, then bust it up into smaller pieces.