Hi,
I have a large mesh. It is only visible if the camera is positioned far away, and disappears as the camera moves closer. From other threads I gathered it could be that the bounding box of the mesh buffers and mesh itself need to be recalculated. I tried that without success. If I position the camera close to the mesh, it is not visible at all.
Any advice would be appreciated.
Thanks
Willem
Code: Select all
void recalc_bbox(SAnimatedMesh* m)
{
u32 count = m->getMeshBufferCount();
IMeshBuffer* b;
for (u32 i = 0; i < count; i++) {
b = m->getMeshBuffer(i);
b->recalculateBoundingBox();
}
m->recalculateBoundingBox();
}
int main(void)
{
float x = 0, y = 1.0f, z = 0;
int lastfps = 0, fps = 0, count = 0;
SAnimatedMesh smesh;
IrrlichtDevice* device = createDevice(video::EDT_OPENGL,
(core::dimension2d<u32>(640, 480)), 16,
false, false, false, 0);
if (!device)
return 1;
device->setWindowCaption(L"Hello world");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
ICameraSceneNode* cam = NULL;
guienv->addStaticText(L"Hello world", rect<s32>(10, 10, 260,22));
IAnimatedMesh* mesh = smgr->getMesh("data/irrlicht/mdl/road.irrmesh");
if (!mesh) {
return 1;
}
smesh.addMesh((IMesh*)mesh);
IAnimatedMeshSceneNode* node =
smgr->addAnimatedMeshSceneNode(mesh);
if (node) {
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture(0,
driver->getTexture("data/gimp/tarsmooth_vert_512X512.bmp"));
node->setPosition(vector3df(-4.970404, 0, -2.243534));
}
cam = smgr->addCameraSceneNode(0,
vector3df(0, y, 0), // camera pos
vector3df(0, 0.009562, 0)); // lookat pos
//smgr->addCameraSceneNodeFPS(0, 5.0f, 0.001f);
while (device->run()) {
driver->beginScene(true, true, SColor(255, 255, 255, 255));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
cam->setPosition(vector3df(0, y, 0));
y -= 0.001;
usleep(50000);
recalc_bbox(&smesh);
fps = driver->getFPS();
if (lastfps != fps) {
stringw str = driver->getName();
str += " Fps:";
str += fps;
device->setWindowCaption(str.c_str());
lastfps = fps;
}
if ((count++ % 400) == 0) {
//takeScreenshot(device);
}
}
device->drop();
return 0;
}