Changing vector of objects to vector of pointer of objects for clearer construnction.

This commit is contained in:
Faerbit 2014-11-23 00:59:54 +01:00
parent ed44f71b8c
commit 97aeb6c965
2 changed files with 16 additions and 16 deletions

View File

@ -12,6 +12,9 @@ Level::Level() {
}
Level::~Level() {
for(unsigned int i = 0; i<objects.size(); i++) {
delete(objects.at(i));
}
}
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
@ -25,14 +28,15 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
//add player
Model model = Model("MarbleSmooth.obj", 0.75f);
Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f);
Object object = Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f),
Object* object = new Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(object);
this->physics.addPlayer(1.25f,object,8.0f,1);
this->physics.addPlayer(1.25f,*object,8.0f,1);
cameraCenter = object;
Model skydomeModel = Model("skydome.obj", skydomeSize);
Material skydomeMaterial = Material("skydome.png", 0.7f, 0.0f, 0.0f, 0.0f);
Object skydomeObject = Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(skydomeObject);
skydome = skydomeObject;
@ -40,20 +44,20 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
Model torchModel = Model("torch.obj", 0.75f);
Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f);
//Create object
Object torchObject = Object(torchModel, torchMaterial, glm::vec3(-3.0f, 6.0f, 0.0f),
Object* torchObject = new Object(torchModel, torchMaterial, glm::vec3(-3.0f, 6.0f, 0.0f),
glm::vec3(0.0f, 1.0472f, 0.0f), shader);
objects.push_back(torchObject);
Model blockModel = Model("Block.obj", 1.0f);
Material blockMaterial = Material("blockTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f);
Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f),
Object* blockObject = new Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(blockObject);
physics.addBox(1,1,1,blockObject,0,2);
physics.addBox(1,1,1,*blockObject,0,2);
Model columnModel = Model("Column.obj", 1.0f);
Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f);
Object columnObject = Object(columnModel, columnMaterial, glm::vec3(-2.0f, 7.0f, -2.0f),
Object* columnObject = new Object(columnModel, columnMaterial, glm::vec3(-2.0f, 7.0f, -2.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(columnObject);
@ -75,12 +79,10 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
// load a texture:
Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f);
//Create object
Object terrainObject = Object(terrainModel, terrainMaterial,
Object* terrainObject = new Object(terrainModel, terrainMaterial,
glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()),
glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(terrainObject);
cameraCenter = &objects[0];
skybox = &objects[1];
//addTerrainPhysic
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
@ -88,13 +90,11 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
void Level::render() {
for(unsigned int i = 0; i<objects.size(); i++) {
objects[i].render();
objects.at(i)->render();
}
}
void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed) {
// rotate bunny
//cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f));
// Ignore first two mouse updates, because they are incorrect
static int i = 0;
if (i <2) {
@ -122,8 +122,8 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
physics.takeUpdateStep(runTime);
objects[0].setPosition(physics.getPos(0));
objects[0].setRotation(physics.getRotation(0));
cameraCenter->setPosition(physics.getPos(0));
cameraCenter->setRotation(physics.getRotation(0));
skydome->setPosition(glm::vec3(cameraCenter->getPosition().x,
0.0f, cameraCenter->getPosition().z));

View File

@ -28,7 +28,7 @@ class Level {
void setSkydomeSize(float size);
private:
std::string filePath;
std::vector<Object> objects;
std::vector<Object*> objects;
std::vector<Light> lights;
glm::vec3 ambientLight;
glm::vec4 fogColor;