Added waterPlane.(with skydome texture)
This commit is contained in:
parent
62e7c42ec6
commit
b7fa9ee5a1
@ -12152,6 +12152,11 @@
|
||||
<nightTexture>nightskydome.png</nightTexture>
|
||||
</skydome>
|
||||
|
||||
<waterPlane>
|
||||
<yPosition>15</yPosition>
|
||||
<texture>skydomeNew.png</texture>
|
||||
</waterPlane>
|
||||
|
||||
<physics>
|
||||
<friction>0.9</friction>
|
||||
<strength>200.0</strength>
|
||||
|
36
loader.cc
36
loader.cc
@ -1,4 +1,5 @@
|
||||
#include "loader.hh"
|
||||
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
|
||||
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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -21,6 +21,12 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||
}
|
||||
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user