codesamples >>
crossplatform scenemanager class
Crossplatform: SceneManager class
Project:
Crossplatform application (Windows & PS3)
Engine:
Custom
Code language:
C++
Class description:
The SceneManager manages all the objects in the scene for Windows and PS3.
MainProgram.cpp
#include "SceneManager.h"
// Constructor
SceneManager::SceneManager(DEVICE* device): m_pDevice(device)
{
}
// Destructor
SceneManager::~SceneManager()
{
}
void SceneManager::UpdateScene(Camera* camera, float time)
{
// Update all the objects in the scene
std::vector<Primitive*>::iterator it;
for (it = m_PrimitiveList.begin(); it != m_PrimitiveList.end(); ++it)
{
Primitive* primitive = *it;
primitive->Update(camera, time);
}
}
void SceneManager::CreateCubes(int amount)
{
// Create all the cubes
for(int index = 0; index < amount; index++)
{
Cube *cube = new Cube();
cube->InitializeData(m_pDevice);
m_PrimitiveList.push_back(cube);
// Rotate and position the cubes
cube->SetAngleY(index * 0.2f);
cube->SetPosition(rand()%200-100.0f, rand()%200-100.0f, rand()%200-100.0f);
}
}
void SceneManager::CreateOctahedrons(int amount)
{
// Create all the octahedrons
for(int index = 0; index < amount; index++)
{
Octahedron *octahedron = new Octahedron();
octahedron->InitializeData(m_pDevice);
m_PrimitiveList.push_back(octahedron);
// Rotate and position the octahedrons
octahedron->SetAngleY(index * 0.2f);
octahedron->SetPosition(rand()%200-100.0f, rand()%200-100.0f, rand()%200-100.0f);
}
}
#if defined(WIN32)
void SceneManager::RenderScene(Camera* camera, ID3D11DeviceContext* deviceContext,
ID3D11VertexShader* vertexShader, ID3D11PixelShader* pixelShader, float time)
{
// Render all the objects
std::vector<Primitive*>::iterator it;
for (it = m_PrimitiveList.begin(); it != m_PrimitiveList.end(); ++it)
{
Primitive* primitive = *it;
primitive->Render(camera, deviceContext, vertexShader, pixelShader, time);
}
}
#elif(PS3)
void SceneManager::RenderScene(Camera* camera, CGprogram cGVertexProgram, CGprogram cGFragmentProgram,
void* vertexProgramUCode, void* fragmentProgramUCode)
{
// Render all the objects
std::vector<Primitive*>::iterator it;
for (it = m_PrimitiveList.begin(); it != m_PrimitiveList.end(); ++it)
{
Primitive* primitive = *it;
primitive->Render(camera, cGVertexProgram, cGFragmentProgram, vertexProgramUCode,
fragmentProgramUCode);
}
}
#endif
SceneManager.h
#ifndef _SCENEMANAGER_H
#define _SCENEMANAGER_H
// Crossplatform: Includes
#include <vector>
#include <assert.h>
#include <string.h>
#include "Cube.h"
#include "Octahedron.h"
// Windows Specific: Includes
#if defined(WIN32)
#include <windows.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dcompiler.h>
#include "Device_Win32.h"
#endif
// PS3 Specific: Includes
#if defined(PS3)
#include "Device_PS3.h"
#endif
class SceneManager
{
public:
// Crossplatform: Functions
SceneManager(DEVICE* device);
virtual ~SceneManager();
void UpdateScene(Camera* camera, float time);
void CreateCubes(int amount);
void CreateOctahedrons(int amount);
// Platform specific functions
#if defined(WIN32)
// Windows Specific: Functions
void RenderScene(Camera* camera, ID3D11DeviceContext* deviceContext, ID3D11VertexShader* vertexShader,
ID3D11PixelShader* pixelShader, float time);
#elif(PS3)
// PS3 Specific: Functions
void RenderScene(Camera* camera, CGprogram cGVertexProgram, CGprogram cGFragmentProgram,
void* vertexProgramUCode, void* fragmentProgramUCode);
#endif
private:
// Crossplatform: Datamembers
std::vector<Primitive*> m_PrimitiveList;
DEVICE* m_pDevice;
};
#endif