diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml
index 162fab6..52e2ac3 100644
--- a/data/levels/Level1.xml
+++ b/data/levels/Level1.xml
@@ -12152,6 +12152,11 @@
nightskydome.png
+
+ 15
+ skydomeNew.png
+
+
0.9
200.0
diff --git a/loader.cc b/loader.cc
index 25e5728..965232d 100644
--- a/loader.cc
+++ b/loader.cc
@@ -1,4 +1,5 @@
#include "loader.hh"
+#include
using namespace tinyxml2;
Loader::Loader() {
@@ -94,6 +95,41 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
Skydome skydomeObject = Skydome(skydomeModel, skydomeMaterial, nightMaterial);
level->setSkydomeObject(skydomeObject);
+ //load the waterPlane
+ XMLElement* waterElement = doc->FirstChildElement("waterPlane");
+ if (waterElement != NULL){
+ float waterHeight = queryFloat(waterElement, "yPosition");
+ std::string waterTexture = queryString(waterElement, "texture");
+ std::string waterTexturePath = "../" + globalTexturePath + waterTexture;
+ if(stat(waterTexturePath.c_str(), &buf) != 0){
+ std::cout << "The texture file " << waterTexturePath << " does not exist." << std::endl;
+ exit(-1);
+ }
+ float heightmapHeight = level->getTerrain()->getHeightmapHeight();
+ float heightmapWidth = level->getTerrain()->getHeightmapWidth();
+ float planeData[] = {
+ -heightmapWidth/2.0f, waterHeight, -heightmapHeight/2.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
+ -heightmapWidth/2.0f, waterHeight, heightmapHeight/2.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ heightmapWidth/2.0f, waterHeight, -heightmapHeight/2.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
+
+ heightmapWidth/2.0f, waterHeight, heightmapHeight/2.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ -heightmapWidth/2.0f, waterHeight, heightmapHeight/2.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ heightmapWidth/2.0f, waterHeight, -heightmapHeight/2.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f
+ };
+ ACGL::OpenGL::SharedArrayBuffer water_ab = ACGL::OpenGL::SharedArrayBuffer(new ACGL::OpenGL::ArrayBuffer());
+ water_ab->defineAttribute("aPosition", GL_FLOAT, 3);
+ water_ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
+ water_ab->defineAttribute("aNormal", GL_FLOAT, 3);
+ water_ab->setDataElements(6, planeData);
+ ACGL::OpenGL::SharedVertexArrayObject water_vao = ACGL::OpenGL::SharedVertexArrayObject(new ACGL::OpenGL::VertexArrayObject());
+ water_vao->bind();
+ water_vao->setMode(GL_TRIANGLES);
+ water_vao->attachAllAttributes(water_ab);
+ Material water_material = Material(waterTexture, 0.1f, 0.2f, 0.8f, 5.0f, true);
+ Object* water_object = new Object(water_vao, water_material, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), true);
+ level->addObject(water_object);
+ }
+
//load lighting parameters
float rColour, gColour, bColour, alpha, xOffset, yOffset, zOffset, intensity;
XMLElement* ambientElement = doc->FirstChildElement("ambientLight");
diff --git a/material.cc b/material.cc
index d084f5e..37fc338 100644
--- a/material.cc
+++ b/material.cc
@@ -1,13 +1,14 @@
#include "material.hh"
Material::Material(std::string filePath, float ambientFactor, float diffuseFactor,
- float specularFactor, float shininess) {
+ float specularFactor, float shininess, bool movingTexture) {
reference = ACGL::OpenGL::Texture2DFileManager::the()->get(ACGL::OpenGL::Texture2DCreator(filePath));
reference->generateMipmaps();
this->ambientFactor = ambientFactor;
this->diffuseFactor = diffuseFactor;
this->specularFactor = specularFactor;
this->shininess = shininess;
+ this->movingTexture = movingTexture;
}
Material::Material() {
@@ -35,3 +36,7 @@ float Material::getSpecularFactor() {
float Material::getShininess() {
return shininess;
}
+
+bool Material::isMoving(){
+ return movingTexture;
+}
diff --git a/material.hh b/material.hh
index c151568..4789ca8 100644
--- a/material.hh
+++ b/material.hh
@@ -9,7 +9,7 @@
class Material{
public:
Material(std::string filePath, float ambientFactor,
- float diffuseFactor, float specularFactor, float shininess);
+ float diffuseFactor, float specularFactor, float shininess, bool movingTexture = false);
Material();
ACGL::OpenGL::SharedTexture2D getReference();
~Material();
@@ -17,12 +17,15 @@ class Material{
float getDiffuseFactor();
float getSpecularFactor();
float getShininess();
+ bool isMoving();
+
private:
ACGL::OpenGL::SharedTexture2D reference;
float ambientFactor;
float diffuseFactor;
float specularFactor;
float shininess;
+ bool movingTexture;
};
#endif
diff --git a/object.cc b/object.cc
index d5daa34..ea09ddf 100644
--- a/object.cc
+++ b/object.cc
@@ -21,6 +21,12 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
}
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale(glm::vec3(model.getScale()));
if(texturePass) {
+ if (material.isMoving()) {
+ shader->setUniform("movingTexture", true);
+ }
+ else {
+ shader->setUniform("movingTexture", false);
+ }
shader->setTexture("uTexture", material.getReference(), 0);
shader->setUniform("modelMatrix", modelMatrix);
}