Example #1
0
void InitScene(ID3D11Device* d3dDevice)
{
    DestroyScene();
    D3DXVECTOR3 cameraEye(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 cameraAt(0.0f, 0.0f, 0.0f);
    float sceneScaling = 1.0f;
    D3DXVECTOR3 sceneTranslation(0.0f, 0.0f, 0.0f);
    bool zAxisUp = false;

#pragma region Pick Scene
    SCENE_SELECTION scene = static_cast<SCENE_SELECTION>(PtrToUlong(gSceneSelectCombo->GetSelectedData()));
	scene = CUBES;
    switch (scene) {
		case CUBE_WORLD: {
#pragma region CUBE_WORLD
            sceneScaling = 1.0f;

			D3DXMatrixScaling(&gWorldMatrix, sceneScaling, sceneScaling, sceneScaling);
			if (zAxisUp) {
				D3DXMATRIXA16 m;
				D3DXMatrixRotationX(&m, -D3DX_PI / 2.0f);
				gWorldMatrix *= m;
			}
			{
				D3DXMATRIXA16 t;
				D3DXMatrixTranslation(&t, sceneTranslation.x, sceneTranslation.y, sceneTranslation.z);
				gWorldMatrix *= t;
			}

			sceneGraph.StartScene(gWorldMatrix,sceneScaling);

			sceneGraph.Add(d3dDevice, L"..\\media\\cube\\cube.sdkmesh",0,0,0,1,500,500);
            //gMeshOpaque.Create(d3dDevice, L"..\\media\\cube\\cube.sdkmesh");			
            LoadSkybox(d3dDevice, L"..\\media\\Skybox\\EmptySpace.dds");

            cameraEye = sceneScaling * D3DXVECTOR3(100.0f, 5.0f, 5.0f);
            cameraAt = sceneScaling * D3DXVECTOR3(0.0f, 0.0f, 0.0f);
        } break;
#pragma endregion
        case POWER_PLANT_SCENE: {
#pragma region POWER_PLANT_SCENE
            sceneScaling = 1.0f;

			D3DXMatrixScaling(&gWorldMatrix, sceneScaling, sceneScaling, sceneScaling);
			if (zAxisUp) {
				D3DXMATRIXA16 m;
				D3DXMatrixRotationX(&m, -D3DX_PI / 2.0f);
				gWorldMatrix *= m;
			}
			{
				D3DXMATRIXA16 t;
				D3DXMatrixTranslation(&t, sceneTranslation.x, sceneTranslation.y, sceneTranslation.z);
				gWorldMatrix *= t;
			}
			
			sceneGraph.StartScene(gWorldMatrix,sceneScaling);

			sceneGraph.Add(d3dDevice, L"..\\media\\powerplant\\powerplant.sdkmesh");
			//gMeshOpaque.Create(d3dDevice, L"..\\media\\powerplant\\powerplant.sdkmesh");
            LoadSkybox(d3dDevice, L"..\\media\\Skybox\\EmptySpace.dds");

            cameraEye = sceneScaling * D3DXVECTOR3(100.0f, 5.0f, 5.0f);
            cameraAt = sceneScaling * D3DXVECTOR3(0.0f, 0.0f, 0.0f);
        } break;
#pragma endregion
        case SPONZA_SCENE: {
#pragma region SPONZA_SCENE
            sceneScaling = 0.05f;

			D3DXMatrixScaling(&gWorldMatrix, sceneScaling, sceneScaling, sceneScaling);
			if (zAxisUp) {
				D3DXMATRIXA16 m;
				D3DXMatrixRotationX(&m, -D3DX_PI / 2.0f);
				gWorldMatrix *= m;
			}
			{
				D3DXMATRIXA16 t;
				D3DXMatrixTranslation(&t, sceneTranslation.x, sceneTranslation.y, sceneTranslation.z);
				gWorldMatrix *= t;
			}
			
			sceneGraph.StartScene(gWorldMatrix,sceneScaling);
			

			sceneGraph.Add(d3dDevice, L"..\\media\\Sponza\\sponza_dds.sdkmesh");
			//gMeshOpaque.Create(d3dDevice, L"..\\media\\Sponza\\sponza_dds.sdkmesh");
            LoadSkybox(d3dDevice, L"..\\media\\Skybox\\EmptySpace.dds");

            cameraEye = sceneScaling * D3DXVECTOR3(1200.0f, 200.0f, 100.0f);
            cameraAt = sceneScaling * D3DXVECTOR3(0.0f, 0.0f, 0.0f);
        } break;
#pragma endregion
		case MULTI_SCENE:{
#pragma region MULTI_SCENE
            sceneScaling = .05f;
			
			D3DXMatrixScaling(&gWorldMatrix, sceneScaling, sceneScaling, sceneScaling);
			if (zAxisUp) {
				D3DXMATRIXA16 m;
				D3DXMatrixRotationX(&m, -D3DX_PI / 2.0f);
				gWorldMatrix *= m;
			}
			{
				D3DXMATRIXA16 t;
				D3DXMatrixTranslation(&t, sceneTranslation.x, sceneTranslation.y, sceneTranslation.z);
				gWorldMatrix *= t;
			}
			
			sceneGraph.StartScene(gWorldMatrix,sceneScaling);

			sceneGraph.Add(d3dDevice, L"..\\media\\Sponza\\sponza_dds.sdkmesh");
			D3DXMATRIXA16 translate;
			D3DXMatrixTranslation(&translate,0,10,0);
			sceneGraph.Add(d3dDevice,L"..\\media\\powerplant\\powerplant.sdkmesh",translate);
			//gMeshOpaque.Create(d3dDevice, L"..\\media\\Sponza\\sponza_dds.sdkmesh");
			//gMeshOpaque2.Create(d3dDevice,L"..\\media\\powerplant\\powerplant.sdkmesh");
            LoadSkybox(d3dDevice, L"..\\media\\Skybox\\EmptySpace.dds");

            cameraEye = sceneScaling * D3DXVECTOR3(100.0f, 5.0f, 5.0f);
            cameraAt = sceneScaling * D3DXVECTOR3(0.0f, 0.0f, 0.0f);
		}break;
#pragma endregion
		case CUBES:
		{
#pragma region CUBES
			sceneScaling = 1.0f;

			D3DXMatrixScaling(&gWorldMatrix, sceneScaling, sceneScaling, sceneScaling);
			if (zAxisUp) {
				D3DXMATRIXA16 m;
				D3DXMatrixRotationX(&m, -D3DX_PI / 2.0f);
				gWorldMatrix *= m;
			}
			{
				D3DXMATRIXA16 t;
				D3DXMatrixTranslation(&t, sceneTranslation.x, sceneTranslation.y, sceneTranslation.z);
				gWorldMatrix *= t;
			}

			sceneGraph.StartScene(gWorldMatrix,sceneScaling);
			D3DXMATRIXA16 translate;
			D3DXMatrixTranslation(&translate,0,0,0);
			
			D3DXMATRIXA16 s;
			D3DXMatrixScaling(&s,100,0.01,100);
			s=s*translate;
			//sceneGraph.Add(d3dDevice, L"..\\media\\cube\\cube.sdkmesh",s);
			//sceneGraph.Add(d3dDevice, L"..\\media\\cube\\cube.sdkmesh",s);


			//Initializing PhysX
			if(!PXEngine)
				PXEngine = new PhysXEngine();
			sceneGraph.AddMeshInstance(d3dDevice, L"..\\media\\cube\\cube.sdkmesh");
			//sceneGraph.Add(d3dDevice,L"..\\media\\powerplant\\powerplant.sdkmesh",translate);
			if(PXEngine)
				PXEngine->InitializePhysX(cubeList, PhysXUnProject, PhysXProject);

			sceneGraph.Add(d3dDevice, L"..\\media\\cube\\cube.sdkmesh",0,0,0,1000,1000,1000);

			//Creating all of the cubes
			for(int i = 0; i < cubeList->size(); i++)
			{
				if(i%10==0)
				{
					sceneGraph.Add(d3dDevice, L"..\\media\\cube\\cube.sdkmesh",0,0,0,1,1,1);
				}
				else
					(*cubeList)[i]->id = sceneGraph.AddInstance(1,(*cubeList)[i]->x, (*cubeList)[i]->y, (*cubeList)[i]->z, (*cubeList)[i]->sx, (*cubeList)[i]->sy, (*cubeList)[i]->sz);
			}
/*
			for(float x =0; x<15;x+=5)
			{
				for(float y=0; y<15; y+=5)
				{
					for(float z=0; z<15; z+=5)
					{
						D3DXMatrixTranslation(&translate,x,y,z);
						sceneGraph.Add(d3dDevice, L"..\\media\\cube\\cube.sdkmesh",x,y,z,1,1,1);
					}
				}
			}
*/
			LoadSkybox(d3dDevice, L"..\\media\\Skybox\\Clouds.dds");
			cameraEye = sceneScaling * D3DXVECTOR3(100.0f, 5.0f, 5.0f);
            cameraAt = sceneScaling * D3DXVECTOR3(0.0f, 0.0f, 0.0f);

		}break;
#pragma endregion
    };
#pragma endregion
	
	cameraEye.x += 200;
    gViewerCamera.SetViewParams(&cameraEye, &cameraAt);
    gViewerCamera.SetScalers(0.01f, 100.0f);
    gViewerCamera.FrameMove(0.0f);
    
    // Zero out the elapsed time for the next frame
    gZeroNextFrameTime = true;
}