Terrain body not aligned (offset by 1 on -z)

notrodash

15-09-2012 15:55:16

What am I doing wrong?

unsigned page_size = terrainGroup->getTerrainSize();
Ogre::Vector3 terrainScale((4096 / (page_size-1)), 600, (4096 / (page_size-1)));
float *heights = new float[page_size*page_size];
for(unsigned y = 0; y < page_size; ++y)
{
for(unsigned x = 0; x < page_size; ++x)
{
Ogre::ColourValue color = imgPtr->getColourAt(x, y, 0);
heights[x + y * page_size] = color.r;
}
}

OgreBulletCollisions::HeightmapCollisionShape *terrainShape = new OgreBulletCollisions::HeightmapCollisionShape(
page_size,
page_size,
terrainScale,
heights,
true
);
OgreBulletDynamics::RigidBody *terrainBody = new OgreBulletDynamics::RigidBody(
"Terrain",
OgreInit::level->physicsManager->getWorld()
);
imgPtr = NULL;

Ogre::Vector3 terrainShiftPos(terrainScale.x/(page_size-1), 0, terrainScale.z/(page_size-1));
terrainShiftPos.y = terrainScale.y / 2 * terrainScale.y;

Ogre::SceneNode *pTerrainNode = OgreInit::sceneManager->getRootSceneNode()->createChildSceneNode();
terrainBody->setStaticShape(pTerrainNode, terrainShape, 0.0f, 0.8f, terrainShiftPos);
terrainBody->setPosition(terrainBody->getWorldPosition()-Ogre::Vector3(0.005, 0, 0.005));
OgreInit::level->physicsManager->addBody(terrainBody);
OgreInit::level->physicsManager->addShape(terrainShape);


I just cant figure it out. The terrain mesh is offset by one down the negative Z axis.
Here are some screenshots:





Thank you :)

UndeadParrot

01-10-2012 12:01:03

Notrodash, I'm having the same problem as you are having ;/

I have a gate, and it's offset. Not by a whole 1 unit, though. At first I thought it could be the model, but that shouldn't really affect this ;s

In other news, I see OgreBullet doesn't include SetLimits functionality for some constraints, like the hinge constraint. So my gate just swings around endlessly. ;|

notrodash

03-10-2012 21:07:28

So nobody knows how to solve this :shock: