是否存在单个命令来标记/启用给定场景管理器中所有节点的阴影?
目前,我可以从所有节点投射阴影,但是我必须为每个场景节点一次又一次地调用相同的函数 addShadowVolumeSceneNode(); 。较小的玩具代码可以这样做,但是随着代码的复杂性和大小的增加,它可能不太理想。
这是我正在使用的代码:
#include <irrlicht.h>
#include "driverChoice.h"
using namespace irr;
using namespace scene;
using namespace core;
using namespace video;
int main()
{
/* create device */
IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640, 480), 16, false, true);
if (device == 0)
return 1;
/* create engine and camera */
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNode(0, core::vector3df(0,-100,0), core::vector3df(0,0,0));
smgr->addLightSceneNode(0, core::vector3df(0,0,400), video::SColorf(1.0f, 1.0f, 0.0f, 0.0f), 800.0f);
/* Add cube */
scene::IMeshSceneNode* node_cube = smgr->addCubeSceneNode(30);
smgr->setShadowColor(video::SColor(150,0,0,0));
node_cube->setPosition(core::vector3df(0,0,-80));
node_cube->setMaterialFlag(video::EMF_LIGHTING, true);
node_cube->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
node_cube->addShadowVolumeSceneNode();
/* Another cube */
scene::IMeshSceneNode* node_cube2 = smgr->addCubeSceneNode(20);
smgr->setShadowColor(video::SColor(150,0,0,0));
node_cube2->setPosition(core::vector3df(0,0,-45));
node_cube2->setMaterialFlag(video::EMF_LIGHTING, true);
node_cube2->setMaterialFlag(video::EMF_BILINEAR_FILTER, true);
node_cube2->addShadowVolumeSceneNode();
/* And another cube */
scene::IMeshSceneNode* node_cube3 = smgr->addCubeSceneNode(10);
smgr->setShadowColor(video::SColor(150,0,0,0));
node_cube3->setPosition(core::vector3df(0,0,-20));
node_cube3->setMaterialFlag(video::EMF_LIGHTING, true);
node_cube3->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
node_cube3->addShadowVolumeSceneNode();
/* Now draw everything and finish */
u32 frames=0;
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
if (++frames==100)
{
core::stringw str = L"Irrlicht Engine [";
str += driver->getName();
str += L"] FPS: ";
str += (s32)driver->getFPS();
device->setWindowCaption(str.c_str());
frames=0;
}
}
device->drop();
return 0;
}
谢谢!
答案 0 :(得分:2)
创建工厂功能:
scene::IMeshSceneNode* CreateCubeWithShadow(scene::ISceneManager* smgr, const core::vector3df &pos)
{
scene::IMeshSceneNode* node_cube = smgr->addCubeSceneNode(10);
node_cube->setPosition(pos);
node_cube->setMaterialFlag(video::EMF_LIGHTING, true);
node_cube->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
node_cube->addShadowVolumeSceneNode();
return node_cube;
}
然后在需要新节点时调用它:
scene::IMeshSceneNode* node_cube1 = CreateCubeWithShadow(smgr, core::vector3df(0,0,-80));
scene::IMeshSceneNode* node_cube2 = CreateCubeWithShadow(smgr, core::vector3df(0,0,-45));
scene::IMeshSceneNode* node_cube3 = CreateCubeWithShadow(smgr, core::vector3df(0,0,-20));
也无需为每个节点调用smgr->setShadowColor(video::SColor(150,0,0,0));
,这是全局设置。