Fixing display loop
|
Before Width: | Height: | Size: 295 KiB |
|
Before Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 807 B |
|
After Width: | Height: | Size: 788 B |
|
After Width: | Height: | Size: 802 B |
|
After Width: | Height: | Size: 788 B |
|
Before Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 796 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 798 B |
|
Before Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 780 B |
@@ -0,0 +1 @@
|
||||
idle:1:80:24:1,idle:90:129:24:1,idle:130:172:24:1,idle:172:210:24:1,idle:210:240:24:1,idle:240:280:24:1
|
||||
@@ -8,46 +8,47 @@
|
||||
#include "Model/Model.hpp"
|
||||
#include "Exceptions/RayError.hpp"
|
||||
|
||||
RAY::Model::Model(const std::string &filename):
|
||||
_model(LoadModel(filename.c_str()))
|
||||
RAY::Drawables::Drawables3D::Model::Model(const std::string &filename, const RAY::Vector3 &position, const RAY::Vector3 &rotationAxis, float rotationAngle, const RAY::Vector3 &scale):
|
||||
ADrawable3D(position, WHITE), _model(LoadModel(filename.c_str())),
|
||||
_rotationAxis(rotationAxis), _rotationAngle(rotationAngle), _scale(scale)
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Model::Model(const Mesh &mesh):
|
||||
_model(LoadModelFromMesh(mesh))
|
||||
RAY::Drawables::Drawables3D::Model::Model(const Mesh &mesh)
|
||||
: ADrawable3D({0, 0, 0}, WHITE), _model(LoadModelFromMesh(mesh))
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Model::~Model()
|
||||
RAY::Drawables::Drawables3D::Model::~Model()
|
||||
{
|
||||
this->unload();
|
||||
}
|
||||
|
||||
bool RAY::Model::load(const std::string &filename)
|
||||
bool RAY::Drawables::Drawables3D::Model::load(const std::string &filename)
|
||||
{
|
||||
this->_model = LoadModel(filename.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::load(const Mesh &mesh)
|
||||
bool RAY::Drawables::Drawables3D::Model::load(const Mesh &mesh)
|
||||
{
|
||||
this->_model = LoadModelFromMesh(mesh);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::unload()
|
||||
bool RAY::Drawables::Drawables3D::Model::unload()
|
||||
{
|
||||
UnloadModel(this->_model);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::unloadKeepMeshes()
|
||||
bool RAY::Drawables::Drawables3D::Model::unloadKeepMeshes()
|
||||
{
|
||||
UnloadModelKeepMeshes(_model);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::setAnimation(const RAY::ModelAnimation &animation)
|
||||
bool RAY::Drawables::Drawables3D::Model::setAnimation(const RAY::ModelAnimation &animation)
|
||||
{
|
||||
if (!IsModelAnimationValid(this->_model, animation))
|
||||
throw RAY::Exception::NotCompatibleError("The animation is not compatible with the model");
|
||||
@@ -55,18 +56,56 @@ bool RAY::Model::setAnimation(const RAY::ModelAnimation &animation)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Model::setTextureToMaterial(RAY::Model::MaterialType materialType, const RAY::Texture &texture)
|
||||
bool RAY::Drawables::Drawables3D::Model::setTextureToMaterial(RAY::Drawables::Drawables3D::Model::MaterialType materialType, const RAY::Texture &texture)
|
||||
{
|
||||
SetMaterialTexture(&this->_model.materials[materialType], materialType, texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
RAY::Model::operator ::Model() const
|
||||
RAY::Drawables::Drawables3D::Model::operator ::Model() const
|
||||
{
|
||||
return this->_model;
|
||||
}
|
||||
|
||||
int RAY::Model::getBoneCount() const
|
||||
int RAY::Drawables::Drawables3D::Model::getBoneCount() const
|
||||
{
|
||||
return this->_model.boneCount;
|
||||
}
|
||||
|
||||
RAY::Drawables::Drawables3D::Model &RAY::Drawables::Drawables3D::Model::setRotationAngle(float rotationAngle)
|
||||
{
|
||||
this->_rotationAngle = rotationAngle;
|
||||
return *this;
|
||||
}
|
||||
|
||||
float RAY::Drawables::Drawables3D::Model::getRotationAngle(void)
|
||||
{
|
||||
return this->_rotationAngle;
|
||||
}
|
||||
|
||||
RAY::Drawables::Drawables3D::Model &RAY::Drawables::Drawables3D::Model::setRotationAxis(const RAY::Vector3 &scale)
|
||||
{
|
||||
this->_scale = scale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const RAY::Vector3 &RAY::Drawables::Drawables3D::Model::getRotationAxis(void)
|
||||
{
|
||||
return this->_rotationAxis;
|
||||
}
|
||||
|
||||
RAY::Drawables::Drawables3D::Model &RAY::Drawables::Drawables3D::Model::setScale(const RAY::Vector3 &scale)
|
||||
{
|
||||
this->_scale = scale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const RAY::Vector3 &RAY::Drawables::Drawables3D::Model::getScale(void)
|
||||
{
|
||||
return this->_scale;
|
||||
}
|
||||
|
||||
void RAY::Drawables::Drawables3D::Model::drawOn(RAY::Window &)
|
||||
{
|
||||
DrawModelEx(this->_model, this->_position, this->_rotationAxis, this->_rotationAngle, this->_scale, this->_color);
|
||||
}
|
||||
@@ -10,21 +10,21 @@
|
||||
|
||||
#include "IRessource.hpp"
|
||||
#include "Drawables/Texture.hpp"
|
||||
#include "Drawables/IDrawable.hpp"
|
||||
#include "Drawables/ADrawable3D.hpp"
|
||||
#include "Model/ModelAnimation.hpp"
|
||||
#include <raylib.h>
|
||||
#include <vector>
|
||||
|
||||
namespace RAY {
|
||||
namespace RAY::Drawables::Drawables3D {
|
||||
//! @brief Basic 3D Model type
|
||||
class Model: public IRessource {
|
||||
class Model: public IRessource, public Drawables::ADrawable3D {
|
||||
public:
|
||||
|
||||
typedef ::MaterialMapIndex MaterialType;
|
||||
|
||||
//! @brief Create an model, loading a file
|
||||
//! @param filePath: path to file to load
|
||||
Model(const std::string &filePath);
|
||||
Model(const std::string &filePath, const RAY::Vector3 &position = {0, 0, 0}, const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0), float rotationAngle = 0, const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1));
|
||||
|
||||
//! @brief Create an model, loading a file
|
||||
//! @param mesh: mesh to load
|
||||
@@ -61,9 +61,36 @@ namespace RAY {
|
||||
|
||||
//! @return The number of bones in the model
|
||||
int getBoneCount() const;
|
||||
|
||||
//! @brief Set rotation angle
|
||||
Model &setRotationAngle(float roationAngle);
|
||||
|
||||
//! @return rotation angle
|
||||
float getRotationAngle(void);
|
||||
|
||||
//! @brief Set Rotation Axis
|
||||
Model &setRotationAxis(const RAY::Vector3 &scale);
|
||||
|
||||
//! @return rotation axis
|
||||
const RAY::Vector3 & getRotationAxis(void);
|
||||
|
||||
//! @brief Set Scale
|
||||
Model &setScale(const RAY::Vector3 &scale);
|
||||
|
||||
//! @return Scale
|
||||
const RAY::Vector3 & getScale(void);
|
||||
|
||||
void drawOn(RAY::Window &) override;
|
||||
|
||||
private:
|
||||
//! @brief Raw data from raylib
|
||||
::Model _model;
|
||||
//! @brief Rotation property
|
||||
RAY::Vector3 _rotationAxis;
|
||||
//! @brief Rotation property
|
||||
float _rotationAngle;
|
||||
//! @brief Scale of the shape
|
||||
RAY::Vector3 _scale;
|
||||
|
||||
INTERNAL:
|
||||
//! @brief A RAY Model is cast-able in libray's model
|
||||
|
||||
@@ -11,6 +11,7 @@ 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]));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "Window.hpp"
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include "Controllers/Mouse.hpp"
|
||||
#include "Drawables/ADrawable2D.hpp"
|
||||
#include "Drawables/ADrawable3D.hpp"
|
||||
@@ -162,11 +163,6 @@ 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);
|
||||
|
||||
@@ -19,15 +19,16 @@
|
||||
#include "Camera/Camera3D.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Drawables/Texture.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
#include "Drawables/IDrawable.hpp"
|
||||
|
||||
namespace RAY {
|
||||
class Model;
|
||||
//! @brief Window manager
|
||||
namespace Drawables {
|
||||
class IDrawable;
|
||||
class ADrawable3D;
|
||||
namespace Drawables3D
|
||||
{
|
||||
class Model;
|
||||
}
|
||||
}
|
||||
class Window {
|
||||
private:
|
||||
@@ -130,10 +131,6 @@ namespace RAY {
|
||||
//! @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
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
#include <System/Renderer/Render2DScreenSystem.hpp>
|
||||
#include <System/Renderer/Renderer2DSystem.hpp>
|
||||
#include <Drawables/2D/Rectangle.hpp>
|
||||
#include <Models/Vector2.hpp>
|
||||
#include <System/Renderer/Renderer3DSystem.hpp>
|
||||
#include "Models/Vector2.hpp"
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
|
||||
@@ -27,7 +29,7 @@ namespace BBM
|
||||
{
|
||||
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
// wal.addSystem<>(); 3D elements here
|
||||
// wal.addSystem<Renderer3DSystem<RAY::Drawables::Drawables3D::Model>>();
|
||||
|
||||
wal.addSystem<Render2DScreenSystem>(window)
|
||||
.addSystem<Renderer2DSystem<RAY::Drawables::Drawables2D::Rectangle>>();
|
||||
@@ -39,7 +41,10 @@ namespace BBM
|
||||
WAL::Scene scene;
|
||||
scene.addEntity("cube")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable2DComponent<RAY::Drawables::Drawables2D::Rectangle>>(Vector2f(), Vector2f(1, 1), RED);
|
||||
.addComponent<Drawable2DComponent<RAY::Drawables::Drawables2D::Rectangle>>(Vector2f(), Vector2f(10, 10), RED);
|
||||
scene.addEntity("camera")
|
||||
.addComponent<PositionComponent>(10, 10, 10)
|
||||
.addComponent<CameraComponent>();
|
||||
return scene;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace BBM
|
||||
Render2DScreenSystem::Render2DScreenSystem(RAY::Window &window)
|
||||
: WAL::System({}),
|
||||
_window(window),
|
||||
_camera(RAY::Vector2(), RAY::Vector2(), 0)
|
||||
_camera(RAY::Vector2(10, 10), RAY::Vector2(), 0)
|
||||
{}
|
||||
|
||||
void Render2DScreenSystem::onSelfUpdate()
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "Wal.hpp"
|
||||
|
||||
const std::vector<std::string>textures = {
|
||||
"black", "blue", "pink", "red", "white", "yellow"
|
||||
"blue", "cyan", "green", "orange", "purple", "red", "yellow"
|
||||
};
|
||||
|
||||
std::string get_full_path(const std::string &color)
|
||||
@@ -47,66 +47,16 @@ std::string get_full_path(const std::string &color)
|
||||
|
||||
int demo()
|
||||
{
|
||||
// WAL::Wal wal;
|
||||
// const int screenWidth = 800;
|
||||
// const int screenHeight = 450;
|
||||
//
|
||||
// RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
// RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE);
|
||||
// RAY::Image icon("assets/icon.png");
|
||||
// window.setIcon(icon);
|
||||
// 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::Camera::Camera2D camera2D(RAY::Vector2(screenWidth / 2.0f, screenHeight / 2.0f),
|
||||
// RAY::Vector2(20.0f, 20.0f),
|
||||
// 0., 1);
|
||||
// WAL::Entity entityPlayer("roger");
|
||||
// //RAY::Drawables::Drawables2D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0);
|
||||
// RAY::Drawables::Drawables2D::Circle circle({0, 0}, 50, MAROON);
|
||||
// //RAY::Drawables::Drawables3D::Cube cube({0, 0, 0}, {2, 2, 2}, BLUE);
|
||||
// BBM::Drawable2DComponent<RAY::Drawables::Drawables2D::Circle> circleComponent(entityPlayer, circle);
|
||||
//// BBM::Drawable3DComponent<RAY::Drawables::Drawables3D::Cube> cubeComponent(entityPlayer, cube);
|
||||
// BBM::PositionComponent posComponent(entityPlayer, {0, 0, 0});
|
||||
//
|
||||
// BBM::Renderer2DSystem<RAY::Drawables::Drawables2D::Circle> circleSystem(window);
|
||||
// //BBM::Renderer3DSystem<RAY::Drawables::Drawables3D::Cube> cubeSystem(window);
|
||||
//
|
||||
//// BBM::RenderScreenSystem<RAY::Camera::Camera2D> renderSystem(window, camera2D);
|
||||
//
|
||||
// wal.addSystem(circleSystem);
|
||||
//// wal.addSystem(renderSystem);
|
||||
// //wal.addSystem(cubeSystem);
|
||||
// entityPlayer.addComponent(circleComponent);
|
||||
// //entityPlayer.addComponent(cubeComponent);
|
||||
// entityPlayer.addComponent(posComponent);
|
||||
// wal.scene.addEntity(entityPlayer);
|
||||
//
|
||||
// camera.setMode(CAMERA_FREE); // Set free camera mode
|
||||
//
|
||||
// float y_rotation = 0;
|
||||
// window.setFPS(60);
|
||||
//
|
||||
// wal.run<int>([](WAL::Wal &wal, int) {});
|
||||
//
|
||||
// window.close();
|
||||
|
||||
|
||||
/*
|
||||
WAL::Wal wal;
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
auto iterator = textures.begin();
|
||||
const std::string modelPath = "assets/player/player.obj";
|
||||
const std::string texturePath = "assets/player/blue.png";
|
||||
//const std::string animationPath = "assets/guy.iqm";
|
||||
std::vector<std::string>::const_iterator iterator = textures.begin();
|
||||
const std::string modelPath = "assets/player/player.iqm";
|
||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE);
|
||||
RAY::Image icon("assets/icon.png");
|
||||
window.setIcon(icon);
|
||||
RAY::Model model(modelPath);
|
||||
RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position
|
||||
RAY::Drawables::Drawables3D::Model model(modelPath, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 3.0f, 3.0f, 3.0f ));
|
||||
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),
|
||||
@@ -122,13 +72,13 @@ int demo()
|
||||
entityPlayer.addComponent(circleComponent);
|
||||
|
||||
RAY::Texture texture(get_full_path(*iterator));
|
||||
//RAY::ModelAnimations animations(modelPath);
|
||||
RAY::ModelAnimations animations(modelPath);
|
||||
RAY::Drawables::Drawables3D::Grid grid(10, 1.0f);
|
||||
RAY::Drawables::Drawables2D::Text instructionText("PRESS SPACE to PLAY MODEL ANIMATION", 10, {10, 20} , MAROON);
|
||||
size_t animationIndex = 0;
|
||||
|
||||
model.setTextureToMaterial(MAP_DIFFUSE, texture);
|
||||
|
||||
RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position
|
||||
|
||||
window.setIcon(icon);
|
||||
camera.setMode(CAMERA_FREE); // Set free camera mode
|
||||
|
||||
float y_rotation = 0;
|
||||
@@ -138,7 +88,13 @@ int demo()
|
||||
{
|
||||
camera.update();
|
||||
|
||||
if (RAY::Controller::Keyboard::isReleased(KEY_SPACE))
|
||||
// Play animation when spacebar is held down
|
||||
if (RAY::Controller::Keyboard::isDown(KEY_SPACE))
|
||||
{
|
||||
animations[animationIndex].incrementFrameCounter();
|
||||
model.setAnimation(animations[animationIndex]);
|
||||
}
|
||||
if (RAY::Controller::Keyboard::isReleased(KEY_UP))
|
||||
{
|
||||
++iterator;
|
||||
if (iterator == textures.end())
|
||||
@@ -146,21 +102,30 @@ int demo()
|
||||
texture.unload();
|
||||
texture.load(get_full_path(*iterator));
|
||||
model.setTextureToMaterial(MAP_DIFFUSE, texture);
|
||||
//animations[0].incrementFrameCounter();
|
||||
//model.setAnimation(animations[0]);
|
||||
}
|
||||
window.setDrawingState(RAY::Window::DRAWING);
|
||||
if (RAY::Controller::Keyboard::isReleased(KEY_LEFT))
|
||||
{
|
||||
animationIndex = --animationIndex % animations.getAnimationsCount();
|
||||
model.setAnimation(animations[animationIndex]);
|
||||
}
|
||||
if (RAY::Controller::Keyboard::isReleased(KEY_RIGHT))
|
||||
{
|
||||
animationIndex = ++animationIndex % animations.getAnimationsCount();
|
||||
model.setAnimation(animations[animationIndex]);
|
||||
}
|
||||
// window.setDrawingState(RAY::Window::DRAWING);
|
||||
window.clear();
|
||||
window.useCamera(camera);
|
||||
window.draw(model, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 5.0f, 5.0f, 5.0f ));
|
||||
|
||||
window.draw(model);
|
||||
|
||||
window.draw(grid);
|
||||
window.draw(circle);
|
||||
window.unuseCamera();
|
||||
window.draw(instructionText);
|
||||
window.setDrawingState(RAY::Window::IDLE);
|
||||
// window.setDrawingState(RAY::Window::IDLE);
|
||||
}
|
||||
*/
|
||||
// window.close();
|
||||
window.close();
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||