//[-------------------------------------------------------] //[ 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); }
/** * @brief * Loads/reloads the sound */ void SNMSound::Load() { // Destroy currently used sound source Source *pSS = static_cast<Source*>(m_pSoundSourceHandler->GetResource()); if (pSS) delete pSS; // Get the PL sound container this scene node is in SceneContainer *pContainer = GetSceneNode().GetContainer(); while (pContainer && !pContainer->IsInstanceOf("PLSound::SCSound")) pContainer = pContainer->GetContainer(); if (pContainer) { SoundManager *pSoundManager = static_cast<SCSound*>(pContainer)->GetSoundManager(); if (pSoundManager) { Source *pSoundSource = pSoundManager->CreateSoundSource(pSoundManager->CreateSoundBuffer(m_sSound, (GetFlags() & Stream) != 0)); m_pSoundSourceHandler->SetResource(pSoundSource); pSoundSource->SetAttribute(Source::Position, GetSceneNode().GetTransform().GetPosition()); pSoundSource->SetVolume(m_fVolume); pSoundSource->Set2D((GetFlags() & No3D) != 0); pSoundSource->SetLooping(!(GetFlags() & NoLoop)); pSoundSource->SetPitch(m_fPitch); pSoundSource->SetReferenceDistance(m_fReferenceDistance); pSoundSource->SetMaxDistance(m_fMaxDistance); pSoundSource->SetRolloffFactor(m_fRolloffFactor); OnPosition(); if (!(GetFlags() & NoStartPlayback)) pSoundSource->Play(); } } }
/** * @brief * Returns the target position within the container space of the owner node */ bool SNMRotationTarget::GetTargetPosition(Vector3 &vPos) const { // Target scene node given? if (Target.Get().GetLength()) { // Get the target scene node const SceneNode *pTarget; if (GetSceneNode().GetContainer()) pTarget = GetSceneNode().GetContainer()->GetByName(Target.Get()); else { // This must be the root :() pTarget = static_cast<const SceneContainer&>(GetSceneNode()).GetByName(Target.Get()); } if (pTarget) { // Set the position of the attached node vPos = pTarget->GetTransform().GetPosition(); // Are we in luck and the target is within the same container as the owner node? if (GetSceneNode().GetContainer() != pTarget->GetContainer()) { // Nope, we have to translate the position into the correct space :( SceneContainer *pContainer = pTarget->GetContainer(); while (pContainer) { vPos *= pContainer->GetTransform().GetMatrix(); pContainer = pContainer->GetContainer(); } // To container space of the owner node pContainer = GetSceneNode().GetContainer(); Stack<SceneContainer*> lstStack; while (pContainer) { lstStack.Push(pContainer); pContainer = pContainer->GetContainer(); } while (lstStack.GetNumOfElements()) { pContainer = lstStack.Top(); lstStack.Pop(); vPos *= pContainer->GetTransform().GetInverseMatrix(); } } // Done return true; } } // Error - no valid target scene node, no target rotation :( return false; }
//[-------------------------------------------------------] //[ 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 * Returns the sound container this sound is in */ SCSound *SNMSound::GetSoundContainer() const { // Get the PL sound container this scene node is in SceneContainer *pContainer = GetSceneNode().GetContainer(); while (pContainer && !pContainer->IsInstanceOf("PLSound::SCSound")) pContainer = pContainer->GetContainer(); // Done return (pContainer && pContainer->IsInstanceOf("PLSound::SCSound")) ? static_cast<SCSound*>(pContainer) : nullptr; }
//[-------------------------------------------------------] //[ 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(); } }
/** * @brief * Returns the gravity vector */ Vector3 PGPhysics::GetGravity() const { // Get the PL physics world this scene node is in SceneContainer *pContainer = GetContainer(); while (pContainer && !pContainer->IsInstanceOf("PLPhysics::SCPhysicsWorld")) pContainer = pContainer->GetContainer(); // Get the gravity vector Vector3 vGravity; if (pContainer && static_cast<SCPhysicsWorld*>(pContainer)->GetWorld()) static_cast<SCPhysicsWorld*>(pContainer)->GetWorld()->GetGravity(vGravity); else vGravity.SetXYZ(0.0f, -9.81f, 0.0f); // Return the gravity vector return vGravity; }
//[-------------------------------------------------------] //[ 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); }
/** * @brief * Function that is called to create the application's scene container */ void EngineApplication::OnCreateScene(SceneContainer &cContainer) { // [TODO] Load 'm_sSceneFilename' if provided // 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); } // Configure scene and set the currently used application camera SetCamera(SceneCreator::ConfigureScene(cContainer, "PLEngine::SceneCreatorDefault")); // 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); }
bool EngineApplication::LoadScene(const String &sFilename) { // Get the scene container holding our scene SceneContainer *pContainer = GetScene(); if (!pContainer) return false; // Error! (should NEVER happen...) // Disable the ingame GUI SceneNode *pGui = pContainer->GetContainer()->GetByName("GUI"); if (pGui) pGui->SetActive(false); // Clear the scene, after calling this method the scene is empty ClearScene(); // Load the scene bool bResult = pContainer->LoadByFilename(sFilename); if (bResult) { // Set a null pointer camera and default scene renderer m_sDefaultSceneRenderer = ""; m_sSceneRendererVariables = ""; m_sClearColor = ""; m_sStartCamera = ""; m_pFirstFoundCamera = nullptr; m_bHasLoadScreen = false; // Get scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { // Assign the first found camera scene node to your surface listener and look for // known key/value data scene nodes SceneQuery *pSceneQuery = pContainer->CreateQuery("PLScene::SQEnumerate"); if (pSceneQuery) { // Connect event handler pSceneQuery->SignalSceneNode.Connect(EventHandlerSceneNode); // Perform the query pSceneQuery->PerformQuery(); // Destroy the query pContainer->DestroyQuery(*pSceneQuery); } // Set to default scene renderer? if (!m_sDefaultSceneRenderer.GetLength()) m_sDefaultSceneRenderer = DefaultSceneRenderer; // Sets all scene renderer pass attribute values to their default value GetSceneRendererTool().SetDefaultValues(); // Set the used scene renderer GetSceneRendererTool().SetSceneRenderer(pContainer, m_sDefaultSceneRenderer, DefaultSceneRenderer); // Set clear color GetSceneRendererTool().SetPassAttribute("Begin", "ColorClear", m_sClearColor); // Set scene renderer variables if (m_sSceneRendererVariables.GetLength()) GetSceneRendererTool().SetValues(m_sSceneRendererVariables); // Is there a given start camera? SceneNode *pCamera = nullptr; if (m_sStartCamera.GetLength()) { SceneNode *pStartCamera = pContainer->GetByName(m_sStartCamera); if (pStartCamera && pStartCamera->IsCamera()) pCamera = pStartCamera; } // Use the first found camera? if (!pCamera) pCamera = m_pFirstFoundCamera; // Activate the current used camera by default if (pCamera) pCamera->SetActive(true); // Assign this camera to the scene renderer and to the application SetCamera(reinterpret_cast<SNCamera*>(pCamera)); } // Emit the scene loading has been finished successfully event SignalSceneLoadingFinished(); } // Enable the ingame GUI if (pGui) pGui->SetActive(true); // Done return bResult; }
//[-------------------------------------------------------] //[ 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(); } } } } }