Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

# Don't fail on empty include (not tracked by git)
- run: if ! [ -d include ]; then mkdir include; fi
- run: sudo apt update && sudo apt install -y libglfw3-dev libglm-dev libgl-dev
- run: sudo apt update && sudo apt install -y libglfw3-dev libglm-dev libgl-dev libtinyxml2-dev
- run: make
format:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,4 +45,4 @@ jobs:

# Don't fail on empty include (not tracked by git)
- run: if ! [ -d include ]; then mkdir include; fi
- run: cppcheck src -I include
- run: cppcheck src -I include -I /usr/include/tinyxml2
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ CPPFLAGS := -Iinclude -std=c++20 -Wall -Wextra -pedantic -Wshadow \
$(shell pkg-config --cflags glfw3) -DGLFW_INCLUDE_NONE \
$(shell pkg-config --cflags glm) \
$(shell pkg-config --cflags gl) \
$(shell pkg-config --cflags tinyxml2) \
-Ilib/include
LIBS := -lm \
$(shell pkg-config --libs glfw3) \
$(shell pkg-config --libs glm) \
$(shell pkg-config --libs gl)
$(shell pkg-config --libs glfw3) \
$(shell pkg-config --libs glm) \
$(shell pkg-config --libs gl) \
$(shell pkg-config --libs tinyxml2)

DEBUG_CPPFLAGS := -O0 -ggdb3
RELEASE_CPPFLAGS := -O2
Expand All @@ -50,7 +52,7 @@ LIB_SOURCES = $(shell find "lib" -name '*.c' -type f)
LIB_OBJECTS = $(patsubst lib/%.c, $(OBJDIR)/%.o, $(LIB_SOURCES))
HEADERS = $(shell find "include" -name '*.hpp' -type f)
DEPENDS = $(patsubst src/%.cpp, $(DEPDIR)/%.d, $(SOURCES))
REPORTS = $(patsubst reports/%.tex, %.pdf, $(shell find reports -name '*.tex' -type f))
REPORTS = $(patsubst reports/%.tex, $(BUILDDIR)/%.pdf, $(shell find reports -name '*.tex' -type f))

ifeq ($(DEBUG), 1)
CPPFLAGS += $(DEBUG_CPPFLAGS)
Expand Down
34 changes: 34 additions & 0 deletions include/engine/Entity.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// Copyright 2025 Ana Oliveira, Humberto Gomes, Mariana Rocha, Sara Lopes
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.

#pragma once

#include <glm/vec4.hpp>
#include <memory>

#include "engine/Model.hpp"
#include "engine/RenderPipeline.hpp"

namespace engine {
class Entity {
protected:
std::shared_ptr<Model> model;
glm::vec4 color;
// TODO - Phase 2 – Add Geometric Transforms

public:
Entity(std::shared_ptr<Model> _model, const glm::vec4 &color);
void draw(const RenderPipeline &pipeline) const;
};
}
69 changes: 69 additions & 0 deletions include/engine/Scene.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// Copyright 2025 Ana Oliveira, Humberto Gomes, Mariana Rocha, Sara Lopes
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.

#pragma once

#include <filesystem>
#include <memory>
#include <string>
#include <tinyxml2.h>
#include <unordered_map>
#include <vector>

#include "engine/Camera.hpp"
#include "engine/Entity.hpp"
#include "engine/RenderPipeline.hpp"

