Commit 2826b080 authored by Håkon Berg Borhaug's avatar Håkon Berg Borhaug
Browse files

Implemented skybox, but need to fix camera/landscape rotation

parent 7008a5ed
......@@ -26,7 +26,7 @@ endif(NOT OPENGL_FOUND)
set( INCLUDE
include/Landscape.hpp
include/Plane.hpp
include/Camera.hpp
include/Clock.hpp
include/FpsCounter.hpp
......@@ -50,7 +50,7 @@ set( INCLUDE
include/stb_image.h
)
set( SRCS
src/Landscape.cpp
src/Plane.cpp
src/Camera.cpp
src/GameManager.cpp
src/SceneObject.cpp
......
......@@ -3,7 +3,7 @@
#include <windows.h>
#include "SceneObject.hpp"
#include "Landscape.hpp"
#include "Plane.hpp"
#include "Character.hpp"
#include "Camera.hpp"
#include "Snow.hpp"
......@@ -31,10 +31,16 @@ class GameManager : public SceneObject
virtual void privateUpdate();
private:
std::shared_ptr<Landscape> ls1_;
std::shared_ptr<Landscape> ls2_;
std::shared_ptr<Landscape> ls3_;
std::shared_ptr<Landscape> ls4_;
std::shared_ptr<Plane> ls1_;
std::shared_ptr<Plane> ls2_;
std::shared_ptr<Plane> ls3_;
std::shared_ptr<Plane> ls4_;
std::shared_ptr<Plane> sbw_;
std::shared_ptr<Plane> sbn_;
std::shared_ptr<Plane> sbe_;
std::shared_ptr<Plane> sbs_;
std::shared_ptr<Plane> sbu_;
std::shared_ptr<Plane> sbd_;
std::shared_ptr<Character> character_;
std::shared_ptr<Camera> cam_;
std::shared_ptr<Snow> snow_;
......
......@@ -18,11 +18,12 @@
#define POS_ARRAY_SIZE 4 * (3 + 2)
#define IND_ARRAY_SIZE 4
class Landscape : public SceneObject
class Plane : public SceneObject
{
public:
Landscape(glm::vec3 trans);
~Landscape();
Plane(glm::vec3 trans, std::string texturePath, glm::vec3 rotationAxis = glm::vec3(0.0f, 0.0f, 0.0f),
float rotationAngle = 0.0f, glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f), bool isFixed = false, bool isTilted = false);
~Plane();
protected:
virtual void privateInit();
......@@ -80,7 +81,8 @@ 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/road.jpg");
Texture texture; // = Texture("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/road.jpg");
unsigned int textureSlot = 0;
bool fixed;
};
......@@ -6,5 +6,5 @@ namespace proj {
const float PoV = 60.0f;
const float aspectRatio = float(width) / float(height);
const float nearClip = 1.0f;
const float farClip = 3000.0f;
const float farClip = 15000.0f;
}
......@@ -9,7 +9,7 @@
Camera::Camera()
{
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));
auto rotation = glm::rotate(glm::mat4(1.0f), glm::radians(0.0f), glm::vec3(0.0f,0.0f,1.0f));
matrix_ = translation * rotation;
}
......
......@@ -23,15 +23,39 @@ void GameManager::privateInit()
// Adding the camera to the scene
cam_.reset(new Camera());
ls1_.reset(new Landscape(glm::vec3(0.0f, -50.0f, 0.0f)));
auto landscapeTexturePath = "C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/road.jpg";
ls1_.reset(new Plane(glm::vec3(0.0f, -50.0f, 0.0f), landscapeTexturePath));
this->addSubObject(ls1_);
ls2_.reset(new Landscape(glm::vec3(200.0f, -50.0f, 0.0f)));
ls2_.reset(new Plane(glm::vec3(200.0f, -50.0f, 0.0f), landscapeTexturePath));
this->addSubObject(ls2_);
ls3_.reset(new Landscape(glm::vec3(400.0f, -50.0f, 0.0f)));
ls3_.reset(new Plane(glm::vec3(400.0f, -50.0f, 0.0f), landscapeTexturePath));
this->addSubObject(ls3_);
ls4_.reset(new Landscape(glm::vec3(600.0f, -50.0f, 0.0f)));
ls4_.reset(new Plane(glm::vec3(600.0f, -50.0f, 0.0f),landscapeTexturePath));
this->addSubObject(ls4_);
float skyboxSize = 10000.0f;
std::string skyboxTexturePathPrefix = "C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_";
sbw_.reset(new Plane(glm::vec3(-skyboxSize / 2, 0, 0.0f), skyboxTexturePathPrefix + "west.bmp", glm::vec3(0.0f, 1.0f, 0.0f),
90.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbw_);
sbn_.reset(new Plane(glm::vec3(0.0f, 0.0f, -skyboxSize / 2), skyboxTexturePathPrefix + "north.bmp", glm::vec3(0.0f, 0.0f, 0.0f),
0.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbn_);
sbe_.reset(new Plane(glm::vec3(skyboxSize / 2, 0.0f, 0.0f), skyboxTexturePathPrefix + "east.bmp", glm::vec3(0.0f, 1.0f, 0.0f),
270.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbe_);
sbs_.reset(new Plane(glm::vec3(0.0f, 0.0f, skyboxSize / 2),skyboxTexturePathPrefix + "south.bmp", glm::vec3(0.0f, 1.0f, 0.0f),
180.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbs_);
sbu_.reset(new Plane(glm::vec3(0.0f, skyboxSize / 2, 0.0f), skyboxTexturePathPrefix + "up.bmp", glm::vec3(1.0f, 0.0f, 0.0f),
90.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbu_);
sbd_.reset(new Plane(glm::vec3(0.0f, -skyboxSize / 2, 0.0f), skyboxTexturePathPrefix + "down.bmp", glm::vec3(0.0f, 0.0f, 0.0f),
0.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, false));
this->addSubObject(sbd_);
character_.reset(new Character());
this->addSubObject(character_);
......
#include "../include/Landscape.hpp"
#include "../include/Plane.hpp"
#include "../../glm-master/glm/glm.hpp"
#include "../../glm-master/glm/gtc/type_ptr.hpp"
#include "../include/Projection.h"
Landscape::Landscape(glm::vec3 trans)
Plane::Plane(glm::vec3 trans, std::string texturePath, glm::vec3 rotationAxis, float rotationAngle, glm::vec3 scale, bool isFixed, bool isTilted)
: texture(Texture(texturePath)), fixed(isFixed)
{
matrix_ = glm::translate(matrix_, trans);
auto translation = glm::translate(glm::mat4(1.0f), trans);
auto rotation = glm::mat4(1.0);
if (rotationAngle != 0.0f) {
rotation *= glm::rotate(glm::mat4(1.0f), glm::radians(rotationAngle), rotationAxis);
}
if (isTilted) {
// rotation *= glm::rotate(glm::mat4(1.0f), glm::radians(-30.0f), glm::vec3(0.0f, 0.0f, 1.0f));
rotation *= glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
}
auto scaling = glm::scale(glm::mat4(1.0f), scale);
matrix_ = translation * rotation * scaling;
}
Landscape::~Landscape()
Plane::~Plane()
{
}
void Landscape::privateInit()
void Plane::privateInit()
{
/* VERTEX BUFFER */
// Is set up in initialization of object attribute
......@@ -46,7 +61,7 @@ void Landscape::privateInit()
shader.Unbind();
}
void Landscape::privateRender()
void Plane::privateRender()
{
shader.Bind();
vao.Bind();
......@@ -124,10 +139,13 @@ void Landscape::privateRender()
}
void Landscape::privateUpdate()
void Plane::privateUpdate()
{
if (fixed)
return;
if (matrix_[3].x < -400) {
matrix_ = glm::translate(matrix_, glm::vec3(800.0f, 0.0f, 0.0f));
matrix_ = glm::translate(matrix_, glm::vec3(798.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