Esempio n. 1
0
/**
*  @brief
*    Performs picking by using the given line start and end positions
*/
bool Picking::PerformPicking(PickingResult &cPickingResult, SceneContainer &cContainer, const Vector3 &vLineStartPos, const Vector3 &vLineEndPos, Cull::Enum nCull)
{
	// Initialize the picking result
	m_pPickingResult = &cPickingResult;
	cPickingResult.m_pSceneNode				 = nullptr;
	cPickingResult.m_nGeometry				 = 0;
	cPickingResult.m_nTriangle				 = 0;
	cPickingResult.m_vPoint					 = Vector3::Zero;
	cPickingResult.m_pSceneContainer		 = &cContainer;
	cPickingResult.m_vLineStartPos			 = vLineStartPos;
	cPickingResult.m_fNearestSquaredDistance = -1.0f;

	// Trace line
	SQLine *pQuery = static_cast<SQLine*>(cContainer.CreateQuery("PLScene::SQLine"));
	if (pQuery) {
		pQuery->SignalSceneNode.Connect(EventHandlerSceneNode);
		pQuery->GetLine().Set(vLineStartPos, vLineEndPos);
		pQuery->SetCull(nCull);
		pQuery->PerformQuery();
		cContainer.DestroyQuery(*pQuery);
	}

	// Was something picked?
	if (cPickingResult.m_pSceneNode) {
		// Ensure that the picking distance is not greater than the possible maximum
		if ((vLineEndPos-vLineStartPos).GetSquaredLength() >= cPickingResult.m_fNearestSquaredDistance)
			return (cPickingResult.m_pSceneNode != nullptr);
	}

	// Nothing (in range) was picked
	return false;
}
Esempio n. 2
0
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;
}