Skip to content

Commit

Permalink
Merge pull request #33 from FppEpitech/feat/implement-the-render-class
Browse files Browse the repository at this point in the history
feat: Render class to draw the scene
  • Loading branch information
mathieurobert1 authored Jun 4, 2024
2 parents d804752 + 2741a65 commit e38389b
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ jobs:
container: epitechcontent/epitest-docker
steps:
- uses: actions/checkout@v4
- name: install_raylib
run: |
sudo dnf install raylib-devel -y
- name: run_tests
run: make tests_run
timeout-minutes: 5
Expand Down
8 changes: 6 additions & 2 deletions gui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ SRC = src/Error/Error.cpp \
src/GameDatas/Player.cpp \
src/GameDatas/Tile.cpp \
src/GameDatas/Team.cpp \
\
src/Render/Render.cpp \
src/Render/UserCamera.cpp \

TEST_FILES = Network/TestNetwork.cpp \
Parsing/TestParser.cpp \
Expand All @@ -29,6 +32,7 @@ TEST_FILES = Network/TestNetwork.cpp \
GameDatas/TestPlayer.cpp \
GameDatas/TestTile.cpp \
GameDatas/TestTeam.cpp \
Render/TestCamera.cpp \

OBJ = $(SRC:.cpp=.o)
MAIN_OBJ = $(MAIN:.cpp=.o)
Expand All @@ -38,7 +42,7 @@ NAME = zappy_gui

# Flags
INCLUDE = -I./include -I./tests
CXXFLAGS = -std=c++20 -Wall -Wextra -Werror
CXXFLAGS = -std=c++20 -Wall -Wextra -Werror -lraylib

# Colors
YELLOW = /bin/echo -e "\x1b[33m $1\x1b[0m"
Expand All @@ -51,7 +55,7 @@ TEST = $(addprefix $(TEST_DIR), $(TEST_FILES))
TEST_OBJ = $(TEST:.cpp=.o)
TEST_GCNO = $(SRC:.cpp=.gcno)
TEST_GCDA = $(SRC:.cpp=.gcda)
TEST_FLAGS = -Wall -Wextra -Werror --coverage -lcriterion
TEST_FLAGS = -Wall -Wextra -Werror --coverage -lcriterion -lraylib

CC = g++

Expand Down
4 changes: 3 additions & 1 deletion gui/include/Engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include "Render/Render.hpp"
#include "Network/Network.hpp"
#include "Parsing/ServerParser.hpp"

