rogerdv
20-12-2010 14:00:18
I have found a problem when testing terrain intersection: the results obtained with ogre and OgreBullet idffers for Y and Z. Here is my code:
for picking (copy&paste from demo):
the picking code seems to work perfectly when intersecting ,meshes, but when the hit object is the terrain, there is a difference (in Z, OgreBullet reports 53 units more, I cant remember the exact difference). Can somebody see any problem here?
void btPhysics::createTerrainShape(Ogre::SceneNode *node, Ogre::Image heightmap, float worldsize, float maxheight)
{
int pagesize = heightmap.getWidth();
float *heights = new float [pagesize*pagesize];
for(unsigned y = 0; y < pagesize; ++y) {
for(unsigned x = 0; x < pagesize; ++x) {
Ogre::ColourValue color = heightmap.getColourAt(x, y, 0);
heights[x + y *pagesize] = color.r;
}
}
Vector3 terrainScale(worldsize /(pagesize-1), maxheight, worldsize /(pagesize-1));
HeightmapCollisionShape *mTerrainShape = new HeightmapCollisionShape(pagesize, pagesize, terrainScale, heights, true);
RigidBody *defaultTerrainBody = new RigidBody("Terrain", mWorld);
const float terrainBodyRestitution = 0.6f;
const float terrainBodyFriction = 0.8f;
Ogre::Vector3 terrainShiftPos( (terrainScale.x * (pagesize - 1) / 2), 0, (terrainScale.z * (pagesize - 1) / 2));
//Ogre::Vector3 terrainShiftPos(0, 0, 0);
terrainShiftPos.y = terrainScale.y / 2 * terrainScale.y;
defaultTerrainBody->setStaticShape (node, mTerrainShape, terrainBodyRestitution, terrainBodyFriction, terrainShiftPos);
mBodies.push_back(defaultTerrainBody);
mShapes.push_back(mTerrainShape);
}for picking (copy&paste from demo):
string btPhysics::getBodyUnderCursor(Ogre::Vector3 &inters, Ogre::Ray ray)
{
//delete mCollisionClosestRayResultCallback;
mCollisionClosestRayResultCallback = new CollisionClosestRayResultCallback(ray, mWorld, 5000);
mWorld->launchRay (*mCollisionClosestRayResultCallback);
if (mCollisionClosestRayResultCallback->doesCollide ())
{
OgreBulletDynamics::RigidBody * body = static_cast <OgreBulletDynamics::RigidBody *>
(mCollisionClosestRayResultCallback->getCollidedObject());
inters = mCollisionClosestRayResultCallback->getCollisionPoint ();
cout <<"Hit :"<< body->getName();
return body->getName();
}
}the picking code seems to work perfectly when intersecting ,meshes, but when the hit object is the terrain, there is a difference (in Z, OgreBullet reports 53 units more, I cant remember the exact difference). Can somebody see any problem here?