Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ cmake-build-debug-coverage
build
extern
imgui.ini
bd
3 changes: 0 additions & 3 deletions core/audio/Bindings.cpp

This file was deleted.

13 changes: 12 additions & 1 deletion core/include/Cube.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const uint32_t WinWidth = 800;
const uint32_t WinHeight = 800;

const uint8_t verticesSize = 192;
const uint16_t verticesSize = 264;
const uint8_t indicesSize = 36;

class Cube {
Expand All @@ -29,6 +29,7 @@ class Cube {
void setScaleUniform();
void setTexUinform();
void setMatUniform();
void setColorUniform();

void scale(float s);
void rotate(float r);
Expand All @@ -37,6 +38,8 @@ class Cube {

void activateShader();
void draw();
void toggleView();
void setPrespective(bool view);

private:
Shader shader;
Expand All @@ -49,6 +52,8 @@ class Cube {
VBO vbo;
EBO ebo;

bool isPerspective;

// Model Matrix
glm::mat4 model;

Expand All @@ -58,6 +63,12 @@ class Cube {
// Projection Matrix
glm::mat4 proj;

// Light Color
glm::vec4 lightColor;

// Light Position
glm::vec3 lightPosition;

GLuint scaleUniID;

float rotation = 0.0f;
Expand Down
4 changes: 4 additions & 0 deletions core/include/Cubes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ class Cubes {
void activateShader();
void clean();

void setPerspective(bool view);
void setPerVal(bool view);

private:
LinkedList <Cube*> *list;
bool isPerspective;
};

#endif // VOXELOOP_CUBES_HPP
48 changes: 0 additions & 48 deletions core/include/LightSource.hpp

This file was deleted.

2 changes: 2 additions & 0 deletions core/include/Voxeloop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Audio.hpp"
#include "Common.hpp"
#include "Cubes.hpp"
// #include "LightSource.hpp"
#include "LinkedList.hpp"
#include "WindowManager.hpp"

Expand All @@ -27,6 +28,7 @@ class Voxeloop {

Cubes *m_cubes;
Audio *m_audio;
// LightSource *m_lightsource;

float m_mvmt;
float m_scale;
Expand Down
24 changes: 23 additions & 1 deletion core/shaders/default.frag
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,31 @@ out vec4 FragColor;

in vec3 color;
in vec2 texCoord;
in vec3 normal;
in vec3 currentPos;

uniform sampler2D tex0;
uniform vec4 lightColor;
uniform vec3 lightPos;

void main() {
FragColor = texture(tex0, texCoord);
// Ambient lighting
float ambient = 0.2f;

// Diffused lighting
vec3 normalizedNormal = normalize(normal);
vec3 lightDirection = normalize(lightPos - currentPos);
float diffuse = max(dot(normal, lightDirection), 0.0f);

// Specular lighting
float specularLight = 0.70f;
vec3 camPos = vec3(0.3f, 0.3f, -2.0f);
vec3 viewDirection = normalize(camPos - currentPos);
vec3 reflectionDirection = reflect(-lightDirection, normal);
float specAmount = pow(max(dot(viewDirection, reflectionDirection), 0.0f), 8);
float specular = specAmount * specularLight;

vec4 light = lightColor * (ambient + diffuse + specular);

FragColor = texture(tex0, texCoord) * light;
}
11 changes: 8 additions & 3 deletions core/shaders/default.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTex;
layout (location = 3) in vec3 aNormal;

out vec3 color;
out vec2 texCoord;
out vec3 normal;

out vec3 currentPos;

uniform float scale;

uniform mat4 model;
uniform mat4 view;
uniform mat4 proj;


void main() {
gl_Position = proj * view * model * vec4(aPos.x * scale, aPos.y * scale, aPos.z * scale, 1.0);
currentPos = vec3(model * vec4(aPos.x * scale, aPos.y * scale, aPos.z * scale, 1.0));
gl_Position = proj * view * vec4(currentPos, 1.0);
color = aColor;
texCoord = aTex;
texCoord = aTex;
normal = aNormal;
}
102 changes: 59 additions & 43 deletions core/src/Cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@

Cube::Cube()
: shader{"../core/shaders/default.vert", "../core/shaders/default.frag"},
_vertices{
_vertices{
// clang-format off
// POSITIONS / COLORS / TEXTURE COORDS
// POSITIONS | COLORS | TEX COORDS | NORMALS
// Face 1
-0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Upper left corner - f
0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Upper right corner - f
0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Lower right corner - f
-0.125f,-0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, // Lower left corner - f
-0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, // Upper left corner - f
0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, // Upper right corner - f
0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f, // Lower right corner - f
-0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, // Lower left corner - f

// Face 2
-0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Upper left corner - b
0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Upper right corner - b
0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, // Lower right corner - b
-0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Lower left corner - b
-0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, // Upper left corner - b
0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, // Upper right corner - b
0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, // Lower right corner - b
-0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // Lower left corner - b

// Face 3
-0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Upper left corner - f
-0.125f,-0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Lower left corner - f
-0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, // Lower left corner - b
-0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Upper left corner - b
-0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, // Upper left corner - f
-0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, // Lower left corner - f
-0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, // Lower left corner - b
-0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, // Upper left corner - b

// Face 4
0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Upper right corner - f
0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, // Lower right corner - f
0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Lower right corner - b
0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Upper right corner - b
0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // Upper right corner - f
0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, // Lower right corner - f
0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // Lower right corner - b
0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, // Upper right corner - b

// Face 5
-0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Upper left corner - f
0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Upper right corner - f
0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Upper right corner - b
-0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, // Upper left corner - b
-0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Upper left corner - f
0.125f, 0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Upper right corner - f
0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, // Upper right corner - b
-0.125f, 0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // Upper left corner - b


// Face 6
0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Lower right corner - f
-0.125f,-0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, // Lower left corner - f
-0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Lower left corner - b
0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f // Lower right corner - b
0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, // Lower right corner - f
-0.125f, -0.125f, 0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, // Lower left corner - f
-0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 0.0f, // Lower left corner - b
0.125f, -0.125f, -0.125f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f // Lower right corner - b

// clang-format on
},
Expand All @@ -53,18 +53,7 @@ Cube::Cube()
// face 2
4, 5, 6,
6, 7, 4,
// face 3
// 0, 4, 7,
// 7, 3, 0,
// // face 4
// 1, 5, 6,
// 6, 2, 1,
// // face 5
// 0, 4, 5,
// 5, 1, 0,
// // face 6
// 3, 7, 6,
// 6, 2, 3

//face 3
8, 9, 10,
10, 11, 8,
Expand All @@ -89,18 +78,25 @@ Cube::Cube()
vbo.setup(_vertices, sizeof(_vertices));
ebo.setup(_indices, sizeof(_indices));

vao.linkAttrib(vbo, 0, 3, GL_FLOAT, 8 * sizeof(float), (void *)0);
vao.linkAttrib(vbo, 1, 3, GL_FLOAT, 8 * sizeof(float),
vao.linkAttrib(vbo, 0, 3, GL_FLOAT, 11 * sizeof(float), (void *)0);
vao.linkAttrib(vbo, 1, 3, GL_FLOAT, 11 * sizeof(float),
(void *)(3 * sizeof(float)));
vao.linkAttrib(vbo, 2, 2, GL_FLOAT, 8 * sizeof(float),
vao.linkAttrib(vbo, 2, 2, GL_FLOAT, 11 * sizeof(float),
(void *)(6 * sizeof(float)));
vao.linkAttrib(vbo, 3, 3, GL_FLOAT, 11 * sizeof(float),
(void *)(8 * sizeof(float)));

vao.unbind();
vbo.unbind();
ebo.unbind();

xpos = random();
ypos = random();

lightColor = glm::vec4(0.0f, 0.28f, 0.49f, 1.0f);
lightPosition = glm::vec3(0.0f, 0.0f, -1.0f);

isPerspective = true;
}

Cube::~Cube() {
Expand Down Expand Up @@ -129,6 +125,8 @@ void Cube::setMatUniform() {
// Uniform for projection matrix
int projLoc = glGetUniformLocation(shader.ID, "proj");
glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(proj));


}

void Cube::scale(float s) { glUniform1f(scaleUniID, s); }
Expand All @@ -137,6 +135,18 @@ void Cube::rotate(float r) { rotation += r; }

void Cube::activateShader() { shader.activate(); }

void Cube::toggleView() { isPerspective = !isPerspective; }

void Cube::setColorUniform() {
int colorLoc = glGetUniformLocation(shader.ID, "lightColor");
glUniform4f(colorLoc, lightColor.x, lightColor.y, lightColor.z, lightColor.w);

int lightPosLoc = glGetUniformLocation(shader.ID, "lightPos");
glUniform3f(lightPosLoc, lightPosition.x, lightPosition.y, lightPosition.z);
}

void Cube::setPrespective(bool view) {isPerspective = view;}

void Cube::draw() {
// Model Matrix
model = glm::mat4(1.0f);
Expand All @@ -148,14 +158,20 @@ void Cube::draw() {
proj = glm::mat4(1.0f);

model =
glm::rotate(model, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
glm::rotate(model, glm::radians(0.0f), glm::vec3(0.0f, 1.0f, 0.0f));

view = glm::translate(view, glm::vec3(xpos, ypos, -2.0f + zmove));

proj = glm::perspective(glm::radians(45.0f), (float)(WinWidth / WinHeight),
if (isPerspective) {
proj = glm::perspective(glm::radians(30.0f), (float)(WinWidth / WinHeight),
0.1f, 25.0f);
} else {
proj = glm::rotate(glm::ortho(-1.0f, 1.0f, 1.0f, -1.0f, -1000.0f, 1000.0f),
glm::radians(225.0f), glm::vec3(-1.0f, 0.0f, 0.0f));
}

setMatUniform();
setColorUniform();
texture.bind();
vao.bind();

Expand Down
Loading