Skip to content

Commit

Permalink
Added Tangram initial form and floor movement!
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoEPRodrigues committed Nov 16, 2017
1 parent 3dbe695 commit b4a70d4
Show file tree
Hide file tree
Showing 23 changed files with 456 additions and 119 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ set(ENGINE_SOURCE_FILES
src/Engine/Shapes/MeshLoader.cpp src/Engine/Shapes/MeshLoader.h
src/Engine/Actor.cpp src/Engine/Actor.h
src/Engine/SceneManagement/SceneGraph.cpp src/Engine/SceneManagement/SceneGraph.h
src/Engine/Utilities/Manager.h src/Engine/Utilities/Managers.h)
src/Engine/Utilities/Manager.h src/Engine/Utilities/Managers.h src/Engine/Utilities/Simulation.cpp src/Engine/Utilities/Simulation.h)

set(EXECUTABLE_SOURCE_FILES
src/Executable/main.cpp
# src/Executable/Tangram/Tangram.cpp src/Executable/Tangram/Tangram.h
# src/Executable/Tangram3D/Tangram3D.cpp src/Executable/Tangram3D/Tangram3D.h
# src/Executable/Quaternion/Quaternion.cpp src/Executable/Quaternion/Quaternion.h
src/Executable/LoaderAndScene/LoaderAndScene.cpp src/Executable/LoaderAndScene/LoaderAndScene.h
)
src/Executable/LoaderAndScene/ColoredActor.cpp src/Executable/LoaderAndScene/ColoredActor.h src/Executable/LoaderAndScene/MoveController.cpp src/Executable/LoaderAndScene/MoveController.h)

set(TESTS_SOURCE_FILES src/Tests/catch.hpp src/Tests/tests.cpp src/Tests/VectorTests.h src/Tests/MatrixTests.h)

Expand Down Expand Up @@ -142,7 +142,7 @@ if (WIN32) # WINDOWS post build
)
endif ()

