|
class ProjectiveDecalApplication : public ExampleApplication
{
protected:
void createScene()
{
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);
// Position the camera
mCamera->setPosition(60, 200, 70);
mCamera->lookAt(0,0,0);
ent = mSceneMgr->createEntity("robot","robot.mesh");
m_waterNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
m_waterNode2->attachObject(ent1);
// Make all of the materials in the head entities receive the decal
for (unsigned int i = 0; i < ent1->getNumSubEntities(); i++)
makeMaterialReceiveDecal(ent1->getSubEntity(i)->getMaterialName());
//m_waterNode2->setPosition(100,0,0); //向X轴移动100个单位
}
void makeMaterialReceiveDecal(const String &matName)
{
// get the material
mat = (MaterialPtr)MaterialManager::getSingleton().getByName(matName);
// create a new pass in the material to render the decal
Pass *pass = mat->getTechnique(0)->createPass();
// set our pass to blend the decal over the model's regular texture
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
pass->setDepthBias(1);
// set the decal to be self illuminated instead of lit by scene lighting
pass->setLightingEnabled(false);
// set up the decal's texture unit
TextureUnitState *texState = pass->createTextureUnitState("decal.png");
texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
texState->setTextureFiltering(FO_POINT, FO_LINEAR, FO_NONE);
}
// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new ProjectiveDecalListener(mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
};
其运行效果如下:

这样看起来没有什么问题,但是如果把CreateScene()这个函数中的最后一行代码"m_waterNode2->setPosition(100,0,0);"的注释去掉的话,结果就奇怪了:

这是为什么呢?makeMaterialReceiveDecal函数是在机器人的材质脚本中添加一个渲染通道,decal.png应该始终和机器人的材质在一起才对呀,怎么移动机器人后,decal.png还留在原地呢???哪位大大可以给小弟解下惑啊~~?谢谢了先~~
|
|