Fichier source en cours : FW - CreateScene.h






Voici le code source cpp :




	#ifndef APPLICATION_FRAME_LISTENER_H
#define APPLICATION_FRAME_LISTENER_H

#include "Framework.h"

namespace engine
{
	namespace directx10
	{
		typedef fw::Sprite2D<D3D10> Sprite2D;
		typedef fw::Cube<D3D10> Cube;
		typedef fw::SphereMeshSceneNode<D3D10> SphereMeshSceneNode;
		typedef fw::Billboard<D3D10> Billboard;
		typedef fw::D3DXSprite2D D3DXSprite2D;
		typedef fw::Vertex3DLines<D3D10> Vertex3DLines;
		typedef fw::SkySphere<D3D10> SkySphere;
		typedef fw::SkyDomeSceneNode<D3D10> SkyDomeSceneNode;
		typedef fw::D3DMeshSceneNode<D3D10> D3DMeshSceneNode;
		typedef fw::SplinePathManager<D3D10> SplinePathManager;
	}
}

using namespace engine;

class ApplicationFrameListener : public fw::FrameListener
{
public:
	ApplicationFrameListener(D3DRenderer* pRenderer) : 
		fw::FrameListener(pRenderer), 
		m_pSprite(nullptr),
		m_pD3DXSprite(nullptr) {}

	virtual ~ApplicationFrameListener() {}

	virtual void UpdateScene(float fTimeSinceLastFrame) override
	{
		if (m_pD3DXSprite)
		{
			m_pD3DXSprite->Render();
		}
	}