add_custom_command(TARGET ThreeEngine POST_BUILD
add_custom_command(TARGET ThreeEngineExecutable POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo Copying Config files
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/config ${EXECUTABLE_OUTPUT_PATH}/config/
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/shaders ${EXECUTABLE_OUTPUT_PATH}/shaders/
Expand Down
36 changes: 18 additions & 18 deletions assets/Cube-vtn.obj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Blender v2.79 (sub 0) OBJ File: 'Cube.blend'
# www.blender.org
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
v 2.000000 0.000000 -2.000000
v 2.000000 0.000000 0.000000
v 0.000000 0.000000 -0.000000
v 0.000000 0.000000 -2.000000
v 2.000000 2.000000 -2.000000
v 1.999999 2.000000 0.000000
v -0.000000 2.000000 -0.000000
v 0.000000 2.000000 -2.000000
vt 0.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
Expand All @@ -20,31 +20,31 @@ vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 1.0000 -0.0000 0.0000
vn 0.0000 -0.0000 1.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
s off
f 2/1/1 4/2/1 1/3/1
f 1/1/1 3/2/1 4/3/1
f 8/4/2 6/5/2 5/6/2
f 5/7/3 2/8/3 1/3/3
f 5/7/3 2/8/3 1/1/3
f 6/9/4 3/10/4 2/11/4
f 3/12/5 8/13/5 4/2/5
f 7/12/5 4/3/5 3/13/5
f 1/14/6 8/15/6 5/6/6
f 2/1/1 3/16/1 4/2/1
f 1/1/1 2/16/1 3/2/1
f 8/4/2 7/17/2 6/5/2
f 5/7/3 6/18/3 2/8/3
f 6/9/4 7/17/4 3/10/4
f 3/12/5 7/19/5 8/13/5
f 7/12/5 8/19/5 4/3/5
f 1/14/6 4/20/6 8/15/6
50 changes: 50 additions & 0 deletions assets/Parallelogram-vtn.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Blender v2.79 (sub 0) OBJ File: 'Parallelogram.blend'
# www.blender.org
o Cube
v 1.989430 0.000000 0.005215
v -0.010458 0.000000 -0.015868
v 0.010625 0.000000 -2.015757
v 2.010514 0.000000 -1.994673
v 2.989375 1.000000 0.015758
v 0.989486 1.000000 -0.005327
v 1.010570 1.000000 -2.005216
v 3.010458 1.000000 -1.984132
vt 0.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 1.000000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn -0.0105 0.0000 0.9999
vn -0.7071 0.7071 -0.0075
vn 0.0105 -0.0000 -0.9999
vn 0.7071 -0.7071 0.0075
s off
f 1/1/1 3/2/1 4/3/1
f 8/4/2 6/5/2 5/6/2
f 1/1/3 6/7/3 2/8/3
f 6/9/4 3/10/4 2/11/4
f 7/12/5 4/3/5 3/13/5
f 1/14/6 8/15/6 5/6/6
f 1/1/1 2/16/1 3/2/1
f 8/4/2 7/17/2 6/5/2
f 1/1/3 5/18/3 6/7/3
f 6/9/4 7/17/4 3/10/4
f 7/12/5 8/19/5 4/3/5
f 1/14/6 4/20/6 8/15/6
20 changes: 20 additions & 0 deletions assets/Pyramid-vtn.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Blender v2.79 (sub 0) OBJ File: 'Pyramid.blend'
# www.blender.org
o Piramid_Cube
v 0.017666 0.000000 -2.005773
v 1.994019 0.000000 0.017597
v -0.005843 0.000000 -0.005912
v -0.005842 2.000000 -0.005912
vt 0.000000 1.000000
vt 1.000000 1.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vn -0.0118 -0.0000 0.9999
vn 0.0000 -1.0000 0.0000
vn -0.9999 0.0000 -0.0118
vn 0.5841 0.5774 -0.5705
s off
f 3/1/1 2/2/1 4/3/1
f 3/1/2 1/4/2 2/2/2
f 3/1/3 4/3/3 1/4/3
f 2/2/4 1/4/4 4/3/4
5 changes: 3 additions & 2 deletions shaders/Color3D/fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#version 330 core

in vec4 ex_Color;
out vec4 out_Color;

uniform vec4 ModelColor;

void main(void)
{
out_Color = ex_Color;
out_Color = ModelColor;
}
9 changes: 0 additions & 9 deletions shaders/Color3D/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

in vec4 in_Position;
in vec4 in_Color;
out vec4 ex_Color;

uniform mat4 ModelMatrix;
uniform vec4 ModelColor = vec4(0.5, 0.5, 0.5, 1.0);

uniform SharedMatrices {
mat4 ViewMatrix;
Expand All @@ -15,11 +13,4 @@ uniform SharedMatrices {
void main(void)
{
gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * in_Position;

float zMixer = clamp((ModelMatrix * in_Position).z, 0.3, 1.0);
float xMixer = clamp((ModelMatrix * in_Position).x, 0.3, 0.5);
ex_Color = vec4(ModelColor.x * zMixer + xMixer,
ModelColor.y * zMixer + xMixer,
ModelColor.z * zMixer + xMixer,
ModelColor.w);
}
9 changes: 7 additions & 2 deletions src/Engine/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace ThreeEngine {

Actor::Actor()
: IDrawable(), isInitiated(false), transform(), mesh(nullptr),
shaderProgram(nullptr), parent(nullptr) { }
: IDrawable(), shaderProgram(nullptr), isInitiated(false),
transform(), mesh(nullptr), parent(nullptr) { }

Actor::~Actor() {
for (auto&& child : children) {
Expand Down Expand Up @@ -84,6 +84,11 @@ namespace ThreeEngine {
return parent->GetParentModelMatrix() * parent->GetModelMatrix();
}

void Actor::setShaderProgram(
const std::shared_ptr<ShaderProgram>& shaderProgram) {
Actor::shaderProgram = shaderProgram;
}

std::shared_ptr<ShaderProgram> Actor::GetShaderProgram() {
if (shaderProgram) {
return shaderProgram;
Expand Down
12 changes: 10 additions & 2 deletions src/Engine/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@
namespace ThreeEngine {
class Actor : public IDrawable {
private:

std::shared_ptr<ShaderProgram> shaderProgram;

protected:
bool isInitiated;

Matrix GetModelMatrix();

Matrix GetLocalModelMatrix();

Matrix GetParentModelMatrix();

std::shared_ptr<ShaderProgram> GetShaderProgram();

public:
struct Transform {
Vector translation{0};
Expand All @@ -34,8 +41,6 @@ namespace ThreeEngine {

std::shared_ptr<Mesh> mesh;

std::shared_ptr<ShaderProgram> shaderProgram;

Actor* parent;

std::vector<Actor*> children;
Expand All @@ -49,6 +54,9 @@ namespace ThreeEngine {
void Draw() override;

void SetParent(Actor* parent);

void setShaderProgram(
const std::shared_ptr<ShaderProgram>& shaderProgram);
};
} // namespace ThreeEngine

Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Camera/Perspective.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ThreeEngine {

class Perspective : public Matrix{
class Perspective : public Matrix {
public:
number angle, d;
Perspective(number FOVy, number aspect, number zNear, number zFar);
Expand Down
23 changes: 5 additions & 18 deletions src/Engine/Controllers/SphereCameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ThreeEngine {
SphereCameraController::SphereCameraController() :
engine(Engine::Instance()),
inPerspective(true),
useQuat(true), previousMouseLocation(),
previousMouseLocation(),
yawPitch(),
translation(Matrix::IdentityMatrix()),
rotation(Matrix::IdentityMatrix()),
Expand All @@ -38,10 +38,6 @@ namespace ThreeEngine {
inPerspective = true;
}
}
// Toggle between using Quaternions or Euler Angles for rotations
if (engine->input.Click('g')) {
useQuat = !useQuat;
}

// Check if mouse was clicked
if (engine->input[MouseKeys::LEFT] || engine->input[MouseKeys::RIGHT]) {
Expand All @@ -57,17 +53,8 @@ namespace ThreeEngine {
Quat::FromAngleAxis(-delta.Y,
Vector(1, 0, 0))).Normalize() * quat;

if (useQuat) {
camera->SetView(Matrix::TranslationMatrix(Vector(0, 0, -15)) *
quat.ToMatrix());
} else {

Matrix rotation = Matrix(Matrix3::RotationMatrix(Maths::Axis::Y,
-delta.X)) *
Matrix(Matrix3::RotationMatrix(Maths::Axis::X,
-delta.Y));
camera->SetView(*camera->GetView() * rotation);
}
camera->SetView(Matrix::TranslationMatrix(Vector(0, 0, -30)) *
quat.ToMatrix());
} else {
UnlockMouse();
}
Expand All @@ -84,10 +71,10 @@ namespace ThreeEngine {
// check if mouse is at window borders
bool mouseXUpdate =
(mouse.X <= 0) ||
(mouse.X >= (int) engine->config["window"]["x"]);
(mouse.X >= (int) engine->config["window"]["x"] - 1);
bool mouseYUpdate =
(mouse.Y <= 0) ||
(mouse.Y >= (int) engine->config["window"]["y"]);
(mouse.Y >= (int) engine->config["window"]["y"] - 1);

if (mouseXUpdate || mouseYUpdate) {
Vector2 newMouseLoc = mouse;
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Controllers/SphereCameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ThreeEngine {
private:
Engine* engine;

bool inPerspective, useQuat;
bool inPerspective;

Vector2 previousMouseLocation, yawPitch;

Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ namespace ThreeEngine {
void Engine::Display() {
++instance->FrameCount;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Time::Update();
instance->PreDraw();
for (auto& actor : instance->actors) {
actor->Draw();
Expand All @@ -197,7 +196,8 @@ namespace ThreeEngine {
}

void Engine::Idle() {
// TODO Insert Updates here
Time::Update();
instance->Update();
instance->input.Update();
glutPostRedisplay();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ namespace ThreeEngine {
*/
virtual void OnInit() { }

/**
* Called when before when no rendering is being done.
*/
virtual void Update() { }

/**
* Called when cleaning OpenGL. Any OpenGL related cleaning needs to be done here.
* This is called before deleting Actors
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Shapes/Cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace ThreeEngine {
Cube::~Cube() = default;

void Cube::ColorUpdate() {
glUniform4f(shaderProgram->GetUniformLocationId("ModelColor"), color[0],
glUniform4f(GetShaderProgram()->GetUniformLocationId("ModelColor"), color[0],
color[1], color[2],
color[3]);
}
Expand Down
20 changes: 20 additions & 0 deletions src/Engine/Utilities/Simulation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* File Simulation.cpp in project ThreeEngine
*
* Copyright (C) Ricardo Rodrigues 2017 - All Rights Reserved
*/
#include "Simulation.h"

namespace ThreeEngine {
SINGLETON_IMPLEMENTATION(Simulation)

void Simulation::Add(IUpdatable* updatable) {
updatables.push_back(std::unique_ptr<IUpdatable>(updatable));
}

void Simulation::Update() {
for (std::unique_ptr<IUpdatable>& updatable : updatables) {
updatable->Update(Time::Delta());
}
}
} /* namespace ThreeEngine */
Loading

0 comments on commit b4a70d4

Please sign in to comment.