diff --git a/Geometry/stoneTexture.png b/Geometry/stoneTexture.png deleted file mode 100644 index 5bc577c..0000000 Binary files a/Geometry/stoneTexture.png and /dev/null differ diff --git a/Geometry/Bunny.ab b/Levels/Geometry/Bunny.ab similarity index 100% rename from Geometry/Bunny.ab rename to Levels/Geometry/Bunny.ab diff --git a/Geometry/Bunny.obj b/Levels/Geometry/Bunny.obj similarity index 100% rename from Geometry/Bunny.obj rename to Levels/Geometry/Bunny.obj diff --git a/Geometry/BunnyColors.atb b/Levels/Geometry/BunnyColors.atb similarity index 100% rename from Geometry/BunnyColors.atb rename to Levels/Geometry/BunnyColors.atb diff --git a/Geometry/Quad.ab b/Levels/Geometry/Quad.ab similarity index 100% rename from Geometry/Quad.ab rename to Levels/Geometry/Quad.ab diff --git a/Geometry/Sphere.obj b/Levels/Geometry/Sphere.obj similarity index 100% rename from Geometry/Sphere.obj rename to Levels/Geometry/Sphere.obj diff --git a/Geometry/clownfishBunny.png b/Levels/Geometry/clownfishBunny.png similarity index 100% rename from Geometry/clownfishBunny.png rename to Levels/Geometry/clownfishBunny.png diff --git a/Geometry/clownfishBunny.ppm b/Levels/Geometry/clownfishBunny.ppm similarity index 100% rename from Geometry/clownfishBunny.ppm rename to Levels/Geometry/clownfishBunny.ppm diff --git a/Geometry/terrainTexture.png b/Levels/Textures/terrainTexture.png similarity index 100% rename from Geometry/terrainTexture.png rename to Levels/Textures/terrainTexture.png diff --git a/Levels/LevelTest/terrain/heightmap.png b/Levels/heightmapLvlTest.png similarity index 100% rename from Levels/LevelTest/terrain/heightmap.png rename to Levels/heightmapLvlTest.png diff --git a/camera.cc b/camera.cc index d5fe672..109ff7a 100644 --- a/camera.cc +++ b/camera.cc @@ -19,6 +19,7 @@ float Camera::getDistance() { void Camera::setDistance(float distance) { this->distance = distance; + updatePosition(); } glm::vec2 Camera::getRotation() { @@ -27,9 +28,11 @@ glm::vec2 Camera::getRotation() { void Camera::setRotation(glm::vec2 rotation) { this->rotation = rotation; + updatePosition(); } void Camera::updateRotation(glm::vec2 rotation) { + this->rotation += rotation; if((this->rotation.x + rotation.x) >= 1.57f) { this->rotation.x = 1.57; this->rotation.y += rotation.y; @@ -41,6 +44,7 @@ void Camera::updateRotation(glm::vec2 rotation) { else { this-> rotation += rotation; } + updatePosition(); } void Camera:: updateDistance(float distance) { @@ -53,4 +57,18 @@ void Camera:: updateDistance(float distance) { else { this->distance += distance; } + updatePosition(); } + +void Camera::updatePosition() { + glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, distance, 0.0f); + // rotate vector + glm::mat4 rotationMatrix = + glm::rotate(rotation[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate(rotation[0], glm::vec3(1.0f, 0.0f, 0.0f)); + this->vector = glm::vec3(rotationMatrix * cameraVector); +} + +glm::vec3 Camera::getVector() { + return vector; +} + diff --git a/camera.hh b/camera.hh index ee21e98..70337cc 100644 --- a/camera.hh +++ b/camera.hh @@ -14,9 +14,12 @@ class Camera { glm::vec2 getRotation(); void setRotation(glm::vec2 rotation); void updateRotation(glm::vec2 rotation); //adds to current rotation + glm::vec3 getVector(); private: + void updatePosition(); float distance; glm::vec2 rotation; + glm::vec3 vector; }; #endif diff --git a/graphics.cc b/graphics.cc index 72550d7..3385480 100644 --- a/graphics.cc +++ b/graphics.cc @@ -154,11 +154,7 @@ glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, fl } glm::mat4 Graphics::buildViewMatrix(Level* level) { - glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, level->getCamera()->getDistance(), 0.0f); - // rotate vector - glm::mat4 rotationMatrix = - glm::rotate(level->getCamera()->getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) *glm::rotate(level->getCamera()->getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f)); - cameraVector = rotationMatrix * cameraVector; //construct lookAt (cameraPosition = cameraCenter + cameraVector - return glm::lookAt(level->getCameraCenter()->getPosition() + glm::vec3(cameraVector), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f)); + return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()), + level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f)); } diff --git a/main.cc b/main.cc index b34583b..1d231fc 100644 --- a/main.cc +++ b/main.cc @@ -37,8 +37,8 @@ void Application::init() // define where shaders and textures can be found: ACGL::Base::Settings::the()->setResourcePath("../"); ACGL::Base::Settings::the()->setShaderPath("Shader/"); - ACGL::Base::Settings::the()->setTexturePath("Geometry/"); - ACGL::Base::Settings::the()->setGeometryPath("Geometry/"); + ACGL::Base::Settings::the()->setTexturePath("Levels/Textures/"); + ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/"); // construct VAO to give shader correct Attribute locations ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared(); diff --git a/terrain.cc b/terrain.cc index b8a71e7..e27e4b5 100644 --- a/terrain.cc +++ b/terrain.cc @@ -13,10 +13,10 @@ Terrain::~Terrain() { void Terrain::load() { - filePath = "../Levels/LevelTest/terrain/"; //TODO remove this, its only for testing + filePath = "../Levels/heightmapLvlTest.png"; //TODO remove this, its only for testing std::vector image; //the raw pixels - unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, filePath + "heightmap.png"); + unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, filePath); if (error) { std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; } @@ -41,7 +41,7 @@ void Terrain::makeTriangleMesh(){ ab->defineAttribute("aTexCoord", GL_FLOAT, 2); ab->defineAttribute("aNormal", GL_FLOAT, 3); - unsigned int rowNum=0, columnNum=0, dataCount=0, abNumFloats=8; //initializing: + unsigned int rowNum=0, columnNum=0, dataCount=0, floatsPerVertex=8; //initializing: bool movingRight = true, isUp = true; int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1; float* abData = new float[numVertices * floatsPerVertex]; @@ -56,9 +56,9 @@ void Terrain::makeTriangleMesh(){ else if (movingRight) { if (columnNum == this->heightmapWidth - 1) { set_abData(abData, dataCount, rowNum, columnNum); - dataCount += abNumFloats; + dataCount += floatsPerVertex; set_abData(abData, dataCount, rowNum, columnNum); - dataCount += abNumFloats; + dataCount += floatsPerVertex; movingRight = false; rowNum = rowNum + 1; } @@ -71,9 +71,9 @@ void Terrain::makeTriangleMesh(){ else { if (columnNum == 0){ set_abData(abData, dataCount, rowNum, columnNum); - dataCount += abNumFloats; + dataCount += floatsPerVertex; set_abData(abData, dataCount, rowNum, columnNum); - dataCount += abNumFloats; + dataCount += floatsPerVertex; movingRight = true; rowNum = rowNum + 1; }