int main( ) { // Boring stuff: set up the scene, object & camera as usual IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 ); IVideoDriver* driver = device->getVideoDriver( ); ISceneManager* smgr = device->getSceneManager( ); IGUIEnvironment* guienv = device->getGUIEnvironment( ); device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY ); guienv->addStaticText( L"Lens Flare", rect<s32>( 10, 10, 260, 22 ), true ); IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) ); node->setMaterialFlag( EMF_LIGHTING, false ); node->setMD2Animation( scene::EMAT_STAND ); node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") ); IAnimatedMeshSceneNode* node2 = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) ); node2->setMaterialFlag( EMF_LIGHTING, false ); node2->setMD2Animation( scene::EMAT_STAND ); node2->setMaterialTexture( 0, driver->getTexture("sydney.bmp") ); node2->setPosition( vector3df( 20.0f, 0.0f, 0.0f ) ); ICameraSceneNode* cam = smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) ); ISceneNode* sun = smgr->addSphereSceneNode( 50.0f, 16 ); sun->setPosition( vector3df( 0.0f, 50.0f, 1000.0f ) ); sun->setMaterialFlag( EMF_LIGHTING, false ); sun->setMaterialTexture( 0, driver->getTexture("sun.png") ); // Interesting stuff // As before, we make a renderer IPostProc* ppRenderer = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) ); // Now make a flare effect: // (render from, output size, sun scene node) // can also use a vector instead of a scene node - when using a scene node the position will follow node automatically CLensFlarePostProc* ppFlare1 = new CLensFlarePostProc( ppRenderer, dimension2di( 1024, 512 ), driver->getTexture("flare.png"), sun, 50.0f ); CLensFlarePostProc* ppFlare2 = new CLensFlarePostProc( ppFlare1, dimension2di( 1024, 512 ), driver->getTexture("flare.png"), vector3df( -2000.0f, 50.0f, 1000.0f ) ); ppFlare2->setQuality( PPQ_CRUDE ); // Setting the quality to crude avoids pixel checking, which is slow (expecially when more than one lens flare), so if you use >1 flare, set most of them to crude. // These variables aren't important - they are just for showing the FPS wchar_t tmp[255]; u8 t = 0u; while( device->run( ) ) { cam->setPosition( vector3df( -(device->getCursorControl( )->getPosition( ).X - 320.0f) * 0.1f, (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.2f, -70.0f ) ); driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 ); ppFlare2->render( NULL ); guienv->drawAll( ); driver->endScene( ); // Show the current FPS if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); } } delete ppFlare1; delete ppFlare2; delete ppRenderer; // Back to boring stuff device->drop(); return 0; }
// ---------------------------------------------------------------------------- ISceneNode* CheckLineHandler::startPlacingNew() { std::list<CheckLine>::iterator it = m_check_lines.begin(); while (it != m_check_lines.end() && it->active) it++; m_check_lines.erase(it, m_check_lines.end()); ISceneManager* sm = Editor::getEditor()->getSceneManager(); m_clip.n1 = sm->addSphereSceneNode(0.2, 16, 0, ANOTHER_MAGIC_NUMBER); return m_clip.n1; } // startPlacingNew
// ---------------------------------------------------------------------------- ISceneNode* CheckLineHandler::place() { if (m_clip.n2) { m_clip.active = true; m_check_lines.push_back(m_clip); m_clip.n1 = 0; m_clip.n2 = 0; m_clip.active = true; return 0; } ISceneManager* sm = Editor::getEditor()->getSceneManager(); m_clip.n2 = sm->addSphereSceneNode(0.2,16,0,ANOTHER_MAGIC_NUMBER); return m_clip.n2; } // place
int main() { srand(time(NULL)); int numPlayers = 4; //Setup irrlicht MyEventReceiver Receiver; IrrlichtDevice *device = createDevice(EDT_OPENGL,dimension2d<u32>(SCREENX,SCREENY),32,FULLSCREEN,false,false,&Receiver); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); //Load key config Receiver.KeyConfig.loadFromFile("KeyConfig.txt"); //Generate maze MazeGenerator MG; /* MG.NewSize(495,497,495,497); MG.Generate("DrunkenWalk2",500,numPlayers);//500,numPlayers); MG.Minimise(); MG.MinimalSolids(false); MG.ConvertLoneToCover();*/ MG.MapFromFile("Maps/01g.txt", "Maps/01m.txt", "Maps/01e.txt"); vector<int> PlayerStartPos; PlayerStartPos.push_back(10); PlayerStartPos.push_back(11); PlayerStartPos.push_back(12); PlayerStartPos.push_back(13); MG.ParseForPlayerStartPositions(PlayerStartPos); //Setup textures ITexture *FloorTexture = driver->getTexture("Textures/Floor.png"); ITexture *WallTexture = driver->getTexture("Textures/Wall.png"); ITexture *CoverTexture = driver->getTexture("Textures/Cover.png"); //Import maze MazeRenderer MR; MR.CreateFromMazeGenerator( MG, smgr ); MR.SetTextures( FloorTexture, WallTexture, CoverTexture ); //Setup camera GameCamera gameCam(70); gameCam.camera = smgr->addCameraSceneNode(); gameCam.camera->setPosition( vector3df( (MR.XSize/2)*MR.TileSize, 40, (MR.YSize/2)*MR.TileSize ) ); gameCam.camera->setRotation( vector3df(0,90,90)); //Create players (4) for testing //Have to use an array as you can't copy boost::threads which pushing into vectors does EntityManager PlayerManager(numPlayers); //Textures ITexture* PlayerTexture[4]; PlayerTexture[0] = driver->getTexture("Textures/Player1.png"); PlayerTexture[1] = driver->getTexture("Textures/Player2.png"); PlayerTexture[2] = driver->getTexture("Textures/Player3.png"); PlayerTexture[3] = driver->getTexture("Textures/Player4.png"); //Names vector<std::string> PlayerName; PlayerName.push_back("Motoko"); PlayerName.push_back("Saito"); PlayerName.push_back("Batou"); PlayerName.push_back("Togusa"); //use this method to get starting cells for an enemy group vector<v2d> vv = GetFreeCells(MG.Convert(),MG.StartX,MG.StartY,4); //HUD test hud HUD(guienv,dimension2d<s32>(SCREENX,SCREENY),"Font\\myfont.xml"); for (int i = 0; i < numPlayers; i++ ) { PlayerManager.GetEntity(i)->Construct(smgr,MG.Convert(), PlayerTexture[i]); PlayerManager.GetEntity(i)->Stats.Name = PlayerName[i]; PlayerManager.GetEntity(i)->Stats.MaxHealth = 100; PlayerManager.GetEntity(i)->Stats.RestoreAll(); PlayerManager.GetEntity(i)->X = MG.XStarts[i]; PlayerManager.GetEntity(i)->Y = MG.YStarts[i]; PlayerManager.GetEntity(i)->Stats.MovementSteps = 5+i; PlayerManager.GetEntity(i)->ReachableTile = driver->getTexture("Textures/TurnReachable.png"); PlayerManager.GetEntity(i)->UnreachableTile = driver->getTexture("Textures/TurnUnreachable.png"); PlayerManager.GetEntity(i)->Stats.RealFiringDistance = 100; PlayerManager.GetEntity(i)->CellShootable = driver->getTexture("Textures/CellShootable.png"); PlayerManager.GetEntity(i)->CellShootableCover = driver->getTexture("Textures/CellShootableCover.png"); PlayerManager.GetEntity(i)->Position(); path filename = "Avatars/"; filename.append(PlayerName[i].c_str()); filename.append(".png"); PlayerManager.GetEntity(i)->Avatar = driver->getTexture( filename ); //test stats PlayerManager.GetEntity(i)->Stats.Accuracy = 100; PlayerManager.GetEntity(i)->Stats.Attack = 100; PlayerManager.GetEntity(i)->Stats.AttackVariance = 0; PlayerManager.GetEntity(i)->Stats.Defense = 0; PlayerManager.GetEntity(i)->Stats.DefenseVariance = 0; } // Create the 3D cursor ISceneNode *Cursor = smgr->addSphereSceneNode(4); //Setup AI int numEnemies = 1; EntityManager EnemyManager(numEnemies); //Textures (none for now) //Need to keep track of all entity positions, so they don't get placed ontop of each other vector<Entity*> EntityList( PlayerManager.GetEntityList() ); for (int i = 0; i < numEnemies; i++) { EnemyManager.GetEntity(i)->Construct(smgr,MG.Convert(), driver->getTexture("Textures/Enemy.png")); EnemyManager.GetEntity(i)->Stats.Name = PlayerName[i]; EnemyManager.GetEntity(i)->Stats.MaxHealth = 100; EnemyManager.GetEntity(i)->Stats.RestoreAll(); EnemyManager.GetEntity(i)->Stats.MovementSteps = 5+i; EnemyManager.GetEntity(i)->Stats.RealFiringDistance = 100; EnemyManager.GetEntity(i)->Stats.Attack = 50; EnemyManager.GetEntity(i)->Stats.Accuracy = 100; //Stats //steup random position EnemyManager.GetEntity(i)->AI_SetRandomDestination(EntityList); EnemyManager.GetEntity(i)->X = EnemyManager.GetEntity(i)->AI_DestinationX; EnemyManager.GetEntity(i)->Y = EnemyManager.GetEntity(i)->AI_DestinationY; //new path will be created EnemyManager.GetEntity(i)->Position(); EnemyManager.GetEntity(i)->AI_State = AI::Patrol; EnemyManager.GetEntity(i)->isAI = true; EntityList.push_back(EnemyManager.GetEntity(i)); } bool rkf = false; //Game loop while (device->run()) { //Create a list of all entities EntityList.clear(); vector<Entity*> EnemyList( EnemyManager.GetEntityList() ); EntityList.insert( EntityList.end(), EnemyList.begin(), EnemyList.end() ); /* * * * * * * * * * * * * * */ /* Player switching module */ /* * * * * * * * * * * * * * */ for (int i = 0; i < PlayerManager.Size; i++) PlayerManager.GetEntity(i)->CheckIfDead(); PlayerManager.ManageCharacterSwitching(Receiver); /* * * * * * * * * * * */ /* Pathfinding module */ /* * * * * * * * * * * */ PlayerManager.GetCurrentEntity()->UpdatePathDisplayTimer(); if (Receiver.MouseState.LeftButtonDown && PlayerManager.GetCurrentEntity()->NewPathDisplayTimer < 1) PlayerManager.GetCurrentEntity()->CreatePathToDestination(EntityList,smgr,Receiver,Cursor->getPosition(),dimension2d<s32>(MR.XSize,MR.YSize),MG.Convert()); /* * * * * * * * * * * * * */ /* Update position module */ /* * * * * * * * * * * * * */ PlayerManager.GetCurrentEntity()->Position(); /* * * * * * * * * * * */ /* Follow path module */ /* * * * * * * * * * * */ if (Receiver.IsKeyDown(Receiver.KeyConfig.FOLLOW_PATH)) PlayerManager.GetCurrentEntity()->FollowPath(EntityList); /* * * * * * * * * */ /* End turn module */ /* * * * * * * * * */ if (Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN) && !rkf) { rkf = true; PlayerManager.EndTurn(); EnemyManager.AI_StartTurn(EntityList, PlayerManager, smgr, Receiver, irr::core::dimension2d<s32>(MR.XSize,MR.YSize), MG.Convert(), MR.MetaTriangleSelector, MR.MetaCoverTriangleSelector); PlayerManager.StartTurn(); } else if (!Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN)) rkf = false; /* * * * * * * * */ /* Cursor module */ /* * * * * * * * */ Cursor->setPosition( vftovi(MouseTo3D( Receiver, MR.CollisionManager, MR.TriSelector)) ); /* * * * * * * * */ /* Camera module */ /* * * * * * * * */ gameCam.Update(Receiver,PlayerManager.GetCurrentEntity()->Node); /* * * * * * * * * * * * */ /* Stats monitor module */ /* * * * * * * * * * * * */ for (int i=0;i<PlayerManager.Size;i++) PlayerManager.GetEntity(i)->Stats.MonitorAll(); /* * * * * * * * * * */ /* Draw scene module */ /* * * * * * * * * * */ driver->beginScene(true,true,SColor(255,100,101,140)); smgr->drawAll(); guienv->drawAll(); HUD.Draw(guienv,PlayerManager.GetCurrentEntity()->Stats,PlayerManager.GetCurrentEntity()->Avatar); //HUD.DrawAIDebug(guienv,*EnemyManager.GetEntity(0),PlayerManager); driver->endScene(); /* * * * * * * */ /* Menu module */ /* * * * * * * */ if (Receiver.IsKeyDown(Receiver.KeyConfig.MENU)) return 0; /* * * * * * * * * * * * */ /* Firing display module */ /* * * * * * * * * * * * */ if (!Receiver.IsKeyDown(KEY_KEY_S)) PlayerManager.GetCurrentEntity()->ShootDisplayKeyFlag = false; else { PlayerManager.GetCurrentEntity()->ShootDisplayKeyFlag = true; PlayerManager.GetCurrentEntity()->DisplayAllCellsThatCanBeShotUsingThreads(smgr,MR.CollisionManager,MR.MetaTriangleSelector,MR.MetaCoverTriangleSelector); } /* * * * * * * * * */ /* Firing module * */ /* * * * * * * * * */ if (Receiver.MouseState.RightButtonDown && !PlayerManager.GetCurrentEntity()->RightMouseFlag) { PlayerManager.GetCurrentEntity()->RightMouseFlag = true; //second playerManager needs to replaced with enemyManager when in place, the function will also need to be edited FireAtTarget(Receiver, PlayerManager, EnemyManager, MR, smgr, Cursor); } else if (!Receiver.MouseState.RightButtonDown) PlayerManager.GetCurrentEntity()->RightMouseFlag = false; } return 0; }
int main() { IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1024, 768), 32, false, false, true, 0); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); smgr->addCameraSceneNodeFPS(); const s32 randLength = 1024; srand(device->getTimer()->getRealTime()); //Creating the grid for unit measure, etc u32 tileNumber = 128; IAnimatedMesh* groundMesh = smgr->addHillPlaneMesh("", dimension2d<float>(8,8),dimension2d<u32>(tileNumber,tileNumber),0,0.0f,dimension2df(0,0),dimension2df(tileNumber,tileNumber)); IAnimatedMeshSceneNode * groundNode = smgr->addAnimatedMeshSceneNode(groundMesh); groundNode->setMaterialTexture(0,driver->getTexture("../media/grid2.png")); groundNode->setMaterialFlag(EMF_LIGHTING,false); groundNode->setPosition(vector3df(0,-2,0)); //obstacles for stuff EntityGroup obstacles; for(int i = 0; i < 20; i++) { ISceneNode* s = smgr->addSphereSceneNode(20); IrrlichtBaseEntity * e = new IrrlichtBaseEntity(s); s->setPosition(vector3df(rand()%randLength - (randLength/2),0,rand()%randLength - (randLength/2))); obstacles.push_back(e); } //Nodes for vehicles ISceneNode * cube = smgr->addCubeSceneNode(4); ISceneNode * cube2 = smgr->addCubeSceneNode(4); cube->setMaterialFlag(EMF_LIGHTING,false); cube->setMaterialTexture(0,driver->getTexture("../media/v1-solid.png")); cube2->setMaterialFlag(EMF_LIGHTING,false); cube2->setMaterialTexture(0,driver->getTexture("../media/v2-solid.png")); //Creating the actual vehicles IrrlichtMobileEntity * Entity1 = new IrrlichtMobileEntity(cube ,vector3df(0,0,0), 1, 90, 40); IrrlichtMobileEntity * Entity2 = new IrrlichtMobileEntity(cube2,vector3df(0,0,300), 1, 100, 50); //Creating the steering conrollers, constructor also sets steering on entity SimpleSteeringController* Entity1Steering = new SimpleSteeringController(Entity1); SimpleSteeringController * Entity2Steering = new SimpleSteeringController(Entity2); //Setting up other params for behaviors Entity1Steering->SetObstacles(obstacles); Entity1Steering->SetHideTarget(Entity2); Entity1Steering->SetBehaviorFlag(EBF_HIDE,true); Entity1Steering->SetBehaviorFlag(EBF_AVOID,true); Entity2Steering->SetObstacles(obstacles); Entity2Steering->SetPursuitTarget(Entity1); Entity2Steering->SetBehaviorFlag(EBF_PURSUIT,true); Entity2Steering->SetBehaviorFlag(EBF_AVOID,true); //vars for tracking time between frames. This allows framerate independent motion state updates. u32 then = device->getTimer()->getTime(); float timeUpdate = 0; while(device->run()) { const u32 now = device->getTimer()->getTime(); const float frameDeltaTime = (float)(now - then) / 1000.f; // Time in seconds then = now; timeUpdate += frameDeltaTime; if(timeUpdate > 1) { core::stringw str = L"desteer v0.0.1 FPS: "; str += (s32)driver->getFPS(); device->setWindowCaption(str.c_str()); timeUpdate = 0; } //Do behavior updates before the rendering. Entity1->Update(frameDeltaTime); Entity2->Update(frameDeltaTime); driver->beginScene(true, true, SColor(255,100,101,140)); smgr->drawAll(); driver->endScene(); } //Clean up irrlicht. device->drop(); return 0; }
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; }
int main() { MyEventReceiver receiver; IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1280, 800), 16, false, false, false, &receiver); if (!device) return 1; IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); scene::ISceneNode* o = smgr->addSphereSceneNode(20); //o->setMaterialFlag(video::EMF_LIGHTING, false); o->setPosition(core::vector3df(0,0,0)); SMaterial &m = o->getMaterial(0); m.EmissiveColor = SColor(255, 255, 0, 0); vector3df sssPos(0, 60, 0); scene::ISceneNode* sss = smgr->addCubeSceneNode(30); sss->setMaterialFlag(video::EMF_LIGHTING, true); //sss->setMaterialTexture(0, driver->getTexture("wall.bmp")); sss->setPosition(sssPos); SMaterial &sssm = sss->getMaterial(0); sssm.EmissiveColor = SColor(100, 255, 255, 255); scene::ISceneNode* hp = smgr->addSphereSceneNode(10); SMaterial &hpm = hp->getMaterial(0); hpm.EmissiveColor = SColor(255, 0, 0, 255); scene::ISceneNode* hd = smgr->addSphereSceneNode(10); SMaterial &hdm = hd->getMaterial(0); hdm.EmissiveColor = SColor(255, 0, 0, 100); scene::ISceneNode* node[10]; for (int i = 0; i < 10; ++i) { node[i] = smgr->addSphereSceneNode(5); //node[i]->setMaterialFlag(video::EMF_LIGHTING, false); node[i]->setVisible(false); SMaterial &m = node[i]->getMaterial(0); m.EmissiveColor = SColor(255, 255, 0, 0); } scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(); vector3df camPos(0,0,200); vector3df camshift(0,0,0); cam->setPosition(camPos); cam->setTarget(core::vector3df(0,0,0)); u32 then = device->getTimer()->getTime(); const f32 MOVEMENT_SPEED = 50.f; irr::video::S3DVertex m_cPlaneVertices[4]; irr::u16 m_iPlaneIndices[6]; m_cPlaneVertices[0] = irr::video::S3DVertex(-100.0f, -100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 0.0f, 0.0f); m_cPlaneVertices[1] = irr::video::S3DVertex(-100.0f, 100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 0.0f, 1.0f); m_cPlaneVertices[2] = irr::video::S3DVertex( 100.0f, 100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 1.0f, 1.0f); m_cPlaneVertices[3] = irr::video::S3DVertex( 100.0f, -100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 1.0f, 0.0f); m_iPlaneIndices[0] = 0; m_iPlaneIndices[1] = 2; m_iPlaneIndices[2] = 1; m_iPlaneIndices[3] = 0; m_iPlaneIndices[4] = 3; m_iPlaneIndices[5] = 2; SMaterial m_cRenderMaterial; m_cRenderMaterial.Wireframe = false; m_cRenderMaterial.Lighting = false; m_cRenderMaterial.TextureLayer[0].TextureWrapU = irr::video::ETC_CLAMP; m_cRenderMaterial.TextureLayer[0].TextureWrapV = irr::video::ETC_CLAMP; ITexture *m_pRenderTexture = 0; CvCapture *capture; IplImage *frame; char AviFileName[]="Accel World.mp4"; capture = cvCaptureFromAVI(AviFileName); if (driver->queryFeature(irr::video::EVDF_RENDER_TO_TARGET)) { m_pRenderTexture = driver->addRenderTargetTexture(irr::core::dimension2d<irr::u32>((irr::u32)(720), (irr::u32)(480))); m_cRenderMaterial.setTexture(0, m_pRenderTexture); } // m_pRenderTexture = driver->getTexture("wall.bmp"); // m_cRenderMaterial.setTexture(0, m_pRenderTexture); while(device->run()) { const u32 now = device->getTimer()->getTime(); const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds then = now; if(receiver.IsKeyDown(irr::KEY_KEY_W)) camshift.Z -= MOVEMENT_SPEED * frameDeltaTime; else if(receiver.IsKeyDown(irr::KEY_KEY_S)) camshift.Z += MOVEMENT_SPEED * frameDeltaTime; if(receiver.IsKeyDown(irr::KEY_KEY_A)) camshift.X -= MOVEMENT_SPEED * frameDeltaTime; else if(receiver.IsKeyDown(irr::KEY_KEY_D)) camshift.X += MOVEMENT_SPEED * frameDeltaTime; if(receiver.IsKeyDown(irr::KEY_KEY_X)) camshift.Y -= MOVEMENT_SPEED * frameDeltaTime; else if(receiver.IsKeyDown(irr::KEY_SPACE)) camshift.Y += MOVEMENT_SPEED * frameDeltaTime; cam->setPosition(camPos + camshift); driver->beginScene(true, true, SColor(255,0,0,0)); driver->setRenderTarget(m_pRenderTexture, true, true, irr::video::SColor(0,0,0,0)); if(cvGrabFrame(capture)) { frame=cvRetrieveFrame(capture); void* pBits = m_pRenderTexture->lock(); u32 Pitch = m_pRenderTexture->getPitch(); int wmin= Pitch; // for(int h=0; h< 100; h++) // memcpy((char*)pBits+((h)*wmin),(char*)frame->imageDataOrigin + h * wmin, wmin); char* tmp = new char[frame->imageSize + 720 * 480]; for (int i = 0; i < 480; ++i) { for (int j = 0; j < 720; ++j) { tmp[(i * 720 + j) * 4] = frame->imageDataOrigin[(i * 720 + j) * 3]; tmp[(i * 720 + j) * 4 + 1] = frame->imageDataOrigin[(i * 720 + j) * 3 + 1]; tmp[(i * 720 + j) * 4 + 2] = frame->imageDataOrigin[(i * 720 + j) * 3 + 2]; tmp[(i * 720 + j) * 4 + 3] = 255; } } memcpy(pBits,tmp, frame->imageSize + 720 * 480); delete []tmp; m_pRenderTexture->unlock(); } driver->setRenderTarget(0, false, false, irr::video::SColor(0,100,100,100)); //driver->setTransform(video::ETS_VIEW, core::matrix4()); driver->setTransform(video::ETS_WORLD, core::matrix4()); //driver->setTransform(video::ETS_PROJECTION, core::matrix4()); driver->setMaterial(m_cRenderMaterial); driver->drawIndexedTriangleList(m_cPlaneVertices, 4, m_iPlaneIndices, 2); smgr->drawAll(); driver->endScene(); } //controller.removeListener(listener); device->drop(); return 0; }
int main() { /* shadowDimen = dimension2du(1024,1024); shadowDimen = dimension2du(2048,2048); shadowDimen = dimension2du(4096,4096); shadowDimen = dimension2du(2048,2048); filterType = EFT_NONE; filterType = EFT_4PCF; filterType = EFT_8PCF; filterType = EFT_4PCF; */ dimension2du shadowDimen = dimension2du(1024,1024); E_FILTER_TYPE filterType = EFT_4PCF; filterType = EFT_NONE; //// IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2du(800,600),32); ISceneManager* smgr = device->getSceneManager(); IVideoDriver* driver = device->getVideoDriver(); ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0,100,.5); cam->setPosition(vector3df(0,10,0)); // Create the effect handler, passing the device and RTT size (as a dimension2d) . effectHandler* effect = new effectHandler(device,shadowDimen); ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/terrain.bmp",0,-1,vector3df(0,0,0),vector3df(0,0,0),vector3df(1,1,1),SColor(255,255,255,255),1,ETPS_33); terrain->setMaterialTexture(0,driver->getTexture("media/terrain.jpg")); terrain->setMaterialTexture(1, driver->getTexture("media/detailmap.jpg")); terrain->scaleTexture(1,10); terrain->setScale(core::vector3df(4, 0.01f, 4)); terrain->setPosition(vector3df(-120,-1.5f,-120)); terrain->setMaterialType(EMT_DETAIL_MAP); // Make the terrain recieve a shadow with the specified filter type. // (NOTE: 12PCF is only available in Direct3D9, all others work with OpenGL) effect->addShadowToNode(terrain,filterType); IAnimatedMeshSceneNode* sydney; IAnimatedMesh* sydneymesh = smgr->getMesh("media/dwarf.x"); for(int g = 0;g < 1;g++) { for(int v = 0;v < 3;v++) { sydney = smgr->addAnimatedMeshSceneNode(sydneymesh); sydney->setScale(vector3df(0.05f,0.05f,0.05f)); sydney->setPosition(vector3df(g * 4,0.5f,v * 4)); sydney->setMaterialFlag(EMF_NORMALIZE_NORMALS,true); sydney->setAutomaticCulling(EAC_FRUSTUM_BOX); sydney->setMaterialType(EMT_SOLID); // Add the nodes to the depth pass so that they cast a shadow. effect->addNodeToDepthPass(sydney); } } effect->getLightCamera()->addAnimator(smgr->createFlyCircleAnimator(sydney->getPosition() + vector3df(0,15,0),25,0.0002f)); effect->getLightCamera()->setNearValue(5); effect->setMaxShadowDistanceFromLight(120); smgr->addLightSceneNode(effect->getLightCamera()); MyEventReceiver receiver(cam); device->setEventReceiver(&receiver); // Parent a sphere to the light camera so we can see its position. smgr->addSphereSceneNode(1,8,effect->getLightCamera())->setMaterialFlag(EMF_LIGHTING,false); while(device->run()) { wchar_t tmp[255]; swprintf(tmp,255,L"Shadow Map Demo (FPS: %d)",driver->getFPS()); device->setWindowCaption(tmp); driver->beginScene(true,true,SColor(0,0,0,0)); // Point the light camera at one of the nodes as it rotates around them. effect->setLightTarget(sydney->getPosition()); // Update the effect handler, remember to always do this BEFORE smgr->drawAll and AFTER beginscene! effect->update(); smgr->drawAll(); // If user wishes we can display the shadow map to the screen. (May not work in OpenGL) if(disp2d) driver->draw2DImage(effect->getShadowMapTexture(),position2d<s32>(0,0)); driver->endScene(); // device->sleep(5); } device->drop(); return 0; }