added project structure
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
#include "glm/gtc/matrix_transform.hpp"
|
||||
|
||||
class Camera {
|
||||
protected:
|
||||
glm::vec3 position;
|
||||
glm::mat4 projection;
|
||||
glm::mat4 view;
|
||||
glm::mat4 viewProj;
|
||||
|
||||
public:
|
||||
Camera(float fov, float width, float height) {
|
||||
projection = glm::perspective(fov/2.0f, width/height, 0.1f, 1000.f);
|
||||
view = glm::mat4(1.0f);
|
||||
position = glm::vec3(0.0f);
|
||||
update();
|
||||
}
|
||||
|
||||
glm::mat4 getViewProj() {
|
||||
return viewProj;
|
||||
}
|
||||
|
||||
virtual void update() {
|
||||
viewProj = projection * view;
|
||||
}
|
||||
|
||||
virtual void translate(glm::vec3 v) {
|
||||
position += v;
|
||||
view = glm::translate(view, v*-1.0f);
|
||||
}
|
||||
};
|
||||
@@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Camera.hpp"
|
||||
|
||||
class FPSCamera : public Camera {
|
||||
protected:
|
||||
float yaw; // rotation y-axis
|
||||
float pitch; // rotating x-axis
|
||||
glm::vec3 lookAt;
|
||||
const float mouseSensitivity = 0.3f;
|
||||
glm::vec3 up;
|
||||
|
||||
public:
|
||||
FPSCamera(float fov, float width, float height) : Camera(fov, width, height) {
|
||||
up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
yaw = -90.0f;
|
||||
pitch = 0.0f;
|
||||
onMouseMoved(0.0f, 0.0f);
|
||||
}
|
||||
|
||||
void onMouseMoved(float xRel, float yRel) {
|
||||
yaw += xRel * mouseSensitivity;
|
||||
pitch -= yRel * mouseSensitivity;
|
||||
if (pitch > 89.0f) pitch = 89.0f;
|
||||
else if (pitch < -89.0f) pitch = -89.0f;
|
||||
|
||||
glm::vec3 front;
|
||||
front.x = cos(glm::radians(pitch)) * cos(glm::radians(yaw));
|
||||
front.y = sin(glm::radians(pitch));
|
||||
front.z = cos(glm::radians(pitch)) * sin(glm::radians(yaw));
|
||||
lookAt = glm::normalize(front);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void update() override {
|
||||
view = glm::lookAt(position, position+lookAt, up);
|
||||
viewProj = projection * view;
|
||||
}
|
||||
|
||||
void moveFront(float amount) {
|
||||
translate(lookAt * amount);
|
||||
update();
|
||||
}
|
||||
|
||||
void moveSideways(float amount) {
|
||||
translate(glm::normalize(glm::cross(lookAt, up)) * amount);
|
||||
update();
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "defines.hpp"
|
||||
|
||||
struct IndexBuffer {
|
||||
IndexBuffer(void* data, uint32 numIndices, uint8 elementSize) {
|
||||
glGenBuffers(1, &bufferId);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*elementSize, data, GL_STATIC_DRAW);
|
||||
|
||||
// POSITION
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex,x));
|
||||
// COLOR
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex,r));
|
||||
|
||||
glBindVertexArray(0);
|
||||
};
|
||||
virtual ~IndexBuffer() {
|
||||
glDeleteBuffers(1, &bufferId);
|
||||
}
|
||||
|
||||
void bind() {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId);
|
||||
}
|
||||
void unbind() {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
GLuint bufferId;
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "defines.hpp"
|
||||
|
||||
struct VertexBuffer {
|
||||
VertexBuffer(void* data, uint32 numVertices) {
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
|
||||
glGenBuffers(1, &bufferId);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, bufferId);
|
||||
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Vertex), data, GL_STATIC_DRAW);
|
||||
|
||||
// POSITION
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex,x));
|
||||
// TEXTURE COORDINATES
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex,u));
|
||||
// COLOR
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex,r));
|
||||
|
||||
glBindVertexArray(0);
|
||||
};
|
||||
virtual ~VertexBuffer() {
|
||||
glDeleteBuffers(1, &bufferId);
|
||||
}
|
||||
|
||||
void bind() {
|
||||
glBindVertexArray(vao);
|
||||
}
|
||||
void unbind() {
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
private:
|
||||
GLuint bufferId;
|
||||
GLuint vao;
|
||||
};
|
||||
21
include/camera/Camera.hpp
Normal file
21
include/camera/Camera.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
#include "glm/gtc/matrix_transform.hpp"
|
||||
|
||||
class Camera {
|
||||
protected:
|
||||
glm::vec3 position;
|
||||
glm::mat4 projection;
|
||||
glm::mat4 view;
|
||||
glm::mat4 viewProj;
|
||||
|
||||
public:
|
||||
Camera(float fov, float width, float height);
|
||||
virtual ~Camera() = default;
|
||||
|
||||
glm::mat4 getViewProj();
|
||||
|
||||
virtual void update();
|
||||
virtual void translate(glm::vec3 v);
|
||||
};
|
||||
20
include/camera/FPS_Camera.hpp
Normal file
20
include/camera/FPS_Camera.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Camera.hpp"
|
||||
|
||||
class FPSCamera : public Camera {
|
||||
protected:
|
||||
float yaw; // rotation y-axis
|
||||
float pitch; // rotating x-axis
|
||||
glm::vec3 lookAt;
|
||||
const float mouseSensitivity = 0.3f;
|
||||
glm::vec3 up;
|
||||
|
||||
public:
|
||||
FPSCamera(float fov, float width, float height);
|
||||
|
||||
void onMouseMoved(float xRel, float yRel);
|
||||
void update() override;
|
||||
void moveFront(float amount);
|
||||
void moveSideways(float amount);
|
||||
};
|
||||
15
include/glPipeline/IndexBuffer.hpp
Normal file
15
include/glPipeline/IndexBuffer.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
||||
struct IndexBuffer {
|
||||
IndexBuffer(void* data, uint32 numIndices, uint8 elementSize);
|
||||
virtual ~IndexBuffer();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
private:
|
||||
GLuint bufferId;
|
||||
};
|
||||
16
include/glPipeline/VertexBuffer.hpp
Normal file
16
include/glPipeline/VertexBuffer.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
||||
struct VertexBuffer {
|
||||
VertexBuffer(void* data, uint32 numVertices);
|
||||
virtual ~VertexBuffer();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
private:
|
||||
GLuint bufferId;
|
||||
GLuint vao;
|
||||
};
|
||||
Reference in New Issue
Block a user