int main() { IrrlichtDevice *device = createDevice( video::EDT_BURNINGSVIDEO, dimension2d<u32>(640, 480), 16, false, false, false, 0); if (!device) return 1; IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); // Add Light to the Scene ILightSceneNode *light = smgr->addLightSceneNode( 0, vector3df() ); light->getLightData().AmbientColor = SColorf( 0.2f, 0.2f, 0.2f ); light->getLightData().SpecularColor = SColorf( 1.0f, 1.0f, 1.0f ); light->getLightData().DiffuseColor = SColorf( 0.8f, 0.8f, 0.8f ); light->setLightType( ELT_DIRECTIONAL ); light->setRotation( vector3df( 45.0f, 45.0f, 0.0f )); smgr->setAmbientLight( SColorf( 0.2f, 0.2f, 0.2f )); // scene::IMeshSceneNode* node = smgr->addCubeSceneNode(20); // if (node){ // node->setMaterialFlag(EMF_LIGHTING, false); // smgr->getMeshManipulator()->setVertexColors(node->getMesh(),SColor(250,250,0,0)); // node->setPosition(core::vector3df(0,0,0) ); // node->setVisible(false); // } smgr->addCameraSceneNode(0, vector3df(0,0,-50), vector3df(0,0,0)); while(device->run()) { core::aabbox3df box; box.MinEdge.set(vector3df(-100,-100,-100)); box.MaxEdge.set(vector3df(100,100,100)); driver->beginScene(true, true, SColor(250, 100, 150, 150)); smgr->drawAll(); guienv->drawAll(); criaGizmosBicos(driver); // criaRegiaAnalise(box, driver); driver->endScene(); } device->drop(); return 0; }
void PhysicsSim::makeLight(vector3df position, float intensity) { ILightSceneNode* lsn = smgr->addLightSceneNode(0, position, video::SColorf(1.f, 1.f, 1.f), 1); // smgr->setAmbientLight(SColorf(0.2, 0.2, 0.2)); SLight sl = lsn->getLightData(); sl.Attenuation = Vector3D(0, 0.001, 0); sl.DiffuseColor = SColorf(1, 1, 1); sl.Direction = Vector3D(0, -1, 0); sl.AmbientColor = SColorf(0.4, 0.4, 0.4); lsn->setLightData(sl); }
void IrrQWidget::buildIrrlichtScene(){ if(idevice != 0){ collMan = iscene->getSceneCollisionManager(); geo = iscene->getGeometryCreator(); ILightSceneNode *light = iscene->addLightSceneNode(); light->setLightType( ELT_DIRECTIONAL ); light->setRotation( vector3df( 45.0f, 45.0f, 0.0f )); light->getLightData().AmbientColor = SColorf( 0.2f, 0.2f, 0.2f, 1.0f ); light->getLightData().DiffuseColor = SColorf( 0.8f, 0.8f, 0.8f, 1.0f ); camera = iscene->addCameraSceneNodeFPS(); camera->setPosition(vector3df(0,0,-90)); camera->setTarget(vector3df(0,0,0)); } }
int main(int argc, char* argv[]) { // ask user for driver video::E_DRIVER_TYPE driverType=driverChoiceConsole(); if (driverType==video::EDT_COUNT) return 1; MyEventReceiver receiver; IrrlichtDevice* device = createDevice(driverType, core::dimension2du(800, 600), 32, false, false, false, &receiver); if(device == 0) return 1; IVideoDriver *driver = device->getVideoDriver(); ISceneManager *smgr = device->getSceneManager(); device->setWindowCaption(L"Irrlicht Example for SMesh usage."); /* Create the custom mesh and initialize with a heightmap */ TMesh mesh; HeightMap hm = HeightMap(255, 255); hm.generate(eggbox); mesh.init(hm, 50.f, grey, driver); // Add the mesh to the scene graph IMeshSceneNode* meshnode = smgr -> addMeshSceneNode(mesh.Mesh); meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); // light is just for nice effects ILightSceneNode *node = smgr->addLightSceneNode(0, vector3df(0,100,0), SColorf(1.0f, 0.6f, 0.7f, 1.0f), 500.0f); if (node) { node->getLightData().Attenuation.set(0.f, 1.f/500.f, 0.f); ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(vector3df(0,150,0),250.0f); if (anim) { node->addAnimator(anim); anim->drop(); } } ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(); if (camera) { camera->setPosition(vector3df(-20.f, 150.f, -20.f)); camera->setTarget(vector3df(200.f, -80.f, 150.f)); camera->setFarValue(20000.0f); } /* Just a usual render loop with event handling. The custom mesh is a usual part of the scene graph which gets rendered by drawAll. */ while(device->run()) { if(!device->isWindowActive()) { device->sleep(100); continue; } if(receiver.IsKeyDown(irr::KEY_KEY_W)) { meshnode->setMaterialFlag(video::EMF_WIREFRAME, !meshnode->getMaterial(0).Wireframe); } else if(receiver.IsKeyDown(irr::KEY_KEY_1)) { hm.generate(eggbox); mesh.init(hm, 50.f, grey, driver); } else if(receiver.IsKeyDown(irr::KEY_KEY_2)) { hm.generate(moresine); mesh.init(hm, 50.f, yellow, driver); } else if(receiver.IsKeyDown(irr::KEY_KEY_3)) { hm.generate(justexp); mesh.init(hm, 50.f, yellow, driver); } driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0xff000000)); smgr->drawAll(); driver->endScene(); } device->drop(); return 0; }
SceneWorld::SceneWorld(PseuGUI *g) : Scene(g) { DEBUG(logdebug("SceneWorld: Initializing...")); debugmode = false; _freeCameraMove = true; // store some pointers right now to prevent repeated ptr dereferencing later (speeds up code) gui = g; wsession = gui->GetInstance()->GetWSession(); world = wsession->GetWorld(); mapmgr = world->GetMapMgr(); movemgr = world->GetMoveMgr(); mychar = wsession->GetMyChar(); ASSERT(mychar); _CalcXYMoveVect(mychar->GetO()); old_char_o = mychar->GetO(); if(soundengine) { soundengine->stopAllSounds(); } ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), SColorf(255, 255, 255, 255), 1000.0f); SLight ldata = light->getLightData(); ldata.AmbientColor = video::SColorf(0.2f,0.2f,0.2f); ldata.DiffuseColor = video::SColorf(1.0f,1.0f,1.0f); ldata.Type = video::ELT_DIRECTIONAL; ldata.Position = core::vector3df(-0.22f,-1,0); light->setLightData(ldata); eventrecv = new MyEventReceiver(); device->setEventReceiver(eventrecv); eventrecv->mouse.wheel = MAX_CAM_DISTANCE; camera = new MCameraFPS(smgr); camera->setNearValue(0.1f); f32 farclip = instance->GetConf()->farclip; if(farclip < 50) farclip = TILESIZE; f32 fov = instance->GetConf()->fov; if(!iszero(fov)) { logdetail("Camera: Field of view (FOV) = %.3f",fov); camera->setFOV(fov); } camera->setFarValue(farclip); debugText = guienv->addStaticText(L"< debug text >",rect<s32>(0,0,driver->getScreenSize().Width,30),true,true,0,-1,true); envBasicColor = video::SColor(0,100,101,190); smgr->setShadowColor(); // set shadow to default color sky = NULL; selectedNode = oldSelectedNode = NULL; //sky = smgr->addSkyDomeSceneNode(driver->getTexture("data/misc/sky.jpg"),64,64,1.0f,2.0f); /* // TODO: for now let irrlicht draw the skybox sky->grab(); // if the camera clip is set too short, the sky will not be rendered properly. sky->remove(); // thus we grab the sky node while removing it from rendering. */ f32 fogfar = instance->GetConf()->fogfar; if(fogfar < 30) fogfar = farclip * 0.7f; f32 fognear = instance->GetConf()->fognear; if(fognear < 10) fognear = fogfar * 0.75f; logdetail("GUI: Using farclip=%.2f fogfar=%.2f fognear=%.2f", farclip, fogfar, fognear); driver->setFog(envBasicColor, true, fognear, fogfar, 0.02f); // setup cursor cursor->setOSCursorVisible(false); cursor->addMouseCursorTexture("data/misc/cursor.png", true); cursor->setVisible(true); InitTerrain(); UpdateTerrain(); RelocateCameraBehindChar(); DEBUG(logdebug("SceneWorld: Init done!")); }
int MultiBouncerGame::run() { if( !m_Engine ) return EXIT_FAILURE; ConfigStorage *input = m_Engine->getConfig()->getSubSection( "Input" ); PulsarEventReceiver *evt = m_Engine->getToolKit<PulsarEventReceiver>(); ScriptToolKit *scriptTK = m_Engine->getToolKit<ScriptToolKit>(); lua_State *lua = scriptTK->getLuaState(); bool useWiimotes = m_Engine->getConfig()->get<bool>( "UseWiimotes", false); EKEY_CODE **codes = 0; wiimote **wiimotes = 0; int connectedWiimotes = 0; int maxPlayers = 0; if( !useWiimotes ) { codes = *loadControls( input, scriptTK ); for( ; maxPlayers < 32; maxPlayers++ ) { if( codes[maxPlayers][0] == KEY_KEY_CODES_COUNT ) break; } } //Callbacks for the goals struct : public ICallback { void onTrigger( Value* entity ) { for( int x = 0; balls[x] != 0; x++ ) { if( entity->getAs<Entity*>()->getID() == balls[x]->getID() ) { points++; balls[x]->reset(); } } } int points; DynamicEntity **balls; } redGoalCallback; struct : public ICallback { void onTrigger( Value* entity ) { for( int x = 0; balls[x] != 0; x++ ) { if( entity->getAs<Entity*>()->getID() == balls[x]->getID() ) { points++; balls[x]->reset(); } } } int points; DynamicEntity **balls; } blueGoalCallback; struct : public ICallback { void onTrigger(Value* val){ static_cast<DynamicEntity*>( val->getAs<Entity*>() )->reset(); } } borderCallback; bool running = true; //Create a callback for the quit key struct : public ICallback { virtual void onTrigger( Value* val ){ *running = false; } bool *running; } exitCallback; exitCallback.running = &running; EKEY_CODE exitKey = scriptTK->getPulsarKeyCode( input->get<String>( "Exit", "ESCAPE" ) ); evt->addKeyPressedCallback( exitKey, &exitCallback ); //Loop until the game is cancelled while( m_Engine->run() && running ) { //Show menu m_MainMenu->setVisible( true ); mScoreWindow->setVisible( false ); //Reset points redGoalCallback.points = 0; blueGoalCallback.points = 0; //Store selected MapName int prevSelection = -1; //Standard loop while( m_Engine->run() && running ) { m_Engine->beginDrawing(); int selection = m_MapList->getSelected(); //Exit loop if everything is selected if( m_OkButton->isPressed() && selection > -1 ) break; //If a new Map gets selected, change the max player limit if( selection > -1 && prevSelection != selection && maxPlayers > 0 ) m_PlayerCounter->setRange( 1.f, std::min( maxPlayers, m_MapData.at( selection )->get<int>( "MaxPlayers" ) ) ); if( mReconnectButton->isPressed() ) { wiimotes = connectWiimotes( connectedWiimotes ); maxPlayers = connectedWiimotes; } prevSelection = selection; m_Engine->endDrawing(); } if( !running ) break; //Hide menu m_MainMenu->setVisible( false ); mScoreWindow->setVisible( true ); //Get the selected file names String selectedMap = m_MapFiles.at( m_MapList->getSelected() ).string().c_str(); //Load the map ConfigStorage map( true ); map.parseXMLFile( selectedMap, "Map" ); map.setAlwaysGetRecursive(); std::vector<ILightSceneNode*> lights; //Add lights, complicated version... //TODO: Light management for( int x = 0; x < map.countVars( "Light" ); x++ ) { ConfigStorage *light = map.getSubSection( "Data" )->getSubSectionN( x, "Light" ); SColor lightColor( 128, light->get<int>( "ColorR", 255 ), light->get<int>( "ColorG", 255 ), light->get<int>( "ColorB", 255 ) ); ILightSceneNode *node = m_Engine->getIrrlichtDevice()->getSceneManager()-> addLightSceneNode( 0, light->get<Vector>( "Position" ), lightColor, light->get<float>( "Radius" ) ); node->getLightData().SpecularColor.set( 0,0,0 ); lights.push_back( node ); } //Add a camera CameraToolKit *cam = m_Engine->getToolKit<CameraToolKit>(); cam->addCamera( ID_CAMERA_PRIMARY ); cam->setCameraPosition( ID_CAMERA_PRIMARY, map.getSubSection( "Data" )->getSubSection( "Camera" )->get<Vector>( "Position" ) ); cam->setCameraTarget( ID_CAMERA_PRIMARY, map.getSubSection( "Data" )->getSubSection( "Camera" )->get<Vector>( "Target" ) ); int numPlayers = (int)m_PlayerCounter->getValue(); IBouncer *players[numPlayers]; Value::createStandardGenerator<SmallFastTestBouncer>(); for( int x = 0; x < numPlayers; x++ ) { players[x] = new SmallFastTestBouncer( x + 1 ); players[x]->setControls( codes[x][0], codes[x][1], codes[x][2], codes[x][3], codes[x][4], codes[x][5], codes[x][6] ); Value *player = new Value( *(SmallFastTestBouncer*)players[x] ); player->setAutoDestroy( true ); map.setValue( "Player", player ); if( x % 2 ) players[x]->spawn( map.getN<Vector>( x / 2, "RedTeamSpawn" ), Vector() ); else players[x]->spawn( map.getN<Vector>( x / 2, "BlueTeamSpawn" ), Vector() ); } for( int x = 0; x < map.countVars( "RedGoal" ); x++ ) { map.getN<GhostSensorEntity>( x, "RedGoal" ). setOnEnterCallback( &redGoalCallback ); } for( int x = 0; x < map.countVars( "BlueGoal" ); x++ ) { map.getN<GhostSensorEntity>( x, "BlueGoal" ). setOnEnterCallback( &blueGoalCallback ); } //Create Balls int numBalls = map.countVars( "Ball" ); DynamicEntity *ballEntity[numBalls + 1]; for( int x = 0; x < numBalls; x++ ) { ballEntity[x] = &map.getN<DynamicEntity>( x, "Ball" ); } ballEntity[numBalls] = 0; redGoalCallback.balls = ballEntity; blueGoalCallback.balls = ballEntity; //Create borders for( int x = 0; x < map.countVars( "Border" ); x++ ) map.getN<GhostSensorEntity>( x, "Border" ).setOnEnterCallback( &borderCallback ); //Start simulation m_Engine->setSimulationState( true ); bool toMenu = false; int sleeptime = 0; //Standard loop again while( m_Engine->run() && !toMenu && running ) { m_Engine->beginDrawing(); if( evt->keyState( KEY_F12 ) ) toMenu = true; if( evt->keyState( KEY_F5 ) ) sleeptime = 0; if( evt->keyState( KEY_F6 ) ) sleeptime = 40000; usleep(sleeptime); String points( redGoalCallback.points ); points += " : "; points += blueGoalCallback.points; points += " FPS: "; points += m_Engine->getIrrlichtDevice()->getVideoDriver()->getFPS(); mScoreCounter->setText( irr::core::stringw( points ).c_str() ); if( useWiimotes ) { wiiuse_poll( wiimotes, 32 ); for( int x = 0; x < numPlayers; x++ ) { if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_B ) ) players[x]->jump(); if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_ONE ) ) players[x]->startAction( 1 ); if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_TWO ) ) players[x]->startAction( 2 ); if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_HOME ) ) toMenu = true; if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_DOWN ) ) players[x]->move( false, false, false, true ); if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_UP ) ) players[x]->move( false, false, true, false ); if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_RIGHT ) ) players[x]->move( true, false, false, false ); if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_LEFT ) ) players[x]->move( false, true, false, false ); } } m_Engine->endDrawing(); } //Stop simulation m_Engine->setSimulationState( false ); for( std::vector<ILightSceneNode*>::iterator x = lights.begin(); x != lights.end(); x++ ) ( *x )->remove(); } for( int x = 0; x < 32; x++ ) delete[] codes[x]; delete[] codes; wiiuse_cleanup( wiimotes, 32 ); return EXIT_SUCCESS; }