Code: Select all
// animated texture matrix test.
void test10()
{
static bool m_running = true;
class EventReceiver : public IEventReceiver
{
bool OnEvent(const SEvent& event)
{
if ((event.EventType == irr::EET_KEY_INPUT_EVENT) &&
!event.KeyInput.PressedDown &&
(event.KeyInput.Key == KEY_ESCAPE))
m_running = false;
return false;
}
};
SIrrlichtCreationParameters cp;
//cp.DriverType = EDT_DIRECT3D9;
cp.DriverType = EDT_OPENGL;
cp.WindowSize = dimension2du(640,480);
cp.EventReceiver = new EventReceiver();
IrrlichtDevice* m_device = createDeviceEx(cp);
if(!m_device)
return;
m_device->getCursorControl()->setVisible(false);
IFileSystem* m_fileSystem = m_device->getFileSystem();
IVideoDriver* m_videoDriver = m_device->getVideoDriver();
ISceneManager* m_sceneManager = m_device->getSceneManager();
IGUIEnvironment* m_gui = m_device->getGUIEnvironment();
ICameraSceneNode* m_camera = m_sceneManager->addCameraSceneNodeFPS(0, 100, 0.02f);
m_camera->setPosition(vector3df(0,0,-10));
// set up plane mesh to face the camera
dimension2df tileSize(150,150);
dimension2d<u32> tileCount(1,1);
IAnimatedMesh* pmesh = m_sceneManager->addHillPlaneMesh("testMesh" ,tileSize, tileCount);
IAnimatedMeshSceneNode* pnode = m_sceneManager->addAnimatedMeshSceneNode(pmesh);
pnode->setPosition(vector3df(0, 0, 150));
pnode->setRotation(vector3df(-90, 0, 0));
// set the hillplane material texture & save a reference
// to the texture matrix.
SMaterial& material = pnode->getMaterial(0);
ITexture* tex = m_videoDriver->getTexture("../media/water.jpg");
material.setTexture(0,tex);
material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
material.setFlag(EMF_LIGHTING,false);
matrix4& textureMatrix = material.TextureLayer[0].getTextureMatrix();
u32 lastTime = m_device->getTimer()->getTime();
vector2df rcenter, trans, scale(1.f, 1.f);
f32 scrollSpeed = 0.5f;
while(m_device->run() && m_running)
{
m_videoDriver->beginScene(true, true, SColor(255,100,101,140));
// update the texture matrix (scroll left)
u32 curTime = m_device->getTimer()->getTime();
irr::u32 t = curTime - lastTime;
if(t)
{
lastTime = curTime;
trans.X += t * 0.001f * scrollSpeed;
textureMatrix.buildTextureTransform(0.f, rcenter, trans, scale);
}
m_sceneManager->drawAll();
m_gui->drawAll();
m_videoDriver->endScene();
}
m_device->drop();
}