Using this code from the forum i can get collision with terrain under cursor. The trouble is as i raise or lower terrain the selected triangle is no longer UNDER the cursor. If i want to select the top of a hill for example, i need to place my mouse on the bottom of the hill. On a location with height 0 i instead select the tringle right under the mouse.
It seems to select the tringle that would be under the mouse if the terrain had no height... Is there any way to fix this so i always select what is ACTUALLY under the cursor?
Thanks
Code: Select all
// move the arrow to the nearest vertex ...
const position2di mousePosition = myDevice->getCursorControl()->getPosition();
const line3df ray = gfx.smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(mousePosition, ppp.camera);
vector3df pos2;
triangle3df Tri;
const scene::ISceneNode* hitNode;
if(ppp.mouse.Y<SCREENY-150)
if (gfx.smgr->getSceneCollisionManager()->getCollisionPoint(ray, selector, pos2, Tri,hitNode))
{
//arrow->setPosition(pos);
static const s32 scale = MAP_SCALE; // terrain is scaled
static const s32 size = HEIGHTMAP_SIZE; // heightmap pixel-size
s32 x = (s32)(pos2.X / scale);
s32 z = (s32)(pos2.Z / scale);
s32 index = x * size + z;