Browse Source

started graphics rework

testing
= 3 years ago
parent
commit
670456d034

include/camera.h → include/graphics/camera.h View File

@@ -35,11 +35,10 @@ public:
void setPosition(const glm::vec3& position);
glm::vec3 getPosition();

void setAspectRatio(const float& aspect);
//id setAngleVector(const glm::vec3& angleVector);
glm::vec3 getAngleVector();

void setWindow(Window* window);

void move(const glm::vec3& offset);
void moveRelative(const glm::vec3& offset);
void rotate(const float& x, const float& y);
@@ -55,8 +54,9 @@ private:
float yawDelta;
float moveDampening;
float tiltDampening;
Window* linkedWindow;
glm::mat4 mAngleMatrix;
float mAspectRatio;
float mFOV;
};

}

+ 4
- 20
include/graphics/drawable.h View File

@@ -1,19 +1,5 @@
/*
* =====================================================================================
*
* Filename: drawable.h
*
* Description: Drawable object
*
* Version: 1.0
* Created: 05/20/2014 11:02:19 PM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
* Drawable class
*/

#include "../camera.h"
@@ -24,18 +10,16 @@ namespace vtk {

//Forward declarations
class Shader;
class RenderTask;

///\brief Abstract base class that can
/// be drawn to a camera

class Drawable {
public:
///\brief Destructor
virtual ~Drawable();

///\brief Draw something from the viewpoint of a camera
///\param camera Camera to draw with
virtual void draw(Camera& camera);
//Draw (called from rednertask)
virtual void draw(RenderTask& task);
protected:
std::shared_ptr<Shader> linkedShader;
};

+ 26
- 0
include/graphics/rendertask.h View File

@@ -0,0 +1,26 @@
/*
* Describes a render task, drawable + camera + target
*/

#pragma once

namespace vtk {

//forward declaration
class Drawable;
class Camera;
class RenderTarget;

class RenderTask {
public:
RenderTask(Drawable& drawable, Camera& camera, RenderTarget& renderTarget);

void draw();
protected:
Drawable& mDrawable;
Camera& mCamera;
RenderTarget& mRenderTarget;
};

}

+ 1
- 1
src/game.cpp View File

@@ -18,7 +18,7 @@

#include "game.h"
#include "loadShader.h"
#include "camera.h"
#include "graphics/camera.h"
#include "scene.h"

//SPAGHETTI INCLUDES

src/camera.cpp → src/graphics/camera.cpp View File

@@ -15,7 +15,7 @@
*
* =====================================================================================
*/
#include "camera.h"
#include "graphics/camera.h"
#include "window.h"

#include <glm/gtc/matrix_transform.hpp>
@@ -32,6 +32,8 @@ Camera::Camera() {
yawDelta = 0.0f;
moveDampening = 0.0f;
tiltDampening = 0.0f;
mAspectRatio = 1.0f;
mFOV = 1.5608f;
}

glm::mat4 Camera::getViewMatrix() {
@@ -45,7 +47,7 @@ glm::mat4 Camera::getViewMatrix() {
}

glm::mat4 Camera::getProjectionMatrix() {
return glm::infinitePerspective(1.5708f, linkedWindow->getAspect(), 1.0f);
return glm::infinitePerspective(mFOV, mAspectRatio, 0.1f);
}

glm::mat4 Camera::getAngleMatrix() {
@@ -61,7 +63,6 @@ void Camera::update(const float& dTime) {
pitchDelta *= dTime * tiltDampening;
yawDelta *= dTime * tiltDampening;
positionDelta *= dTime * moveDampening;

{
//reverse project for direction vector
glm::vec4 rayClip(0.0f, 0.0f, -1.0f, 1.0f);
@@ -80,12 +81,12 @@ glm::vec3 Camera::getPosition() {
return position;
}

glm::vec3 Camera::getAngleVector() {
return direction;
void Camera::setAspectRatio(const float& aspect) {
mAspectRatio = aspect;
}

void Camera::setWindow(Window* window) {
linkedWindow = window;
glm::vec3 Camera::getAngleVector() {
return direction;
}

void Camera::move(const glm::vec3& offset) {

+ 1
- 1
src/scenes/testscene.cpp View File

@@ -70,7 +70,7 @@ void TestScene::init() {
glUseProgram(shaders);

camera.setPosition(glm::vec3(0.0f, 5.0f, 5.0f));
camera.setWindow(&linkedGame->window);
camera.setAspectRatio(linkedGame->window.getAspect());

viewMatUni = glGetUniformLocation(shaders, "view");
projMatUni = glGetUniformLocation(shaders, "proj");

+ 1
- 1
src/scenes/testscene.h View File

@@ -20,7 +20,7 @@
#pragma once

#include "scene.h"
#include "camera.h"
#include "graphics/camera.h"
#include "inputhandler.h"
#include "world.h"
#include "graphics/skybox.h"

+ 0
- 15
src/terraingen.cpp View File

@@ -66,21 +66,6 @@ void TerrainGen::generateChunk(Chunk* chunk) {
}
}
}

//grass on top
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
for (int k = 0; k < 16; k++) {
if (chunk->getVoxelType(i,j,k) != 0) {
//if (chunk->getVoxelType(i,j+1,k) == 0) {
// chunk->setVoxelType(i,j,k,2);
//}
}
}
}
}


}

}

Loading…
Cancel
Save