	virtual void CreateScene() override 
	{
		ShaderSceneNodeInfo param;
		param.SetTexture("chakra.jpg");
		param.SetTextureTileFactor(1.0f);

		m_pSprite = new directx10::Sprite2D("water.jpg", 700, 478);
		m_pSprite->Initialize();
		m_pSprite->PushCustomShaderParameter(param);

		AddMeshSceneNode(m_pSprite); 
		
		ShaderSceneNodeInfo param2;
		param2.SetTexture("chakra.jpg");
		param2.SetTextureTileFactor(1.0f);

		directx10::Cube* pCube = new directx10::Cube;
		pCube->PushCustomShaderParameter(param2);

		pCube->SetScale(5.0f, 10.0f, 5.0f);
		pCube->SetPosition(0.0f, 100.0f, 0.0f);

		pCube->CreateAABBLines(Colours::Red);

		AddMeshSceneNode(pCube);

		ShaderSceneNodeInfo param3;
		param3.SetTexture("sun.jpg");
		param3.SetTextureTileFactor(1.0f);

		directx10::SphereMeshSceneNode* pSphere = new directx10::SphereMeshSceneNode(100);
		pSphere->SetScale(0.3f, 0.3f, 0.3f);

		pSphere->PushCustomShaderParameter(param3);

		pSphere->CreateAABBLines(Colours::White);
		pSphere->SetPosition(0.0f, 100.0f, 0.0f);	
		pSphere->RecalculateBoundingBox();

		AddMeshSceneNode(pSphere);


		directx10::Billboard* pBillboard = new directx10::Billboard(Colours::Red,
			Colours::Blue, 80, 30);


		ShaderSceneNodeInfo param4;
		param4.SetTexture("kerrigan.jpg");
		param4.SetTextureTileFactor(1.0f);

		pBillboard->PushCustomShaderParameter(param4);
		pBillboard->SetPosition(0.0f, 30.0f, 0.0f);
		pBillboard->SetScale(1.0f, 1.0f, 1.0f);

		AddMeshSceneNode(pBillboard);

		m_pD3DXSprite = new directx10::D3DXSprite2D("kerrigan.jpg", 400, 400);
		m_pD3DXSprite->Initialize();

		m_pSkySphere = new directx10::SkySphere("grassenvmap1024.dds");
		m_pSkySphere->Initialize();

		AddMeshSceneNode(m_pSkySphere);

		D3D10MeshSceneNode* pNode = GEOMETRY_CREATOR->CreateCylinderMesh<D3D10>(15, 30, 50);

		pNode->SetShaderTechnique(SHADER_MANAGER->GetShader("SimpleTexture"));

		ShaderSceneNodeInfo param5;
		param5.SetTexture("wood.jpg");
		param5.SetTextureTileFactor(10.0f);

		pNode->PushCustomShaderParameter(param5);
		pNode->CreateAABBLines(Colours::Purple);

		AddMeshSceneNode(pNode);

		directx10::D3DMeshSceneNode* pSkyDomeNode =
			new directx10::SkyDomeSceneNode("skydome.jpg", 32, 32, 1.0f, 1.0f, 10000.0f);

		pSkyDomeNode->SetPosition(0.0f, -525.0f, 0.0f);

		ShaderSceneNodeInfo param9;
		param9.SetTextureTileFactor(1.0f);

		pSkyDomeNode->PushCustomShaderParameter(param9);

		AddMeshSceneNode(pSkyDomeNode);

		std::vector<D3DXVECTOR3> points;
		points.push_back(D3DXVECTOR3(0.0f, 0.0f, 10.0f));
		points.push_back(D3DXVECTOR3(220.0f, 13.0f, 10.0f));
		points.push_back(D3DXVECTOR3(0.0f, 0.0f, 10.0f));
		points.push_back(D3DXVECTOR3(10.0f, 210.0f, 10.0f));

		directx10::SplinePathManager* pSplines = new directx10::SplinePathManager();
		pSplines->Initialize();

		SplineAnimator* pSplineAnimator = new SplineAnimator(0, points, 30.0f,
			10.0f);

		Camera* pTrackCamera = new Camera("TrackCamera");	

		SCENE_MANAGER->AddCamera(pTrackCamera);	

		SCENE_MANAGER->SetActiveCamera(pTrackCamera);	
			
		pTrackCamera->AddAnimator(pSplineAnimator);
			
		pTrackCamera->LookAt(D3DXVECTOR3(0.0f, 0.0f, 0.0f));


		pSplines->GenerateSplinePath3DLines	(pSplineAnimator);


		D3D10MeshSceneNode* pWaterPlane = OBJ_LOADER_MANAGER->LoadMeshD3D10("water_plane.obj");

		pWaterPlane->SetShaderTechnique( SHADER_MANAGER->GetShader("SimpleTexture") );

		ShaderSceneNodeInfo param6;
		param6.SetTexture("seamless.jpg");
		param6.SetTextureTileFactor(550.0f);

		pWaterPlane->PushCustomShaderParameter(param6);
		pWaterPlane->SetScale(1000.0f, 0.0f, 1000.0f);
		AddMeshSceneNode(pWaterPlane);

		D3D10MeshSceneNode* pMesh = MESH_CACHES_MANAGER(D3D10)->ReadMeshFileCache("mesh.cache");

		pMesh->SetShaderTechnique(SHADER_MANAGER->GetShader("SimpleTexture"));

		ShaderSceneNodeInfo param6;
		param6.SetTexture("seamless.jpg");
		param6.SetTextureTileFactor(550.0f);

		pMesh->PushCustomShaderParameter(param6);
		pMesh->SetScale(1000.0f, 0.0f, 1000.0f);
		pMesh->SetVertexType(VertexLayoutType::PTN_VERTEX);
		pMesh->SetDrawMethod(D3DMeshSceneNode<D3D10>::DrawMethod::DRAW_INDEXED);
		pMesh->SetTopology(D3D_PRIMITIVE_TOPOLOGY::D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		pMesh->SetIndexFormat(D3DMeshSceneNode<D3D10>::IndexFormat::FORMAT_32_BIT);

		AddMeshSceneNode(pMesh);


		for (uint32 i = 0; i < 5; i++)
		{
			directx10::Cube* pCube = new directx10::Cube;
			pCube->PushCustomShaderParameter(param2);
							
			pCube->SetScale(5.0f, 10.0f, 5.0f);
			pCube->SetPosition(1.0f * i * (20), 100.0f, 0.0f);

			AddMeshSceneNode(pCube);
		}

		MESH_CACHES_MANAGER(D3D10)->WriteMeshFileCache(pCube, "cube.cache");

		D3DGeneric_Texture* pTex1 =
			GetSystem()->GetCurrentRenderer()->GetTextureManager()->CreateTexture("Yoann.JPG", LoadMode::Zip); 

		D3DGeneric_Texture* pTex2 =
			GetSystem()->GetCurrentRenderer()->GetTextureManager()->CreateTexture("groupes.png", LoadMode::Zip);

		std::vector<D3DGeneric_Texture*> aTexturesArray;
		aTexturesArray.push_back(pTex1);
		aTexturesArray.push_back(pTex2);

		D3DGeneric_Texture* pTexArray =
			GetSystem()->GetCurrentRenderer()->GetTextureManager()->CreateTextureArray(aTexturesArray, 1200, 800);

		D3DGeneric_ShaderResourceView& pTexArrayRV =
			GetSystem()->GetCurrentRenderer()->GetTextureManager()->LoadTextureRVArray(pTexArray, "YoannTex", "Yoann");

		D3D10_GPU_MEMORY_POOL->SetTextureRVArray("aSharedTextures1", pTexArrayRV.GetD3D10Ptr());
	}

private:
	directx10::Sprite2D* m_pSprite;
	directx10::D3DXSprite2D* m_pD3DXSprite;
	directx10::SkySphere* m_pSkySphere;
};

#endif