Yet another attempt
I cant seem to get the result i would expect. I would expect when hovering the first added point the coordinate 0,0,0 would be traced.
I noticed the code in the topic linked above uses a animated mesh but this isnt the problem is it?
let me show you what i have so far
Adding data:
Code: Select all
void AddDataIrrlicht()
{
//return;
irr::video::SMaterial Material;
Material.Lighting = false;
Material.Wireframe = false;
Material.PointCloud = true;
Material.Thickness = 5;
irr::scene::SMesh* smesh = new irr::scene::SMesh();
const unsigned int numberOfPoints = 50000;
for(int id = 0; id < 40; id++)
{
irr::scene::SMeshBuffer *buffer = new irr::scene::SMeshBuffer();
buffer->Material = Material;
buffer->Vertices.reallocate(numberOfPoints);
for(int pointCounter = 0; pointCounter < numberOfPoints; ++pointCounter)
{
irr::video::S3DVertex pointVertex = irr::video::S3DVertex(pointCounter, 0, id,
0, 0, -1,
irr::video::SColor(255,0,0,0),
0, 1);
buffer->Vertices.push_back(pointVertex);
buffer->Indices.push_back(id * pointCounter + pointCounter -1);
}
buffer->recalculateBoundingBox();
smesh->addMeshBuffer(buffer);
}
smesh->recalculateBoundingBox();
//EHM_STREAM
smesh->setHardwareMappingHint(irr::scene::EHM_STATIC, irr::scene::EBT_VERTEX_AND_INDEX);
m_smgr->addMeshSceneNode(smesh);
}
Collision detection:
Code: Select all
while(m_device->run())
{
irr::core::position2di initialCursorPosition;
irr::core::position2di initialObjectPosition;
irr::scene::ISceneNode* SelectedNode = m_smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(m_device->getCursorControl()->getPosition(),0,false);
//If we selected a node
if(SelectedNode)
{
irr::core::plane3df const planeXZ(SelectedNode->getAbsolutePosition(), irr::core::vector3df(0.f, 1.f, 0.f));
irr::core::position2di currentCursorPosition(m_device->getCursorControl()->getPosition());
irr::core::line3df ray(m_smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(currentCursorPosition, m_smgr->getActiveCamera()));
irr::core::vector3df intersectWithPlane;
if(planeXZ.getIntersectionWithLine(ray.start, ray.getVector(), intersectWithPlane))
{
TRACE("Object pos: %d %d %d \n", intersectWithPlane.X, intersectWithPlane.Y, intersectWithPlane.Z);
}
}
m_driver->beginScene(true, true, irr::video::SColor(255,200,200,200));
m_smgr->drawAll();
m_driver->endScene();
}