-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from FppEpitech/feat/implement-the-render-class
feat: Render class to draw the scene
- Loading branch information
Showing
9 changed files
with
378 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.