It seems works pretty nice when a zone is flat as in this pic:
But it seems to fly over the terrain if a ground down:
How do i fix it?
Here's my code:
Terrain
Code: Select all
// Create Island
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"media/models/heightmaps/island_HM.jpg",
0, // parent node
-1, // node id
core::vector3df(-6000.f, -2703.f, -3000.f), // position
core::vector3df(0.f, 0.f, 0.f), // rotation
core::vector3df(10.f, 15.f, 10.f), // scale 10,7,10
video::SColor ( 255, 255, 255, 255 ), // vertexColor
4, // maxLOD
scene::ETPS_17, // patchSize
4 // smoothFactor
);
terrain->setMaterialTexture(0,
driver->getTexture("media/models/heightmaps/island_TX.jpg"));
terrain->setMaterialTexture(1,
driver->getTexture("media/data/detail5.bmp"));
terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(1.0f, 5000.0f);
terrain->setMaterialFlag(video::EMF_FOG_ENABLE, true);
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->getMesh()->setHardwareMappingHint(EHM_STATIC);
scene::CDynamicMeshBuffer* buffer =
new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_32BIT);
terrain->getMeshBufferForLOD(*buffer, 0);
video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)
buffer->getVertexBuffer().getData();
buffer->drop();
Code: Select all
IAnimatedMesh* dmesh = smgr->getMesh("media/models/md2/player.md2");
if (!dmesh)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* dnode = smgr->addAnimatedMeshSceneNode( dmesh );
if (dnode)
{
dnode->setMaterialFlag(EMF_LIGHTING, true);
dnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
dnode->setMD2Animation(scene::EMAT_STAND);
dnode->setAnimationSpeed(15);
dnode->setMaterialTexture( 0,
driver->getTexture("media/models/md2/player.jpg"));
dnode->setPosition(vector3df(-2445,150,5140));
dnode->setScale(vector3df(0.01,0.01,0.01));
dnode->setRotation(vector3df(0,90,0));
}
Code: Select all
// Create Triangle Selector for the terrain
scene::ITriangleSelector* selector
= smgr->createTerrainTriangleSelector(terrain, 0);
terrain->setTriangleSelector(selector);
// Meta Triangle Selector
scene::IMetaTriangleSelector* metaSelector = smgr->createMetaTriangleSelector();
metaSelector->addTriangleSelector(selector);
// Collision
ISceneNodeAnimatorCollisionResponse* anim1;
anim1 = smgr->createCollisionResponseAnimator(
metaSelector, dnode, core::vector3df(25,50,25),
core::vector3df(0, terrain ? -2.5 : 0.0,0),
core::vector3df(0,-49.78,0), 0.005f);
dnode->addAnimator(anim1);
anim1->drop();