mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-05 19:04:26 +00:00
Merge pull request #55 from AnonymusRaccoon/animations
Animations containers
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 295 KiB |
+12
-7
@@ -18,7 +18,6 @@ set(HEADERS
|
||||
sources/IRessource.hpp
|
||||
sources/Matrix.hpp
|
||||
sources/Mesh.hpp
|
||||
sources/Model.hpp
|
||||
sources/Window.hpp
|
||||
sources/Audio/IAudio.hpp
|
||||
sources/Audio/Music.hpp
|
||||
@@ -52,11 +51,18 @@ set(HEADERS
|
||||
sources/Drawables/3D/Ray.hpp
|
||||
sources/Drawables/3D/Sphere.hpp
|
||||
sources/Drawables/3D/Triangle.hpp
|
||||
sources/Exceptions/RayError.hpp
|
||||
sources/Model/Model.hpp
|
||||
sources/Model/ModelAnimation.hpp
|
||||
sources/Model/ModelAnimations.hpp
|
||||
sources/Vector/Vector2.hpp
|
||||
sources/Vector/Vector3.hpp
|
||||
)
|
||||
|
||||
set(SRC
|
||||
sources/Color.cpp
|
||||
sources/Font.cpp
|
||||
sources/Window.cpp
|
||||
sources/Audio/Music.cpp
|
||||
sources/Audio/Sound.cpp
|
||||
sources/Camera/Camera2D.cpp
|
||||
@@ -84,12 +90,12 @@ set(SRC
|
||||
sources/Drawables/ADrawable3D.cpp
|
||||
sources/Drawables/Image.cpp
|
||||
sources/Drawables/Texture.cpp
|
||||
sources/Exceptions/RayError.cpp
|
||||
sources/Model/Model.cpp
|
||||
sources/Model/ModelAnimation.cpp
|
||||
sources/Model/ModelAnimations.cpp
|
||||
sources/Vector/Vector2.cpp
|
||||
sources/Vector/Vector3.cpp
|
||||
sources/Color.cpp
|
||||
sources/Font.cpp
|
||||
sources/Model.cpp
|
||||
sources/Window.cpp
|
||||
)
|
||||
|
||||
find_package(raylib QUIET)
|
||||
@@ -99,6 +105,5 @@ if (NOT raylib_FOUND)
|
||||
endif()
|
||||
|
||||
add_library(${LIB_NAME} STATIC ${SRC} ${HEADERS})
|
||||
target_compile_definitions(${LIB_NAME} INTERFACE INTERNAL=private)
|
||||
target_compile_definitions(${LIB_NAME} PRIVATE INTERNAL=public)
|
||||
target_compile_definitions(${LIB_NAME} INTERFACE INTERNAL=private PRIVATE INTERNAL=public)
|
||||
target_link_libraries(${LIB_NAME} raylib)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "Camera/Camera2D.hpp"
|
||||
|
||||
RAY::Camera::Camera2D::Camera2D(const Vector2 &offset, const Vector2 &target, float rotation, float zoom):
|
||||
RAY::Camera::Camera2D::Camera2D(const RAY::Vector2 &offset, const RAY::Vector2 &target, float rotation, float zoom):
|
||||
_camera({offset, target, rotation, zoom})
|
||||
{
|
||||
}
|
||||
@@ -33,12 +33,12 @@ void RAY::Camera::Camera2D::setZoom(float zoom)
|
||||
this->_camera.zoom = zoom;
|
||||
}
|
||||
|
||||
const Vector2 &RAY::Camera::Camera2D::getOffset(void) const
|
||||
RAY::Vector2 RAY::Camera::Camera2D::getOffset(void) const
|
||||
{
|
||||
return this->_camera.offset;
|
||||
}
|
||||
|
||||
const Vector2 &RAY::Camera::Camera2D::getTarget(void) const
|
||||
RAY::Vector2 RAY::Camera::Camera2D::getTarget(void) const
|
||||
{
|
||||
return this->_camera.target;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define CAMERA2D_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Vector/Vector2.hpp"
|
||||
#include "Camera/ICamera.hpp"
|
||||
|
||||
namespace RAY::Camera {
|
||||
@@ -41,9 +42,9 @@ namespace RAY::Camera {
|
||||
void setZoom(float zoom);
|
||||
|
||||
//! @brief Get Offset
|
||||
const Vector2 &getOffset(void) const;
|
||||
Vector2 getOffset(void) const;
|
||||
//! @brief Get target
|
||||
const Vector2 &getTarget(void) const;
|
||||
Vector2 getTarget(void) const;
|
||||
//! @brief Get rotation
|
||||
float getRotation(void) const;
|
||||
//! @brief Get zoom
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "Camera/Camera3D.hpp"
|
||||
|
||||
RAY::Camera::Camera3D::Camera3D(const Vector3 &position, const Vector3 &target, const Vector3 &up, float fovy, Projection projection):
|
||||
RAY::Camera::Camera3D::Camera3D(const RAY::Vector3 &position, const RAY::Vector3 &target, const RAY::Vector3 &up, float fovy, Projection projection):
|
||||
_camera({position, target, up, fovy, projection})
|
||||
{
|
||||
}
|
||||
@@ -37,17 +37,17 @@ void RAY::Camera::Camera3D::setProjection(Projection projection)
|
||||
this->_camera.projection = projection;
|
||||
}
|
||||
|
||||
const Vector3 &RAY::Camera::Camera3D::getPosition(void) const
|
||||
RAY::Vector3 RAY::Camera::Camera3D::getPosition(void) const
|
||||
{
|
||||
return this->_camera.position;
|
||||
}
|
||||
|
||||
const Vector3 &RAY::Camera::Camera3D::getTarget(void) const
|
||||
RAY::Vector3 RAY::Camera::Camera3D::getTarget(void) const
|
||||
{
|
||||
return this->_camera.target;
|
||||
}
|
||||
|
||||
const Vector3 &RAY::Camera::Camera3D::getUp(void) const
|
||||
RAY::Vector3 RAY::Camera::Camera3D::getUp(void) const
|
||||
{
|
||||
return this->_camera.up;
|
||||
}
|
||||
@@ -72,6 +72,11 @@ void RAY::Camera::Camera3D::setMode(Mode mode)
|
||||
this->_mode = mode;
|
||||
}
|
||||
|
||||
void RAY::Camera::Camera3D::update(void)
|
||||
{
|
||||
UpdateCamera(&this->_camera);
|
||||
}
|
||||
|
||||
RAY::Camera::Camera3D::operator ::Camera3D() const
|
||||
{
|
||||
return this->_camera;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define CAMERA3D_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Vector/Vector3.hpp"
|
||||
#include "Camera/ICamera.hpp"
|
||||
#include "Camera/CameraProjection.hpp"
|
||||
#include "Camera/CameraMode.hpp"
|
||||
@@ -46,11 +47,11 @@ namespace RAY::Camera {
|
||||
void setProjection(Projection projection);
|
||||
|
||||
//! @brief Get Position
|
||||
const Vector3 &getPosition(void) const;
|
||||
Vector3 getPosition(void) const;
|
||||
//! @brief Get target
|
||||
const Vector3 &getTarget(void) const;
|
||||
Vector3 getTarget(void) const;
|
||||
//! @brief Get up
|
||||
const Vector3 &getUp(void) const;
|
||||
Vector3 getUp(void) const;
|
||||
//! @brief Get Fovy
|
||||
float getFovy(void) const;
|
||||
//! @brief Get projection
|
||||
@@ -59,9 +60,12 @@ namespace RAY::Camera {
|
||||
//! @brief Returns camera 3d transform matrix
|
||||
Matrix getMatrix(void) const override;
|
||||
|
||||
// Set camera mode (multiple camera modes available)
|
||||
//! @brief Set camera mode (multiple camera modes available)
|
||||
void setMode(Mode mode);
|
||||
|
||||
//! @brief Update camera position for selected mode
|
||||
void update(void);
|
||||
|
||||
private:
|
||||
::Camera3D _camera;
|
||||
Mode _mode;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "Drawables/2D/Triangle.hpp"
|
||||
#include <exception>
|
||||
#include "Exceptions/RayError.hpp"
|
||||
|
||||
RAY::Drawables::Drawables2D::Triangle::Triangle(const Vector2 &positionA, const Vector2 &positionB, const Vector2 &positionC, const Color &color):
|
||||
ADrawable2D(positionA, color), _posB(positionB), _posC(positionC)
|
||||
@@ -52,9 +52,8 @@ void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Window &)
|
||||
DrawTriangle(this->_position, this->_posB, this->_posC, this->_color);
|
||||
}
|
||||
|
||||
void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Image &image)
|
||||
void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Image &)
|
||||
{
|
||||
(void)image;
|
||||
throw std::exception();
|
||||
throw RAY::Exception::NotSupportedError("An triangle cannot be drawn on an image");
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace RAY::Drawables::Drawables2D {
|
||||
|
||||
//! @brief Draw point on window
|
||||
void drawOn(RAY::Window &) override;
|
||||
//! @brief Draw point on image
|
||||
//! @brief A Triangle cannot be drawn on an image, an exception will be thrown
|
||||
void drawOn(RAY::Image &image) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#define ADRAWABLE3D_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Vector/Vector3.hpp"
|
||||
#include "Drawables/IDrawable.hpp"
|
||||
#include "Color.hpp"
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** RayError
|
||||
*/
|
||||
|
||||
#include "RayError.hpp"
|
||||
|
||||
RAY::Exception::RayError::RayError(const std::string &expectionMessage):
|
||||
runtime_error(expectionMessage)
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Exception::NotSupportedError::NotSupportedError(const std::string &expectionMessage):
|
||||
RayError(expectionMessage)
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Exception::NotCompatibleError::NotCompatibleError(const std::string &expectionMessage):
|
||||
RayError(expectionMessage)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** RayError
|
||||
*/
|
||||
|
||||
#ifndef RAYERROR_HPP_
|
||||
#define RAYERROR_HPP_
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace RAY::Exception {
|
||||
//! @brief base exception class for RAY lib
|
||||
class RayError: public std::runtime_error {
|
||||
public:
|
||||
//! @brief Create a new RAY exception
|
||||
RayError(const std::string &what);
|
||||
|
||||
//! @brief A default destructor
|
||||
~RayError() = default;
|
||||
|
||||
//! @brief A RAY exception is copy constructable
|
||||
RayError(const RayError &) = default;
|
||||
|
||||
//! @brief A default assignment operator
|
||||
RayError &operator=(const RayError &) = default;
|
||||
};
|
||||
|
||||
//! @brief exception used when an incompatibility occurs
|
||||
class NotCompatibleError: public RayError {
|
||||
public:
|
||||
//! @brief Create a new exception instance
|
||||
NotCompatibleError(const std::string &what);
|
||||
|
||||
//! @brief A default destructor
|
||||
~NotCompatibleError() = default;
|
||||
|
||||
//! @brief An exception is copy constructable
|
||||
NotCompatibleError(const NotCompatibleError &) = default;
|
||||
|
||||
//! @brief A default assignment operator
|
||||
NotCompatibleError &operator=(const NotCompatibleError &) = default;
|
||||
};
|
||||
|
||||
//! @brief exception used when an non-supported operation is done
|
||||
class NotSupportedError: public RayError {
|
||||
public:
|
||||
//! @brief Create a new exception instance
|
||||
NotSupportedError(const std::string &what = "This operation is currently not supported");
|
||||
|
||||
//! @brief A default destructor
|
||||
~NotSupportedError() = default;
|
||||
|
||||
//! @brief An exception is copy constructable
|
||||
NotSupportedError(const NotSupportedError &) = default;
|
||||
|
||||
//! @brief A default assignment operator
|
||||
NotSupportedError &operator=(const NotSupportedError &) = default;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !RAYERROR_HPP_ */
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** Model
|
||||
*/
|
||||
|
||||
#include "Model.hpp"
|
||||
|
||||
RAY::Model::Model(const std::string &filename):
|
||||
_model(LoadModel(filename.c_str()))
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Model::Model(const Mesh &mesh):
|
||||
_model(LoadModelFromMesh(mesh))
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Model::~Model()
|
||||
{
|
||||
this->unload();
|
||||
}
|
||||
|
||||
bool RAY::Model::load(const std::string &filename)
|
||||
{
|
||||
this->_model = LoadModel(filename.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::load(const Mesh &mesh)
|
||||
{
|
||||
this->_model = LoadModelFromMesh(mesh);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::unload()
|
||||
{
|
||||
UnloadModel(_model);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::unloadKeepMeshes()
|
||||
{
|
||||
UnloadModelKeepMeshes(_model);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** Model
|
||||
*/
|
||||
|
||||
#include "Model/Model.hpp"
|
||||
#include "Exceptions/RayError.hpp"
|
||||
|
||||
RAY::Model::Model(const std::string &filename):
|
||||
_model(LoadModel(filename.c_str()))
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Model::Model(const Mesh &mesh):
|
||||
_model(LoadModelFromMesh(mesh))
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Model::~Model()
|
||||
{
|
||||
this->unload();
|
||||
}
|
||||
|
||||
bool RAY::Model::load(const std::string &filename)
|
||||
{
|
||||
this->_model = LoadModel(filename.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::load(const Mesh &mesh)
|
||||
{
|
||||
this->_model = LoadModelFromMesh(mesh);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::unload()
|
||||
{
|
||||
UnloadModel(this->_model);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::unloadKeepMeshes()
|
||||
{
|
||||
UnloadModelKeepMeshes(_model);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::setAnimation(const RAY::ModelAnimation &animation)
|
||||
{
|
||||
if (!IsModelAnimationValid(this->_model, animation))
|
||||
throw RAY::Exception::NotCompatibleError("The animation is not compatible with the model");
|
||||
UpdateModelAnimation(this->_model, animation, animation.getFrameCounter());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::setTextureToMaterial(RAY::Model::MaterialType materialType, const RAY::Texture &texture)
|
||||
{
|
||||
SetMaterialTexture(&this->_model.materials[materialType], materialType, texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
RAY::Model::operator ::Model() const
|
||||
{
|
||||
return this->_model;
|
||||
}
|
||||
|
||||
int RAY::Model::getBoneCount() const
|
||||
{
|
||||
return this->_model.boneCount;
|
||||
}
|
||||
@@ -9,12 +9,19 @@
|
||||
#define MODEL_HPP_
|
||||
|
||||
#include "IRessource.hpp"
|
||||
#include "Drawables/Texture.hpp"
|
||||
#include "Drawables/IDrawable.hpp"
|
||||
#include "Model/ModelAnimation.hpp"
|
||||
#include <raylib.h>
|
||||
#include <vector>
|
||||
|
||||
namespace RAY {
|
||||
//! @brief Basic 3d Model type
|
||||
//! @brief Basic 3D Model type
|
||||
class Model: public IRessource {
|
||||
public:
|
||||
|
||||
typedef ::MaterialMapIndex MaterialType;
|
||||
|
||||
//! @brief Create an model, loading a file
|
||||
//! @param filePath: path to file to load
|
||||
Model(const std::string &filePath);
|
||||
@@ -29,6 +36,7 @@ namespace RAY {
|
||||
//! @brief A model is assignable
|
||||
Model& operator=(const Model &model) = default;
|
||||
|
||||
//! @brief Model destructor, unloads all related data
|
||||
~Model();
|
||||
|
||||
//! @brief Load model from file (meshes and materials)
|
||||
@@ -38,12 +46,29 @@ namespace RAY {
|
||||
bool load(const Mesh &mesh);
|
||||
|
||||
//! @brief Unload model (including meshes) from memory (RAM and/or VRAM)
|
||||
bool unload();
|
||||
bool unload() override;
|
||||
|
||||
//! @brief Unload model (excluding meshes) from memory (RAM and/or VRAM)
|
||||
bool unloadKeepMeshes();
|
||||
|
||||
//! @brief Update model animation pose
|
||||
bool setAnimation(const RAY::ModelAnimation &animation);
|
||||
|
||||
//! @brief Sets a texture to the Nth material
|
||||
//! @param materielIndex The type of material to apply the texture to (serves as an index)
|
||||
//! @param texture the texture to apply
|
||||
bool setTextureToMaterial(MaterialType materialType, const RAY::Texture &texture);
|
||||
|
||||
//! @return The number of bones in the model
|
||||
int getBoneCount() const;
|
||||
private:
|
||||
//! @brief Raw data from raylib
|
||||
::Model _model;
|
||||
|
||||
INTERNAL:
|
||||
//! @brief A RAY Model is cast-able in libray's model
|
||||
operator ::Model() const;
|
||||
|
||||
};
|
||||
};
|
||||
#endif /* !Model_HPP_ */
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** ModelAnimation
|
||||
*/
|
||||
|
||||
#include "Model/ModelAnimation.hpp"
|
||||
|
||||
RAY::ModelAnimation::ModelAnimation(::ModelAnimation &animation):
|
||||
_animation(animation), _frameCounter(0)
|
||||
{
|
||||
}
|
||||
|
||||
size_t RAY::ModelAnimation::getFrameCounter() const
|
||||
{
|
||||
return this->_frameCounter;
|
||||
}
|
||||
|
||||
size_t RAY::ModelAnimation::getFrameCount() const
|
||||
{
|
||||
return this->_animation.frameCount;
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimation::setFrameCounter(size_t frameCounter)
|
||||
{
|
||||
this->_frameCounter = frameCounter % this->_animation.frameCount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimation::incrementFrameCounter()
|
||||
{
|
||||
this->_frameCounter = (this->_frameCounter + 1) % this->_animation.frameCount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
RAY::ModelAnimation::operator ::ModelAnimation() const
|
||||
{
|
||||
return this->_animation;
|
||||
}
|
||||
|
||||
RAY::ModelAnimation::operator ::ModelAnimation *()
|
||||
{
|
||||
return &this->_animation;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** ModelAnimation
|
||||
*/
|
||||
|
||||
#ifndef MODELANIMATION_HPP_
|
||||
#define MODELANIMATION_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include <memory>
|
||||
|
||||
namespace RAY {
|
||||
//! @brief A Holder for Model Animations
|
||||
class ModelAnimation {
|
||||
public:
|
||||
//! @brief A Model animation constructor
|
||||
//! @param animationPtr an animation pointer, returned by the nimation-loading function
|
||||
ModelAnimation(::ModelAnimation &animationPtr);
|
||||
|
||||
//! @brief A default copy-constructor
|
||||
ModelAnimation(const ModelAnimation &) = default;
|
||||
|
||||
//! @brief A model animation is assignable
|
||||
ModelAnimation &operator=(const ModelAnimation &) = default;
|
||||
|
||||
//! @brief Returns the current frame the animation is at
|
||||
size_t getFrameCounter() const;
|
||||
|
||||
//! @brief Returns the number of frame in the animation
|
||||
size_t getFrameCount() const;
|
||||
|
||||
//! @brief Set the frame the position is at
|
||||
ModelAnimation &setFrameCounter(size_t frameCounter);
|
||||
|
||||
//! @brief Increment the frame counter
|
||||
ModelAnimation &incrementFrameCounter();
|
||||
|
||||
//! @brief Default destructor
|
||||
~ModelAnimation() = default;
|
||||
|
||||
private:
|
||||
::ModelAnimation &_animation;
|
||||
|
||||
size_t _frameCounter;
|
||||
INTERNAL:
|
||||
//! @brief Castin Object to raw model animation pointer
|
||||
operator ::ModelAnimation *();
|
||||
|
||||
//! @brief Castin Object to raw model animation pointer
|
||||
operator ::ModelAnimation() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* !MODELANIMATION_HPP_ */
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** ModelAnimations
|
||||
*/
|
||||
|
||||
#include "Model/ModelAnimations.hpp"
|
||||
|
||||
RAY::ModelAnimations::ModelAnimations(const std::string &filePath):
|
||||
_animationsPtr(LoadModelAnimations(filePath.c_str(), &this->_animationCount))
|
||||
{
|
||||
::ModelAnimation *ptr = this->_animationsPtr.get();
|
||||
for (int i = 0; i < this->_animationCount; i++)
|
||||
this->_animations.push_back(RAY::ModelAnimation(ptr[i]));
|
||||
}
|
||||
|
||||
RAY::ModelAnimations::~ModelAnimations()
|
||||
{
|
||||
UnloadModelAnimations(this->_animationsPtr.release(), this->_animationCount);
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index)
|
||||
{
|
||||
return this->_animations[index];
|
||||
}
|
||||
|
||||
size_t RAY::ModelAnimations::getAnimationsCount() const
|
||||
{
|
||||
return this->_animationCount;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** ModelAnimations
|
||||
*/
|
||||
|
||||
#ifndef MODELANIMATIONS_HPP_
|
||||
#define MODELANIMATIONS_HPP_
|
||||
|
||||
#include "Model/ModelAnimation.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace RAY {
|
||||
//! @brief A Holder for Model Animations
|
||||
class ModelAnimations {
|
||||
public:
|
||||
//! @brief A Model animation constructor
|
||||
//! @param filePath Path to the file containing animations
|
||||
ModelAnimations(const std::string &filePath);
|
||||
|
||||
//! @brief Only single entity can hold these animations pointers
|
||||
ModelAnimations(const ModelAnimations &) = delete;
|
||||
|
||||
//! @brief Unloads all animations
|
||||
~ModelAnimations();
|
||||
|
||||
//! @brief Only single entity can hold these animations pointers
|
||||
ModelAnimations &operator=(const ModelAnimations &) = delete;
|
||||
|
||||
//! @brief Castin Object to raw model animation pointer
|
||||
ModelAnimation &operator[](int index);
|
||||
|
||||
//! @return the number of loaded animations
|
||||
size_t getAnimationsCount() const;
|
||||
|
||||
private:
|
||||
//! @brief Holds the pointer returned by the loading function
|
||||
std::unique_ptr<::ModelAnimation> _animationsPtr;
|
||||
|
||||
//! @brief A holder for animations
|
||||
std::vector<ModelAnimation> _animations;
|
||||
|
||||
//! @brief the number of loaded animations
|
||||
int _animationCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !MODELANIMATIONS_HPP_ */
|
||||
@@ -160,6 +160,11 @@ void RAY::Window::draw(const Mesh &mesh, const Material &material, const Matrix
|
||||
DrawMesh(mesh, material, transform);
|
||||
}
|
||||
|
||||
void RAY::Window::draw(const RAY::Model &model, const RAY::Vector3 &position, const RAY::Vector3 &rotationAxis, float rotationAngle, const RAY::Vector3 &scale, const RAY::Color &tint)
|
||||
{
|
||||
DrawModelEx(model, position, rotationAxis, rotationAngle, scale, tint);
|
||||
}
|
||||
|
||||
void RAY::Window::setIcon(RAY::Image &img)
|
||||
{
|
||||
SetWindowIcon(img);
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
#include <raylib.h>
|
||||
#include <string>
|
||||
#include <Vector/Vector2.hpp>
|
||||
#include "Vector/Vector2.hpp"
|
||||
#include "Vector/Vector3.hpp"
|
||||
#include "Controllers/Keyboard.hpp"
|
||||
#include "Camera/Camera2D.hpp"
|
||||
#include "Camera/Camera3D.hpp"
|
||||
@@ -18,8 +19,10 @@
|
||||
#include "Canvas.hpp"
|
||||
#include "Drawables/IDrawable.hpp"
|
||||
#include "Drawables/Texture.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
|
||||
namespace RAY {
|
||||
class Model;
|
||||
//! @brief Window manager
|
||||
class Window: public Canvas {
|
||||
public:
|
||||
@@ -116,11 +119,15 @@ namespace RAY {
|
||||
//! @param texture The object to render
|
||||
//! @param position The position of the texture relative to the top left window corner
|
||||
//! @param tint
|
||||
void draw(const RAY::Texture &texture, const Vector2 &position, const Color &tint);
|
||||
void draw(const Texture &texture, const Vector2 &position, const Color &tint);
|
||||
|
||||
//! @brief Draw a 3d mesh with material and transform
|
||||
void draw(const Mesh &mesh, const Material &material, const Matrix &transform);
|
||||
|
||||
//! @brief Draw a model
|
||||
void draw(const Model &model, const Vector3 &position, const Vector3 &rotationAxis = Vector3(0, 0, 0),
|
||||
float rotationAngle = 0, const Vector3 &scale = Vector3(1, 1, 1), const Color &tint = WHITE);
|
||||
|
||||
|
||||
private:
|
||||
//! @brief Creates window, and opens it if openNow is set to true
|
||||
|
||||
@@ -10,5 +10,5 @@
|
||||
|
||||
RAY::Vector3 toRAY(const WAL::Vector3f &wal)
|
||||
{
|
||||
return RAY::Vector3(wal.x, wal.y, wal.y);
|
||||
return RAY::Vector3(wal.x, wal.y, wal.y);
|
||||
}
|
||||
+75
-16
@@ -6,25 +6,84 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "Window.hpp"
|
||||
#include "Drawables/2D/Text.hpp"
|
||||
#include "Drawables/2D/Circle.hpp"
|
||||
#include "Controllers/Keyboard.hpp"
|
||||
#include "Camera/Camera3D.hpp"
|
||||
#include "Drawables/3D/Grid.hpp"
|
||||
#include "Drawables/3D/Cube.hpp"
|
||||
#include <cmath>
|
||||
#include "Wal.hpp"
|
||||
#include "Camera/Camera3D.hpp"
|
||||
#include "Controllers/Keyboard.hpp"
|
||||
#include "Drawables/2D/Text.hpp"
|
||||
#include "Drawables/3D/Grid.hpp"
|
||||
#include "Drawables/Texture.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
#include "Model/ModelAnimations.hpp"
|
||||
#include "Vector/Vector3.hpp"
|
||||
#include "Window.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
WAL::Wal wal;
|
||||
try {
|
||||
wal.run();
|
||||
return 0;
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << ex.what() << std::endl;
|
||||
return 84;
|
||||
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE);
|
||||
RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f),
|
||||
RAY::Vector3(0.0f, 0.0f, 0.0f),
|
||||
RAY::Vector3(0.0f, 1.0f, 0.0f),
|
||||
45.0f, CAMERA_PERSPECTIVE
|
||||
);
|
||||
RAY::Model model("assets/guy.iqm");
|
||||
RAY::Texture texture("assets/guytex.png");
|
||||
RAY::ModelAnimations animations("assets/guy.iqm");
|
||||
RAY::Drawables::Drawables3D::Grid grid(10, 1.0f);
|
||||
RAY::Drawables::Drawables2D::Text instructionText("PRESS SPACE to PLAY MODEL ANIMATION", 10, {10, 20} , MAROON);
|
||||
model.setTextureToMaterial(MAP_DIFFUSE, texture);
|
||||
|
||||
RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position
|
||||
|
||||
camera.setMode(CAMERA_FREE); // Set free camera mode
|
||||
|
||||
window.setFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!window.shouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
camera.update();
|
||||
|
||||
// Play animation when spacebar is held down
|
||||
if (RAY::Controller::Keyboard::isDown(KEY_SPACE))
|
||||
{
|
||||
animations[0].incrementFrameCounter();
|
||||
model.setAnimation(animations[0]);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
window.setDrawingState(RAY::Window::DRAWING);
|
||||
|
||||
window.clear();
|
||||
|
||||
window.useCamera(camera);
|
||||
|
||||
window.draw(model, position, RAY::Vector3(1.0f, 0.0f, 0.0f), -90.0f, RAY::Vector3( 1.0f, 1.0f, 1.0f ));
|
||||
|
||||
window.draw(grid);
|
||||
|
||||
window.unuseCamera();
|
||||
|
||||
window.draw(instructionText);
|
||||
|
||||
window.setDrawingState(RAY::Window::IDLE);
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
window.close(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user