Expand Down Expand Up @@ -44,8 +45,9 @@ class Gui::Engine {

private:

ServerParser _parser; // Parser class for server's command
ServerParser _parser; // Parser class for server's command.
Network _network; // Network class to connect to the server.
Render _render; // Render class to draw the scene.

/**
* @brief Listen the server and update Engine with its commands.
Expand Down
59 changes: 59 additions & 0 deletions gui/include/Render/Render.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
** EPITECH PROJECT, 2024
** Zappy GUI
** File description:
** Render
*/

#pragma once

#define WINDOW_WIDTH 1920
#define WINDOW_HEIGHT 1080
#define WINDOW_TITLE "Zappy GUI"

#include "raylib.h"
#include "Render/UserCamera.hpp"

namespace Gui {

/**
* @brief Render class to display Zappy.
*
*/
class Render;
};

class Gui::Render {

public:

/**
* @brief Construct a new Render object.
*
*/
Render();

/**
* @brief Destroy the Render object.
*
*/
~Render();

/**
* @brief Check if the window is open.
*
* @return true - the window is open
* @return false - the window is closed
*/
bool isOpen();

/**
* @brief Draw the scene.
*
*/
void draw();

private:

UserCamera _camera; // Camera of the scene.
};
105 changes: 105 additions & 0 deletions gui/include/Render/UserCamera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
** EPITECH PROJECT, 2024
** Zappy GUI
** File description:
** Camera
*/

#pragma once

#include "raylib.h"

#include <memory>

namespace Gui {

/**
* @brief UserCamera class to handle the camera.
*
*/
class UserCamera;
};

class Gui::UserCamera {

public:

/**
* @brief Construct a new User Camera object.
*
*/
UserCamera();

/**
* @brief Destroy the User Camera object.
*
*/
~UserCamera() = default;

/**
* @brief Set the Position object.
*
* @param position New camera position.
*/
void setPosition(Vector3 position);

/**
* @brief Set the Target object.
*
* @param target New camera target.
*/
void setTarget(Vector3 target);

/**
* @brief Set the Up object.
*
* @param up New camera up vector.
*/
void setUp(Vector3 up);

/**
* @brief Set the Fovy object.
*
* @param fovy New camera fovy.
*/
void setFovy(float fovy);

/**
* @brief Get the Position object.
*
* @return Vector3 - position
*/
Vector3 getPosition(void) const;

/**
* @brief Get the Target object.
*
* @return Vector3 - target
*/
Vector3 getTarget(void) const;

/**
* @brief Get the Up object.
*
* @return Vector3 - up
*/
Vector3 getUp(void) const;

/**
* @brief Get the Fovy object.
*
* @return float - fovy
*/
float getFovy(void) const;

/**
* @brief Get the Camera object.
*
* @return Camera - camera
*/
std::shared_ptr<Camera> getCamera();

private:

std::shared_ptr<Camera> _camera;
};
9 changes: 4 additions & 5 deletions gui/src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ Gui::Engine::Engine(Network network) : _network(network) {}

void Gui::Engine::run(void)
{
//while (//TODO : renderer.getIsOpen()) {
while (_render.isOpen()) {
listenServer();
// TODO :
// handleEvents();
// display();
// }
// TODO : handleEvents();
_render.draw();
}
}

void Gui::Engine::listenServer(void)
Expand Down
41 changes: 41 additions & 0 deletions gui/src/Render/Render.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
** EPITECH PROJECT, 2024
** Zappy GUI
** File description:
** Render
*/

#include "Render/Render.hpp"

Gui::Render::Render()
{
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE);
DisableCursor();
SetTargetFPS(140);
}

Gui::Render::~Render()
{
CloseWindow();
}

bool Gui::Render::isOpen()
{
return !WindowShouldClose();
}

void Gui::Render::draw()
{
UpdateCamera(_camera.getCamera().get(), CAMERA_FIRST_PERSON);
BeginDrawing();

ClearBackground(RAYWHITE);

BeginMode3D(*_camera.getCamera());
DrawGrid(20, 1.0f);
EndMode3D();

DrawFPS(10, 10);

EndDrawing();
}
63 changes: 63 additions & 0 deletions gui/src/Render/UserCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
** EPITECH PROJECT, 2024
** Zappy GUI
** File description:
** UserCamera
*/

#include "Render/UserCamera.hpp"

Gui::UserCamera::UserCamera()
{
_camera = std::make_shared<Camera>();
_camera->position = (Vector3){ 5.0f, 5.0f, 5.0f };
_camera->target = (Vector3){ 0.0f, 2.0f, 0.0f };
_camera->up = (Vector3){ 0.0f, 1.0f, 0.0f };
_camera->fovy = 70.0f;
_camera->projection = CAMERA_PERSPECTIVE;
}

void Gui::UserCamera::setPosition(Vector3 position)
{
_camera->position = position;
}

void Gui::UserCamera::setTarget(Vector3 target)
{
_camera->target = target;
}

void Gui::UserCamera::setUp(Vector3 up)
{
_camera->up = up;
}

void Gui::UserCamera::setFovy(float fovy)
{
_camera->fovy = fovy;
}

Vector3 Gui::UserCamera::getPosition(void) const
{
return _camera->position;
}

Vector3 Gui::UserCamera::getTarget(void) const
{
return _camera->target;
}

Vector3 Gui::UserCamera::getUp(void) const
{
return _camera->up;
}

float Gui::UserCamera::getFovy(void) const
{
return _camera->fovy;
}

std::shared_ptr<Camera> Gui::UserCamera::getCamera()
{
return _camera;
}
Loading

0 comments on commit e38389b

Please sign in to comment.