/** * @brief * Restarts the game */ void Application67::Restart() { // Get the scene container SceneContainer *pSceneContainer = GetScene(); if (pSceneContainer) { // Clean up your scene container pSceneContainer->Clear(); // Create the camera (we need the camera to control the post processing) SceneNode *pCamera = pSceneContainer->Create("PLScene::SNCamera", "FixedCamera"); if (pCamera && pCamera->IsInstanceOf("PLScene::SNCamera")) { // Add a post process scene node modifier from the 'PLPostProcessEffects'-plugin pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessOldFilm", "Flags='Inactive'"); // Make this to our main scene camera SetCamera(reinterpret_cast<SNCamera*>(pCamera)); } // Create an UFO from mars attacking the earth :D pSceneContainer->Create("SNUFO", "Ufo"); // Create the gun (the player) pSceneContainer->Create("SNGun", "Gun", "Position=\"157 155\""); } }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application60::OnCreateScene(SceneContainer &cContainer) { // Create a camera scene node SceneNode *pCameraSceneNode = cContainer.Create("PLScene::SNCamera", "FreeCamera", "Position=\"1 2 -3\" Rotation=\"25 210 0\""); if (pCameraSceneNode && pCameraSceneNode->IsInstanceOf("PLScene::SNCamera")) { // Make this to our main scene camera SetCamera(reinterpret_cast<SNCamera*>(pCameraSceneNode)); } // Create a scene node with the soldier mesh which can produce a shadow SceneNode *pSoldierSceneNode = cContainer.Create("PLScene::SNMesh", "Soldier", "Flags=\"CastShadow|ReceiveShadow\" Position=\"0.0 0.1 -5.0\" Scale=\"0.008 0.008 0.008\" Mesh=\"Data/Meshes/Soldier.mesh\""); if (pSoldierSceneNode) { // Add a scene node modifier which will constantly rotate the soldier pSoldierSceneNode->AddModifier("PLScene::SNMRotationLinearAnimation", "Velocity=\"0 10 0\""); // Add a scene node modifier which will playback the animation named "walk_0" letting the soldier walk pSoldierSceneNode->AddModifier("PLScene::SNMMeshAnimation", "Name=\"walk_0\""); // Add a scene node modifier which will animate the morph target named "blink" letting the soldier blink from time to time pSoldierSceneNode->AddModifier("PLScene::SNMMeshMorphBlink", "Name=\"blink\""); } // Create a light source scene node to illuminate the scene - this light can cast shadows cContainer.Create("PLScene::SNPointLight", "Light", "Flags=\"CastShadow|Flares|Corona\" Range=\"4\""); // Create the floor scene node cContainer.Create("PLScene::SNMesh", "Floor", "Flags=\"CastShadow|ReceiveShadow\" Position=\"0.0 0.0 -5.0\" Rotation=\"0.0 180.0 0.0\" Scale=\"4.0 0.1 4.0\" Mesh=\"Default\""); // Set scene container SetScene(&cContainer); }
//[-------------------------------------------------------] //[ Protected virtual PLScene::SceneApplication functions ] //[-------------------------------------------------------] void EngineApplication::OnCreateRootScene() { // Get the scene context SceneContext *pSceneContext = GetSceneContext(); if (pSceneContext) { // First, create the scene root container which holds the scene container with our 'concrete' scene within it SceneContainer *pRootContainer = pSceneContext->GetRoot() ? static_cast<SceneContainer*>(pSceneContext->GetRoot()->Create("PLScene::SceneContainer", "RootScene")) : nullptr; if (pRootContainer) { // Protect this important container! pRootContainer->SetProtected(true); // Create a scene container with our 'concrete scene' SceneNode *pSceneContainerNode = pRootContainer->Create("PLScene::SceneContainer", "Scene"); if (pSceneContainerNode && pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pSceneContainer = static_cast<SceneContainer*>(pSceneContainerNode); // Protect this important container! pSceneContainer->SetProtected(true); // Connect event handler if (pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) static_cast<SceneContainer*>(pSceneContainerNode)->SignalLoadProgress.Connect(EventHandlerLoadProgress); // Create the 'concrete scene' OnCreateScene(*pSceneContainer); } // Create scene node for engine information SceneNode *pSceneNode = pRootContainer->Create("PLEngine::SNEngineInformation"); if (pSceneNode) pSceneNode->SetActive(m_bEditModeEnabled); // Create console scene node - using the console command 'timescale <value>' we // can change the scene time (slowdown or accelerate) pSceneNode = pRootContainer->Create("PLEngine::SNConsole"); if (pSceneNode && pSceneNode->GetClass()->IsDerivedFrom("PLEngine::SNConsoleBase")) { SNConsoleBase *pConsole = static_cast<SNConsoleBase*>(pSceneNode); // Register default commands pConsole->RegisterCommand(0, "quit", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); pConsole->RegisterCommand(0, "exit", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); pConsole->RegisterCommand(0, "bye", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); pConsole->RegisterCommand(0, "logout", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); // Set active state pConsole->SetActive(m_bEditModeEnabled); } } // Set the root scene SetRootScene(pRootContainer); } }
//[-------------------------------------------------------] //[ Protected virtual PLFrontendQt::QPLSceneContext functions ] //[-------------------------------------------------------] void MySceneContext::OnCreateScene(SceneContainer &cContainer) { // Create a camera SceneNode *pCamera = cContainer.Create("PLScene::SNCamera", "FreeCamera", "Position=\"1 2 -3\" Rotation=\"25 0 0\""); if (pCamera && pCamera->IsInstanceOf("PLScene::SNCamera")) SetCamera(reinterpret_cast<SNCamera*>(pCamera)); // Create the floor cContainer.Create("PLScene::SNMesh", "Floor", "Position=\"0.0 0.0 5.0\" Rotation=\"0.0 180.0 0.0\" Scale=\"4.0 0.1 4.0\" Mesh=\"Default\""); // Set scene container SetScene(&cContainer); }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application65::OnCreateScene(SceneContainer &cContainer) { // Create a scene node with the soldier mesh cContainer.Create("PLScene::SNMesh", "Soldier", "Position=\"0.0 -0.7 -4.0\" Scale=\"0.008 0.008 0.008\" Mesh=\"Data/Meshes/Soldier.mesh\""); // Create a nice particle effect behind the soldier cContainer.Create("PLParticleGroups::PGMagic2", "Magic2", "Position=\"0.0 0.0 -25.0\""); // Create a moving light source to illuminate the scene cContainer.Create("PLScene::SNPointLight", "Light", "Position=\"1.0 2.0 -2.0\" Flags=\"Flares|Corona|Blend\" Range=\"15.0\""); // Create a camera - this time we increase the camera FOV to get a better space feeling :) SceneNode *pCamera = cContainer.Create("PLScene::SNCamera", "FixedCamera", "Position=\"0.0 0.0 -2.5\" Rotation=\"0.0 180.0 0.0\" FOV=\"60\""); if (pCamera && pCamera->IsInstanceOf("PLScene::SNCamera")) { // Make this to our main scene camera SetCamera(reinterpret_cast<SNCamera*>(pCamera)); // Get class list of all available post process scene node modifiers m_lstModifierClasses.Clear(); ClassManager::GetInstance()->GetClasses(m_lstModifierClasses, "PLCompositing::SNMPostProcess", Recursive, NoBase, NoAbstract); // 'Activate' the first effect if (m_lstModifierClasses.GetNumOfElements()) pCamera->AddModifier(m_lstModifierClasses[m_nCurrentSelectedModifier]->GetClassName()); } // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(&cContainer); } // Within the parent container... SceneContainer *pContainer = cContainer.GetContainer(); if (pContainer) { // Add our information text scene nodes SceneNode *pInfoText = pContainer->Create("PLScene::SceneContainer", "InfoText", "Flags=\"NoCulling\""); if (pInfoText && pInfoText->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pInfoTextContainer = static_cast<SceneContainer*>(pInfoText); pInfoTextContainer->Create("PLScene::SNText2D", '0', "Position=\"0.01 0.01\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("'F1' = Show/hide this help text") + '\"'); pInfoTextContainer->Create("PLScene::SNText2D", '1', "Position=\"0.01 0.03\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("'Space' = Enable/disable post processing") + '\"'); pInfoTextContainer->Create("PLScene::SNText2D", '2', "Position=\"0.01 0.05\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("'1-7' = Custom post process effects") + '\"'); pInfoTextContainer->Create("PLScene::SNText2D", '3', "Position=\"0.01 0.07\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("'Page up' = Next post process effect") + '\"'); pInfoTextContainer->Create("PLScene::SNText2D", '4', "Position=\"0.01 0.09\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("'Page down' = Previous post process effect") + '\"'); } } // Set scene container SetScene(&cContainer); }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application64::OnCreateScene(SceneContainer &cContainer) { // Create a camera SceneNode *pCamera = cContainer.Create("PLScene::SNCamera", "FreeCamera", "Position=\"1 2 -3\" Rotation=\"25 210 0\""); if (pCamera && pCamera->IsInstanceOf("PLScene::SNCamera")) { // Make this to our main scene camera SetCamera(reinterpret_cast<SNCamera*>(pCamera)); } // Create a scene node with the soldier mesh - in debug mode, show some fancy technical visualizations SceneNode *pSceneNode = cContainer.Create("PLScene::SNMesh", "Soldier", "Position=\"0.0 0.1 -5.0\" Scale=\"0.008 0.008 0.008\" Mesh=\"Data/Meshes/Soldier.mesh\" DebugFlags=\"DebugShowWireframe|DebugShowJoints|DebugShowJointNames|DebugShowSkeleton\""); if (pSceneNode) { // Rotate the soldier pSceneNode->AddModifier("PLScene::SNMRotationLinearAnimation", "Velocity=\"0 10 0\""); // Playback the animation named "walk_0" letting the soldier walk pSceneNode->AddModifier("PLScene::SNMMeshAnimation", "Name=\"walk_0\""); // Animate the morph target named "blink" letting the soldier blink from time to time pSceneNode->AddModifier("PLScene::SNMMeshMorphBlink", "Name=\"blink\""); } // Create the floor cContainer.Create("PLScene::SNMesh", "Floor", "Position=\"0.0 0.0 -5.0\" Rotation=\"0.0 180.0 0.0\" Scale=\"4.0 0.1 4.0\" Mesh=\"Default\""); // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(&cContainer); } // Set scene container SetScene(&cContainer); // Create the picking component m_pMyPicking = new MyPicking(*this); }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application67::OnCreateScene(SceneContainer &cContainer) { // Create a scene container with our 'concrete sound scene' using the default sound API SceneNode *pSceneContainerNode = cContainer.Create("PLSound::SCSound", "SoundScene"); if (pSceneContainerNode && pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pSceneContainer = static_cast<SceneContainer*>(pSceneContainerNode); // Protect this important container! pSceneContainer->SetProtected(true); // Populate the scene container // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(pSceneContainer); // Get the scene context SceneContext *pSceneContext = GetSceneContext(); if (pSceneContext) { // Create us a scene renderer SceneRenderer *pSceneRenderer = pSceneContext->GetSceneRendererManager().Create("2DGame"); if (pSceneRenderer) { // Add begin scene renderer pass pSceneRenderer->Create("PLCompositing::SRPBegin", "Begin", "TextureFormat=\"R8G8B8A8\" Flags=\"Inactive\""); // Add our own scene renderer pass pSceneRenderer->Create("SRP2DGame", "2DGame"); // Add post processing scene renderer pass pSceneRenderer->Create("PLCompositing::SRPPostProcessing", "PostProcessing"); // Add end scene renderer pass pSceneRenderer->Create("PLCompositing::SRPEnd", "End"); // Make this scene renderer to the default scene renderer of our scene surface painter pSPScene->SetDefaultSceneRenderer(pSceneRenderer->GetName()); } } } // Set scene container SetScene(pSceneContainer); // Start the game Restart(); } }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application66::OnCreateScene(SceneContainer &cContainer) { // Set scene container flags cContainer.SetFlags(SceneNode::NoCulling); // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(&cContainer); } // Within the parent container... SceneContainer *pContainer = cContainer.GetContainer(); if (pContainer) { // Create a 'ingame'-GUI scene node const SNGui *pGuiSceneNode = static_cast<SNGui*>(pContainer->Create("PLFrontendPLGui::SNGui", "GUI")); if (pGuiSceneNode) { // Setup the GUI Gui *pGui = pGuiSceneNode->GetGui(); if (pGui) { // Create the GUI font if (!GuiFont) { GuiFont = new Font(*pGui); GuiFont->LoadFromFile("Data/Fonts/LinLibertine_Re-2.7.9.9.otf", 18); } // Set GUI options pGui->SetMouseVisible(false); // Create ingame GUI container m_pIngameGui = new IngameGui(*this, pGui->GetRootWidget()); m_pIngameGui->SetSize(Vector2i(1024, 768)); m_pIngameGui->SetBackgroundColor(PLGraphics::Color4::Transparent); m_pIngameGui->SetFocus(); m_pIngameGui->SetVisible(true); } } } // Set scene container SetScene(&cContainer); }
/** * @brief * Function that is called to create the application's root scene */ void SceneApplication::OnCreateRootScene() { // [TODO] Load 'm_sSceneFilename' if provided // Is there a scene context? if (m_pSceneContext) { // First, create the scene root container which holds the scene container with our 'concrete' scene within it SceneContainer *pRootContainer = m_pSceneContext->GetRoot() ? static_cast<SceneContainer*>(m_pSceneContext->GetRoot()->Create("PLScene::SceneContainer", "RootScene")) : nullptr; if (pRootContainer) { // Protect this important container! pRootContainer->SetProtected(true); // Create a scene container with our 'concrete scene' SceneNode *pSceneContainerNode = pRootContainer->Create("PLScene::SceneContainer", "Scene"); if (pSceneContainerNode && pSceneContainerNode->IsContainer()) { // Protect this important container! pSceneContainerNode->SetProtected(true); } } // Set the root scene SetRootScene(pRootContainer); } }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application70::OnCreateScene(SceneContainer &cContainer) { // Create a camera SceneNode *pCamera = cContainer.Create("PLScene::SNCamera", "FreeCamera", "Position=\"1 2 -3\" Rotation=\"25 210 0\""); if (pCamera && pCamera->IsInstanceOf("PLScene::SNCamera")) { // Make this to our main scene camera SetCamera(reinterpret_cast<SNCamera*>(pCamera)); // Add a controller modifier so we can look around the camera by using a default control pCamera->AddModifier("PLEngine::SNMEgoLookController"); // Add a controller modifier so we can move around the camera by using a default control pCamera->AddModifier("PLEngine::SNMMoveController"); } // Create the floor cContainer.Create("PLScene::SNMesh", "Floor", "Position=\"0 0 -5\" Scale=\"4 0.1 4\" Mesh=\"Default\""); // Create an instance of the fire particle effect scene node cContainer.Create("SNFireSample", "Fire", "Position=\"0.5 0.3 -5\" Scale=\"0.1 0.1 0.1\""); // Create an instance of the basic particle effect scene node cContainer.Create("SNBasicSample", "Basic", "Position=\"-0.5 0.1 -8\" Scale=\"0.5 0.5 0.5\""); // Create an instance of the gravitation particle effect scene node cContainer.Create("SNGravitationSample", "Gravitation", "Position=\"-1 1 -5\" Scale=\"0.5 0.5 0.5\""); // Create an instance of the galaxy particle effect scene node cContainer.Create("SNGalaxySample", "Galaxy", "Position=\"-3 0.5 -8\" Scale=\"0.5 0.5 0.5\""); // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(&cContainer); } // Set scene container SetScene(&cContainer); }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application61::OnCreateScene(SceneContainer &cContainer) { // Set no scene container as default SetScene(nullptr); // Sound API given? if (m_sSoundAPI.GetLength()) { // Create a scene container with our 'concrete sound scene' using the chosen sound API SceneNode *pSceneContainerNode = cContainer.Create("PLSound::SCSound", "SoundScene", "SoundAPI=\"" + m_sSoundAPI + "\" Pitch=\"" + Timing::GetInstance()->GetTimeScaleFactor() + '\"'); if (pSceneContainerNode && pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pSceneContainer = static_cast<SceneContainer*>(pSceneContainerNode); // Protect this important container! pSceneContainer->SetProtected(true); // Set scene container SetScene(pSceneContainer); // Populate the scene container // Create a camera SceneNode *pCamera = pSceneContainer->Create("PLScene::SNCamera", "FreeCamera", "Position=\"0.0 -1.5 1.4\" Rotation=\"-14.0 180.0 0.0\""); if (pCamera && pCamera->IsInstanceOf("PLScene::SNCamera")) { // Make this to our main scene camera SetCamera(reinterpret_cast<SNCamera*>(pCamera)); // Add a controller modifier so we can look around the camera by using a default control pCamera->AddModifier("PLEngine::SNMEgoLookController"); // Add a controller modifier so we can move around the camera by using a default control pCamera->AddModifier("PLEngine::SNMMoveController", "Speed=\"2\""); // Make this camera to the 'sound listener' pSceneContainer->SetAttribute("Listener", pCamera->GetName()); } // Create the floor pSceneContainer->Create("PLScene::SNMesh", "Floor", "Position=\"0.0 -2.1 -5.0\" Rotation=\"0.0 180.0 0.0\" Scale=\"4.0 0.1 4.0\" Mesh=\"Default\""); // Create a box on the floor pSceneContainer->Create("PLScene::SNMesh", "Box", "Position=\"0.0 -1.5 -5.0\" Scale=\"0.5 0.5 0.5\" Mesh=\"Default\""); // Create rain particles and rain sound pSceneContainer->Create("PLParticleGroups::PGRain", "Rain", "Position=\"0.0 15.0 -5.0\" Flags=\"ForceUpdate\" MediumSize=\"3\""); pSceneContainer->Create("PLSound::SNSound", "RainSound", "Sound=\"Data/Sounds/Rain.ogg\" Volume=\"0.2\""); // Create the soldier walking in the rain :) SceneNode *pSoldier = pSceneContainer->Create("PLScene::SNMesh", "Soldier", "Position=\"0.0 -1.5 -5.0\" Scale=\"0.007 0.007 0.007\" Mesh=\"Data/Meshes/Soldier.mesh\""); if (pSoldier) { // Add animation modifier pSoldier->AddModifier("PLScene::SNMMeshAnimation", "Name=\"walk_0\" Speed=\"2\""); // Let the soldier walk on a path... pSoldier->AddModifier("PLScene::SNMPositionPath", "Filename=\"Data/Misc/61Sound_Soldier.path\" Speed=\"0.5\" Flags=\"NodeIndexProgress\" Interpolation=\"CatmullRomCurve\""); // ... and we should look into the direction he's moving pSoldier->AddModifier("PLScene::SNMRotationMoveDirection"); // Link a footsteps sound to the soldier pSoldier->AddModifier("PLSound::SNMSound","Sound=\"Data/Sounds/Walking.ogg\""); } // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(pSceneContainer); } // Within the parent container... SceneContainer *pContainer = pSceneContainer->GetContainer(); if (pContainer) { // Get/add our information text scene nodes SceneNode *pInfoText = pContainer->Create("PLScene::SceneContainer", "InfoText", "Flags=\"NoCulling\""); if (pInfoText && pInfoText->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pInfoTextContainer = static_cast<SceneContainer*>(pInfoText); // The name of the used sound API pInfoTextContainer->Create("PLScene::SNText2D", "SoundAPI", "Position=\"0.01 0.01\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("Sound API: ") + GetSoundAPI() + '\"'); // Draw keys information pInfoTextContainer->Create("PLScene::SNText2D", "Keys", "Position=\"0.01 0.04\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("Keys:") + '\"'); pInfoTextContainer->Create("PLScene::SNText2D", "TimeScale", "Position=\"0.06 0.08\" Flags=\"No3DPosition|NoCenter\""); UpdateTimeScaleTextNode(); } } } } }