int example_customscenenode() { // create device IrrlichtDevice *device = startup(); if (device == 0) return 1; // could not create selected driver. // create engine and camera EventReceiver_basic receiver(device); device->setEventReceiver(&receiver); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); smgr->addCameraSceneNode(0, vector3df(0, -40, 0), vector3df(0, 0, 0)); CSampleSceneNode *myNode = new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666); ISceneNodeAnimator* anim = smgr->createRotationAnimator(vector3df(0.8f, 0, 0.8f)); if (anim) { myNode->addAnimator(anim); anim->drop(); anim = 0; // As I shouldn't refer to it again, ensure that I can't } myNode->drop(); myNode = 0; // As I shouldn't refer to it again, ensure that I can't return run(device); }
int main() { IrrlichtDevice* irrDevice = createDevice(EDT_OPENGL,dimension2d<s32>(800,600),32,false,false,false,0); IVideoDriver* irrVideo = irrDevice->getVideoDriver(); ISceneManager* irrSceneMgr = irrDevice->getSceneManager(); TMovie* movie = new TMovie(irrDevice->getTimer()); movie->LoadMovie("Mymovie.avi"); irrVideo->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); u32 w = movie->getMovieWidth(); u32 h = movie->getMovieHeight(); ITexture* movTxtr = irrVideo->addTexture(dimension2d<s32>(w<513?512:1024,h<513?512:1024),"imovie"); irrSceneMgr->addCameraSceneNode(0, vector3df(0,0,-20), vector3df(0,0,0)); CSampleSceneNode* myNode = new CSampleSceneNode(irrSceneMgr->getRootSceneNode(), irrSceneMgr, 666); myNode->setMaterialTexture( 0, movTxtr); myNode->drop(); ISceneNodeAnimator* anim = irrSceneMgr->createRotationAnimator(vector3df(0,0.1f,0)); myNode->addAnimator(anim); anim->drop(); while(irrDevice->run()) { irrVideo->beginScene(true, true, SColor(0,200,200,200)); if (movie->NextMovieFrame()) movie->DrawMovie(0,0,movTxtr); irrSceneMgr->drawAll(); irrVideo->endScene(); } irrDevice->drop(); return 0; }
GameFieldNeo::GameFieldNeo() : BaseGameEntity(BaseGameEntity::GetNextValidID(), vector3df(0.f, 0.f, 0.f), 0.f, vector3df(1.f, 1.f, 1.f)) { // get ready scene node ISceneManager* pSmgr = IrrDvc.GetSmgr(); m_pMesh = pSmgr->getMesh("Rsrc/Cube.dae"); if (m_pMesh) { m_pSceneNode = pSmgr->addAnimatedMeshSceneNode(m_pMesh); m_pSceneNode->setScale(vector3df(10.f, 10.f, 10.f)); m_pSceneNode->setMaterialFlag(video::EMF_LIGHTING, false); } scene::ISceneNodeAnimator* pAnim = pSmgr->createRotationAnimator(core::vector3df(1,1,1)); if (pAnim) { m_pSceneNode->addAnimator(pAnim); pAnim->drop(); } }
int main(int argc, char **argv) { // Help? if (argv[1] && argv[1][0] == '-') die(helpmsg); putenv((char *) "vblank_mode=0"); // No vsync for us, thanks. MyEventReceiver *r = new MyEventReceiver(); IrrlichtDevice *dev = createDevice(EDT_OPENGL, core::dimension2d<u32>(1024,768), 32, false, false, false, r); if (!dev) die("Can't initialize Irrlicht"); IVideoDriver *drv = dev->getVideoDriver(); ISceneManager *smgr = dev->getSceneManager(); IGPUProgrammingServices *gpu = drv->getGPUProgrammingServices(); ICameraSceneNode *cam = NULL; ITexture *pic = NULL; IMeshSceneNode *ball = NULL; bool showpic = false; IReadFile *areamap = createMemoryReadFile(AreaMap33, sizeof(AreaMap33), "AreaMap33", false); if (!areamap) die("Failed to load areamap"); ITexture *areamaptex = drv->getTexture(areamap); areamap->drop(); // If there's an argument, assume it is a pic to load; otherwise, draw a sphere if (argv[1] && access(argv[1], R_OK) == 0) { showpic = true; pic = drv->getTexture(argv[1]); if (!pic) die("Can't load image"); cam = smgr->addCameraSceneNode(); } else { cam = smgr->addCameraSceneNodeMaya(); cam->setTarget(vector3df(0, 0, 0)); ball = smgr->addSphereSceneNode(40, 8); int ballshader = gpu->addHighLevelShaderMaterial(rnd,0,EVST_VS_1_1,0); ball->setMaterialType((E_MATERIAL_TYPE) ballshader); ISceneNodeAnimator *cool = smgr->createRotationAnimator(vector3df(-0.1, 0.1, -0.1)); ball->addAnimator(cool); cool->drop(); } // Set up static defines, RTTs, quads dimension2d<u32> screensize = drv->getScreenSize(); char defines[128]; snprintf(defines, 128, "#define PIXEL_SIZE vec2(1.0f / %u.0, 1.0f / %u.0)\n" "#define MAX_SEARCH_STEPS 8.0\n#define MAX_DISTANCE 33.0\n", screensize.Width, screensize.Height); ITexture *rt1 = drv->addRenderTargetTexture(screensize, "rt1", ECF_A8R8G8B8); ITexture *rt2 = drv->addRenderTargetTexture(screensize, "rt2", ECF_A8R8G8B8); ITexture *rt3 = drv->addRenderTargetTexture(screensize, "rt3", ECF_A8R8G8B8); if (!rt1 || !rt2 || !rt3) die("No RTT"); ScreenQuad *def = new ScreenQuad(drv); ScreenQuad *sq = new ScreenQuad(drv); ScreenQuad *sq2 = new ScreenQuad(drv); ScreenQuad *sq3 = new ScreenQuad(drv); ScreenQuad *norm = new ScreenQuad(drv); if (showpic) def->SetTexture(pic); sq->SetTexture(rt1); sq->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false); norm->SetTexture(rt1); norm->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false); sq2->SetTexture(rt2); sq2->SetTexture(rt2, 1); sq2->SetTexture(areamaptex, 2); sq2->GetMaterial().TextureLayer[2].BilinearFilter = false; sq3->SetTexture(rt3); sq3->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false); sq3->SetTexture(rt1,1); state_t state = MLAA_OFF; stringc tmp1, tmp2; tmp1 = defines; tmp1 += offsetvs; tmp2 = defines; tmp2 += color1fs; // Load shaders int edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str()); sq->SetMaterialType((E_MATERIAL_TYPE) edge); tmp2 = defines; tmp2 += blend2fs; blendcb *bcb = new blendcb(); edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str(),0,EPST_PS_1_1,bcb); sq2->SetMaterialType((E_MATERIAL_TYPE) edge); tmp2 = defines; tmp2 += neigh3fs; neighcb *ncb = new neighcb(); edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str(),0,EPST_PS_1_1,ncb); sq3->SetMaterialType((E_MATERIAL_TYPE) edge); // Record start time int lastfps = -1, minfps = 10000; unsigned long long total_frames = 0, fxtimer = 0, tmplong, onframes = 0; struct timeval starttime, tick1, tick2; float glsltime = 0; gettimeofday(&starttime, NULL); wchar_t cap[20]; glEnable(GL_STENCIL_TEST); unsigned char firstrun = 1; // To avoid the glsl compiler in the timing // Main loop while (dev->run()) { gettimeofday(&tick1, NULL); drv->beginScene(); switch (state) { case MLAA_OFF: if (showpic) def->Render(false); else smgr->drawAll(); break; case MLAA_ON: if (showpic) def->Render(rt1); else { drv->setRenderTarget(rt1); smgr->drawAll(); } glClear(GL_STENCIL_BUFFER_BIT); glStencilFunc(GL_ALWAYS, 1, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); sq->Render(rt2); glStencilFunc(GL_EQUAL, 1, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); sq2->Render(rt3); drv->setRenderTarget(rt1, false, false); // Overlay the smoothed edges on the initial image sq3->Render(false); // Blit the final image to the framebuffer glStencilFunc(GL_ALWAYS, 1, ~0); norm->Render(); break; } drv->endScene(); if (state == MLAA_ON) { gettimeofday(&tick2, NULL); if (!firstrun) { tmplong = (tick2.tv_sec - tick1.tv_sec) * 10000; tmplong += (tick2.tv_usec - tick1.tv_usec) / 100; fxtimer += tmplong; onframes++; } else { firstrun = 0; glsltime = tick2.tv_sec - tick1.tv_sec; glsltime += (tick2.tv_usec - tick1.tv_usec) / 1000000.0; } } int fps = drv->getFPS(); if (minfps > fps) minfps = fps; if (lastfps != fps) { swprintf(cap, 20, L"%d fps, MLAA %s", fps, state == MLAA_ON ? "on" : "off"); dev->setWindowCaption(cap); lastfps = fps; } if (r->IsKeyDown(KEY_KEY_M)) { if (state == MLAA_ON) state = MLAA_OFF; else state = MLAA_ON; lastfps++; } usleep(1); // 16? total_frames++; } dev->drop(); delete ncb; delete bcb; delete def; delete sq; delete sq2; delete sq3; delete norm; delete r; struct timeval endtime; gettimeofday(&endtime, NULL); float sec = endtime.tv_sec - starttime.tv_sec; sec += ((float) endtime.tv_usec - starttime.tv_usec) / 1000000; printf("\nRan %.3fs, ", sec); sec -= glsltime; printf("average fps %.2f, min %d\n", (float) total_frames/sec, minfps); if (onframes) { printf("\nAverage on fps %.2f, average off fps %.2f\n\n", (float) onframes/(fxtimer/10000.0), (float) (total_frames - onframes)/(sec - (fxtimer/10000.0))); // printf("MLAA took on average %.1fms\n", (float) (fxtimer / onframes) / 10.0); } return 0; }
/** Test functionality of the ISceneNodeAnimator implementations. */ bool sceneNodeAnimator(void) { IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(160, 120)); assert_log(device); if(!device) return false; ISceneManager * smgr = device->getSceneManager(); // Test the hasFinished() method. ISceneNodeAnimatorCollisionResponse* collisionResponseAnimator = smgr->createCollisionResponseAnimator(0, 0); ISceneNodeAnimator* deleteAnimator = smgr->createDeleteAnimator(1); ISceneNodeAnimator* flyCircleAnimator = smgr->createFlyCircleAnimator(); ISceneNodeAnimator* flyStraightAnimator = smgr->createFlyStraightAnimator(vector3df(0, 0, 0), vector3df(0, 0, 0), 1, false); ISceneNodeAnimator* flyStraightAnimatorLooping = smgr->createFlyStraightAnimator(vector3df(0, 0, 0), vector3df(0, 0, 0), 1, true); ISceneNodeAnimator* rotationAnimator = smgr->createRotationAnimator(vector3df(0, 0, 0)); array<vector3df> points; points.push_back(vector3df(0, 0, 0)); points.push_back(vector3df(0, 0, 0)); ISceneNodeAnimator* followSplineAnimator = smgr->createFollowSplineAnimator(0, points, 1000.f); array<video::ITexture*> textures; textures.push_back(0); textures.push_back(0); ISceneNodeAnimator* textureAnimator = smgr->createTextureAnimator(textures, 1, false); ISceneNodeAnimator* textureAnimatorLooping = smgr->createTextureAnimator(textures, 1, true); bool result = true; ISceneNode * deletedNode = smgr->addEmptySceneNode(); deletedNode->addAnimator(deleteAnimator); ISceneNode * testNode = smgr->addEmptySceneNode(); testNode->addAnimator(collisionResponseAnimator); testNode->addAnimator(deleteAnimator); testNode->addAnimator(flyCircleAnimator); testNode->addAnimator(flyStraightAnimator); testNode->addAnimator(flyStraightAnimatorLooping); testNode->addAnimator(rotationAnimator); testNode->addAnimator(followSplineAnimator); testNode->addAnimator(textureAnimator); testNode->addAnimator(textureAnimatorLooping); result &= !collisionResponseAnimator->hasFinished(); result &= !deleteAnimator->hasFinished(); result &= !flyCircleAnimator->hasFinished(); result &= !flyStraightAnimator->hasFinished(); result &= !flyStraightAnimatorLooping->hasFinished(); result &= !rotationAnimator->hasFinished(); result &= !followSplineAnimator->hasFinished(); result &= !textureAnimator->hasFinished(); result &= !textureAnimatorLooping->hasFinished(); device->run(); device->sleep(10); device->run(); smgr->drawAll(); // These animators don't have an endpoint. result &= !collisionResponseAnimator->hasFinished(); result &= !flyCircleAnimator->hasFinished(); result &= !rotationAnimator->hasFinished(); result &= !followSplineAnimator->hasFinished(); // These animators are looping and so can't finish. result &= !flyStraightAnimatorLooping->hasFinished(); result &= !textureAnimatorLooping->hasFinished(); // These have an endpoint and have reached it. result &= deleteAnimator->hasFinished(); result &= flyStraightAnimator->hasFinished(); result &= textureAnimator->hasFinished(); collisionResponseAnimator->drop(); deleteAnimator->drop(); flyCircleAnimator->drop(); flyStraightAnimator->drop(); flyStraightAnimatorLooping->drop(); rotationAnimator->drop(); followSplineAnimator->drop(); textureAnimator->drop(); textureAnimatorLooping->drop(); device->closeDevice(); device->run(); device->drop(); if(!result) { logTestString("One or more animators has a bad hasFinished() state\n."); assert_log(false); } return result; }