namespace engine {

class Scene {
private:
int windowWidth, windowHeight;
std::string windowTitle;
Camera camera;

// TODO - Phase 2 - add support for groups (linear scene is going to make it harder for phase 3)
std::vector<std::unique_ptr<Entity>> entities;

public:
Scene(const std::string &file);
Scene(const Scene &scene) = delete;
Scene(Scene &&scene) = delete;

int getWindowWidth() const;
int getWindowHeight() const;
Camera &getCamera();

void draw(const RenderPipeline &pipeline) const;
void setWindowSize(int width, int height);

private:
const tinyxml2::XMLElement *getOnlyOneNodeFromXML(const tinyxml2::XMLNode *parent,
const std::string &name);
glm::vec3 getVectorFromXML(const tinyxml2::XMLElement *element);

void getWindowFromXML(const tinyxml2::XMLElement *worldElement);
void getCameraFromXML(const tinyxml2::XMLElement *worldElement);

void getEntitiesFromWorldXML(
const std::filesystem::path &sceneDirectory,
std::unordered_map<std::string, std::shared_ptr<Model>> &loadedModels,
const tinyxml2::XMLElement *worldElement);
void getEntitiesFromGroupXML(
const std::filesystem::path &sceneDirectory,
std::unordered_map<std::string, std::shared_ptr<Model>> &loadedModels,
const tinyxml2::XMLElement *groupdElement);
};

}
11 changes: 3 additions & 8 deletions include/engine/SceneWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@

#include <memory>

#include "engine/Camera.hpp"
#include "engine/Model.hpp"
#include "engine/RenderPipeline.hpp"
#include "engine/Scene.hpp"
#include "engine/Window.hpp"

namespace engine {
class SceneWindow : public Window {
private:
RenderPipeline pipeline;
Camera camera;

// TODO - remove, these are for testing purposes only
std::unique_ptr<Model> model;
glm::vec3 translate;
Scene scene;

public:
SceneWindow();
SceneWindow(const std::string &sceneFile);

protected:
void onUpdate(float time, float timeElapsed);
Expand Down
6 changes: 4 additions & 2 deletions include/engine/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class Window {
~Window();

void runLoop();
int getWidth();
int getHeight();
void resize(int _width, int _height);

int getWidth() const;
int getHeight() const;

protected:
GLFWwindow *getHandle();
Expand Down
1 change: 1 addition & 0 deletions res/models/taurus.3d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Só para a pasta não apagar.
14 changes: 14 additions & 0 deletions res/scenes/scene_box.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<world>
<window width="512" height="512" />
<camera>
<position x="3" y="2" z="1" />
<lookAt x="0" y="0" z="0" />
<up x="0" y="1" z="0" />
<projection fov="60" near="1" far="1000" />
</camera>
<group>
<models>
<model file="../models/box.3d" />
</models>
</group>
</world>
14 changes: 14 additions & 0 deletions res/scenes/scene_plane.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<world>
<window width="512" height="512" />
<camera>
<position x="3" y="2" z="1" />
<lookAt x="0" y="0" z="0" />
<up x="0" y="1" z="0" />
<projection fov="60" near="1" far="1000" />
</camera>
<group>
<models>
<model file="../models/plane.3d" />
</models>
</group>
</world>
14 changes: 14 additions & 0 deletions res/scenes/scene_sphere.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<world>
<window width="512" height="512" />
<camera>
<position x="3" y="2" z="1" />
<lookAt x="0" y="0" z="0" />
<up x="0" y="1" z="0" />
<projection fov="60" near="1" far="1000" />
</camera>
<group>
<models>
<model file="../models/sphere.3d" />
</models>
</group>
</world>
31 changes: 31 additions & 0 deletions src/engine/Entity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// Copyright 2025 Ana Oliveira, Humberto Gomes, Mariana Rocha, Sara Lopes
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.

#include "engine/Entity.hpp"

#include "engine/Model.hpp"

namespace engine {

Entity::Entity(std::shared_ptr<Model> _model, const glm::vec4 &_color) {
this->model = _model;
this->color = _color;
}

void Entity::draw(const RenderPipeline &pipeline) const {
pipeline.setColor(color);
this->model->draw();
}

}
1 change: 1 addition & 0 deletions src/engine/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ void Model::draw() const {
glBindVertexArray(this->vao);
glDrawElements(GL_TRIANGLES, this->vertexCount, GL_UNSIGNED_INT, nullptr);
}

}
1 change: 1 addition & 0 deletions src/engine/RenderPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ void RenderPipeline::assertProgramLinking() const {
throw std::runtime_error("Program linking error: " + logMessage);
}
}

}
Loading