Changing vector of objects to vector of pointer of objects for clearer construnction.
This commit is contained in:
parent
ed44f71b8c
commit
97aeb6c965
30
level.cc
30
level.cc
@ -12,6 +12,9 @@ Level::Level() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Level::~Level() {
|
Level::~Level() {
|
||||||
|
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||||
|
delete(objects.at(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||||
@ -25,14 +28,15 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
//add player
|
//add player
|
||||||
Model model = Model("MarbleSmooth.obj", 0.75f);
|
Model model = Model("MarbleSmooth.obj", 0.75f);
|
||||||
Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f);
|
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);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(object);
|
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);
|
Model skydomeModel = Model("skydome.obj", skydomeSize);
|
||||||
Material skydomeMaterial = Material("skydome.png", 0.7f, 0.0f, 0.0f, 0.0f);
|
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);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(skydomeObject);
|
objects.push_back(skydomeObject);
|
||||||
skydome = skydomeObject;
|
skydome = skydomeObject;
|
||||||
@ -40,20 +44,20 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
Model torchModel = Model("torch.obj", 0.75f);
|
Model torchModel = Model("torch.obj", 0.75f);
|
||||||
Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f);
|
Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f);
|
||||||
//Create object
|
//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);
|
glm::vec3(0.0f, 1.0472f, 0.0f), shader);
|
||||||
objects.push_back(torchObject);
|
objects.push_back(torchObject);
|
||||||
|
|
||||||
Model blockModel = Model("Block.obj", 1.0f);
|
Model blockModel = Model("Block.obj", 1.0f);
|
||||||
Material blockMaterial = Material("blockTexture_small.png", 0.1f, 0.6, 0.4f, 2.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);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(blockObject);
|
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);
|
Model columnModel = Model("Column.obj", 1.0f);
|
||||||
Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.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);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(columnObject);
|
objects.push_back(columnObject);
|
||||||
|
|
||||||
@ -75,12 +79,10 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
// load a texture:
|
// load a texture:
|
||||||
Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f);
|
Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f);
|
||||||
//Create object
|
//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.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(terrainObject);
|
objects.push_back(terrainObject);
|
||||||
cameraCenter = &objects[0];
|
|
||||||
skybox = &objects[1];
|
|
||||||
|
|
||||||
//addTerrainPhysic
|
//addTerrainPhysic
|
||||||
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
|
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
|
||||||
@ -88,13 +90,11 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
|
|
||||||
void Level::render() {
|
void Level::render() {
|
||||||
for(unsigned int i = 0; i<objects.size(); i++) {
|
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) {
|
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
|
// Ignore first two mouse updates, because they are incorrect
|
||||||
static int i = 0;
|
static int i = 0;
|
||||||
if (i <2) {
|
if (i <2) {
|
||||||
@ -122,8 +122,8 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
|
|||||||
|
|
||||||
physics.takeUpdateStep(runTime);
|
physics.takeUpdateStep(runTime);
|
||||||
|
|
||||||
objects[0].setPosition(physics.getPos(0));
|
cameraCenter->setPosition(physics.getPos(0));
|
||||||
objects[0].setRotation(physics.getRotation(0));
|
cameraCenter->setRotation(physics.getRotation(0));
|
||||||
|
|
||||||
skydome->setPosition(glm::vec3(cameraCenter->getPosition().x,
|
skydome->setPosition(glm::vec3(cameraCenter->getPosition().x,
|
||||||
0.0f, cameraCenter->getPosition().z));
|
0.0f, cameraCenter->getPosition().z));
|
||||||
|
2
level.hh
2
level.hh
@ -28,7 +28,7 @@ class Level {
|
|||||||
void setSkydomeSize(float size);
|
void setSkydomeSize(float size);
|
||||||
private:
|
private:
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
std::vector<Object> objects;
|
std::vector<Object*> objects;
|
||||||
std::vector<Light> lights;
|
std::vector<Light> lights;
|
||||||
glm::vec3 ambientLight;
|
glm::vec3 ambientLight;
|
||||||
glm::vec4 fogColor;
|
glm::vec4 fogColor;
|
||||||
|
Loading…
Reference in New Issue
Block a user