I'm pretty sure this kind of question has already been asked but it's hard to find something relevant so here's my problem :
I'm loading an Irrlicht terrainscenenode with a flat heightmap and a texture, and I setup bullet to make it a static plane to let some boxes fall on it. The problem is that when the boxes fall they go through the texture and stop on an invisible plane below it. I think the problem comes from the plane because the boxes textures and their physics correspond. I'm a bit confused because the Irrlicht collision detector is set at the same height than the plane texture but bullet says that the "real" plane is below.
So I'm wondering if it's because my heightmap suck (I made it with Blender). Do I need a full black or full white heightmap to get the texture corresponding with the height ? Or maybe it's something else ?
[Solved] Quick question about Bullet and Irrlicht terrain
-
- Posts: 33
- Joined: Fri Mar 01, 2013 1:26 am
[Solved] Quick question about Bullet and Irrlicht terrain
Last edited by Nyx Erebos on Sat Aug 24, 2013 2:22 pm, edited 1 time in total.
Re: Quick question about Bullet and Irrlicht terrain
There probably is something wrong in your part of code. Bullet and irrlicht should work fine together.
Post your code to some code paste site and someone might find what you did wrong.
Post your code to some code paste site and someone might find what you did wrong.
Working on game: Marrbles (Currently stopped).
-
- Posts: 33
- Joined: Fri Mar 01, 2013 1:26 am
Re: Quick question about Bullet and Irrlicht terrain
I half answered my question, I made a full black heightmap and now the texture is at the right place... which is now below the bullet plane
I give the same position for both the irrlicht and bullet plane. Do I have to adjust it because irrlicht and bullet don't consider the position in the same way ?
I have a wrapper around the irrlicht terrain node but basically that's what I do (I don't write the whole bullet initialisation because it's copy/paste from the bullet examples) :
Then I update bullet in the main loop. I don't know if the problem comes from the bullet plane position (setOrigin) that may not work the same way as the irrlicht terrain position, or if the values I give to btBoxShape aren't good.
To see if the physical world corresponds to what irrlicht renders I make boxes fall so perhaps it's a texture not drawn where I expect it to be, but it's unlikely because the boxes collide perfectly between themselves.
[EDIT] : I apologize for the spam, a little test confirmed what I thought, the irrlicht position is the position of the "minPoint" whereas the bullet position corresponds to the center of the object. To fix my problem I had to adjust the position of the boxes I give to irrlicht (so yeah that part of the problem came from my boxes ).
[EDIT 2] : in case someone's wondering it's :
instead of what I wrote.
I give the same position for both the irrlicht and bullet plane. Do I have to adjust it because irrlicht and bullet don't consider the position in the same way ?
I have a wrapper around the irrlicht terrain node but basically that's what I do (I don't write the whole bullet initialisation because it's copy/paste from the bullet examples) :
Code: Select all
ITerrainSceneNode * terrain = sceneManager->addTerrainSceneNode("path/to/heightmap", parent, -1, /*position*/ vector3df(1600,100,3300), /*rotation*/ vector3df(0.f, 0.f, 0.f), /*scale*/ vector3df(2.f, 1.f, 2.f), vertexColor, maxLOD, patchSize, smoothFactor);
//then I set all stuff visual related (textures, materialtype...) but I don't show it here
//I get the edges length because bullet need them (I don't know if the fabs are needed, I need to look more closely at how getBoundingBox works)
float_t groundLengthOverX = fabs(terrain->getBoundingBox().MinEdge.X) + fabs(terrain->getBoundingBox().MaxEdge.X);
float_t groundLengthOverZ = fabs(terrain->getBoundingBox().MinEdge.Z) + fabs(terrain->getBoundingBox().MaxEdge.Z);
//from here it's almost straight out of the bullet examples
btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(groundLengthOverX/2.),btScalar(0.1),btScalar(groundLengthOverZ/2.)));
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(btScalar(1600), btScalar(100), btScalar(3300)));
btScalar mass(0.f);
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic) groundShape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo GroundRbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* groundBody = new btRigidBody(GroundRbInfo);
m_dynamicsWorld->addRigidBody(groundBody);
To see if the physical world corresponds to what irrlicht renders I make boxes fall so perhaps it's a texture not drawn where I expect it to be, but it's unlikely because the boxes collide perfectly between themselves.
[EDIT] : I apologize for the spam, a little test confirmed what I thought, the irrlicht position is the position of the "minPoint" whereas the bullet position corresponds to the center of the object. To fix my problem I had to adjust the position of the boxes I give to irrlicht (so yeah that part of the problem came from my boxes ).
[EDIT 2] : in case someone's wondering it's :
Code: Select all
float_t groundLengthOverX = fabs(terrain->getBoundingBox().MaxEdge.X) - fabs(terrain->getBoundingBox().MinEdge.X);
float_t groundLengthOverZ = fabs(terrain->getBoundingBox().MaxEdge.Z) - fabs(terrain->getBoundingBox().MinEdge.Z);