Commit 7008a5ed authored by Håkon Berg Borhaug's avatar Håkon Berg Borhaug
Browse files

Implemented moving road-landscape and rotated camera

parent c3171b1f
......@@ -31,7 +31,10 @@ class GameManager : public SceneObject
virtual void privateUpdate();
private:
std::shared_ptr<Landscape> ls_;
std::shared_ptr<Landscape> ls1_;
std::shared_ptr<Landscape> ls2_;
std::shared_ptr<Landscape> ls3_;
std::shared_ptr<Landscape> ls4_;
std::shared_ptr<Character> character_;
std::shared_ptr<Camera> cam_;
std::shared_ptr<Snow> snow_;
......
......@@ -15,13 +15,13 @@
#include "../../glm-master/glm/glm.hpp"
// 4 points with 3D position and 2D texture position
#define POS_ARRAY_SIZE 4 * 4 * (3 + 2) //4 * 4 * (3 + 2)
#define IND_ARRAY_SIZE 4 * 4 //4 * 4
#define POS_ARRAY_SIZE 4 * (3 + 2)
#define IND_ARRAY_SIZE 4
class Landscape : public SceneObject
{
public:
Landscape();
Landscape(glm::vec3 trans);
~Landscape();
protected:
......@@ -43,35 +43,35 @@ private:
// 0.5f, 0.5f, 3.0f,
// -0.5f, 0.5f, 0.0f
// Left plane
-100.0f, -50.0f, 100.0f, 0.0f, 0.0f,
100.0f, -50.0f, 100.0f, 1.0f, 0.0f,
100.0f, -50.0f, -100.0f, 1.0f, 1.0f,
-100.0f, -50.0f, -100.0f, 0.0f, 1.0f,
-100.0f,0.0f, 100.0f, 0.0f, 0.0f,
100.0f, 0.0f, 100.0f, 1.0f, 0.0f,
100.0f, 0.0f, -100.0f, 1.0f, 1.0f,
-100.0f,0.0f, -100.0f, 0.0f, 1.0f,
// Middle plane
0.0f, -50.0f, 50.0f, 0.0f, 0.0f,
100.0f, -50.0f, 50.0f, 1.0f, 0.0f,
100.0f, -50.0f, -50.0f, 1.0f, 1.0f,
0.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// // Middle plane
// 0.0f, -50.0f, 50.0f, 0.0f, 0.0f,
// 100.0f, -50.0f, 50.0f, 1.0f, 0.0f,
// 100.0f, -50.0f, -50.0f, 1.0f, 1.0f,
// 0.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// Right plane
100.0f, -50.0f, 50.0f, 0.0f, 0.0f,
200.0f, -50.0f, 50.0f, 1.0f, 0.0f,
200.0f, -50.0f, -50.0f, 1.0f, 1.0f,
100.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// // Right plane
// 100.0f, -50.0f, 50.0f, 0.0f, 0.0f,
// 200.0f, -50.0f, 50.0f, 1.0f, 0.0f,
// 200.0f, -50.0f, -50.0f, 1.0f, 1.0f,
// 100.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// Background
-1000.0f, -1000.0f, -500.0f, 0.0f, 0.0f,
1000.0f, -1000.0f, -500.0f, 1.0f, 0.0f,
1000.0f, 1000.0f, -500.0f, 1.0f, 1.0f,
-1000.0f, 1000.0f, -500.0f, 0.0f, 1.0f,
// // Background
// -1000.0f, -1000.0f, -500.0f, 0.0f, 0.0f,
// 1000.0f, -1000.0f, -500.0f, 1.0f, 0.0f,
// 1000.0f, 1000.0f, -500.0f, 1.0f, 1.0f,
// -1000.0f, 1000.0f, -500.0f, 0.0f, 1.0f,
};
unsigned int indices_[IND_ARRAY_SIZE] = {
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
// 4, 5, 6, 7,
// 8, 9, 10, 11,
// 12, 13, 14, 15
};
VertexArray vao;
......@@ -80,7 +80,7 @@ private:
IndexBuffer ibo = IndexBuffer(indices_, IND_ARRAY_SIZE);
Shader shader = Shader("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Vertex.shader",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Fragment.shader");
Texture texture = Texture("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/test.jpg");
Texture texture = Texture("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/road.jpg");
unsigned int textureSlot = 0;
};
......@@ -6,7 +6,7 @@ layout(location = 0) out vec4 color;
in vec2 v_TexCoord;
uniform vec4 u_Color;
//uniform vec4 u_Color;
uniform sampler2D u_Texture;
void main() {
......
......@@ -8,7 +8,9 @@
Camera::Camera()
{
matrix_ = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -300.0f));
auto translation = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -300.0f));
auto rotation = glm::rotate(glm::mat4(1.0f), glm::radians(30.0f), glm::vec3(0.0f,0.0f,1.0f));
matrix_ = translation * rotation;
}
Camera::~Camera()
......
......@@ -31,7 +31,6 @@ void Character::privateInit()
setUpHealthbar();
GLenum err = glGetError();
if (err != GL_NO_ERROR)
std::cout<< "OpenGL error: " << gluErrorString(err) << std::endl;
......@@ -349,6 +348,7 @@ void Character::setUpHBTextures()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
stbi_set_flip_vertically_on_load(0);
int width, height, nrChannels;
std::string filepath = "C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/HP.jpg";
unsigned char *data = stbi_load(filepath.c_str(), &width, &height, &nrChannels, 0);
......@@ -366,9 +366,9 @@ void Character::setUpHBTextures()
void Character::privateUpdate()
{
auto translation = glm::translate(glm::mat4(1.0f), glm::vec3(0.2f * speed_, 0.0f, 0.0f));
auto rotation = glm::rotate(matrix_, 0.01f, glm::vec3(0.0f,1.0f,0.0f));
matrix_ = translation * rotation;
// auto translation = glm::translate(glm::mat4(1.0f), glm::vec3(0.2f * speed_, 0.0f, 0.0f));
// auto rotation = glm::rotate(matrix_, 0.01f, glm::vec3(0.0f,1.0f,0.0f));
// matrix_ = translation * rotation;
}
......
......@@ -23,8 +23,14 @@ void GameManager::privateInit()
// Adding the camera to the scene
cam_.reset(new Camera());
ls_.reset(new Landscape());
this->addSubObject(ls_);
ls1_.reset(new Landscape(glm::vec3(0.0f, -50.0f, 0.0f)));
this->addSubObject(ls1_);
ls2_.reset(new Landscape(glm::vec3(200.0f, -50.0f, 0.0f)));
this->addSubObject(ls2_);
ls3_.reset(new Landscape(glm::vec3(400.0f, -50.0f, 0.0f)));
this->addSubObject(ls3_);
ls4_.reset(new Landscape(glm::vec3(600.0f, -50.0f, 0.0f)));
this->addSubObject(ls4_);
character_.reset(new Character());
this->addSubObject(character_);
......
......@@ -4,8 +4,9 @@
#include "../include/Projection.h"
Landscape::Landscape()
Landscape::Landscape(glm::vec3 trans)
{
matrix_ = glm::translate(matrix_, trans);
}
Landscape::~Landscape()
......@@ -31,10 +32,9 @@ void Landscape::privateInit()
/* SHADER */
shader.Bind();
shader.SetUniform4f("u_Color", 0.0f, 0.0f, 1.0f, 1.0f);
// shader.SetUniform4f("u_Color", 0.0f, 0.0f, 1.0f, 1.0f);
/* TEXTURE */
// unsigned int textureSlot = 0;
texture.Bind(textureSlot);
shader.SetUniform1i("u_Texture", textureSlot);
......@@ -44,7 +44,6 @@ void Landscape::privateInit()
vbo.Unbind();
ibo.Unbind();
shader.Unbind();
}
void Landscape::privateRender()
......@@ -127,6 +126,11 @@ void Landscape::privateRender()
void Landscape::privateUpdate()
{
if (matrix_[3].x < -400) {
matrix_ = glm::translate(matrix_, glm::vec3(800.0f, 0.0f, 0.0f));
}
else {
matrix_ = glm::translate(matrix_, glm::vec3(-2.0f, 0.0f, 0.0f));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment