raylib: remove rl namespace
This will allow us to use rlImGUI
This commit is contained in:
@@ -1,26 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
namespace rl {
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
}
|
|
||||||
|
|
||||||
namespace Ley {
|
namespace Ley {
|
||||||
|
|
||||||
class Model {
|
class cModel {
|
||||||
private:
|
private:
|
||||||
Model(const std::string &obj_path, const std::string &texture_path);
|
cModel(const std::string &obj_path, const std::string &texture_path);
|
||||||
public:
|
public:
|
||||||
static Model create(const std::string &obj_path, const std::string &texture_path);
|
static cModel create(const std::string &obj_path, const std::string &texture_path);
|
||||||
~Model();
|
~cModel();
|
||||||
void setPosition(rl::Vector3 position) { _position = position; }
|
void setPosition(Vector3 position) { _position = position; }
|
||||||
rl::Vector3 getPosition() const { return _position; }
|
Vector3 getPosition() const { return _position; }
|
||||||
rl::Model getModel() const { return _model; }
|
Model getModel() const { return _model; }
|
||||||
void Draw(rl::Color color) const { rl::DrawModel(_model, _position, 1.0f, color); }
|
void Draw(Color color) const { DrawModel(_model, _position, 1.0f, color); }
|
||||||
private:
|
private:
|
||||||
rl::Model _model;
|
Model _model;
|
||||||
rl::Texture2D _texture;
|
Texture2D _texture;
|
||||||
rl::Vector3 _position;
|
Vector3 _position;
|
||||||
std::string _obj_path;
|
std::string _obj_path;
|
||||||
std::string _texture_path;
|
std::string _texture_path;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,26 +4,26 @@
|
|||||||
|
|
||||||
namespace Ley {
|
namespace Ley {
|
||||||
|
|
||||||
Model::Model(const std::string &obj, const std::string &texture) {
|
cModel::cModel(const std::string &obj, const std::string &texture) {
|
||||||
std::filesystem::path asset_path("assets");
|
std::filesystem::path asset_path("assets");
|
||||||
std::filesystem::path obj_path(obj);
|
std::filesystem::path obj_path(obj);
|
||||||
_obj_path = to_utf8(asset_path / obj_path);
|
_obj_path = to_utf8(asset_path / obj_path);
|
||||||
_model = rl::LoadModel(_obj_path.c_str());
|
_model = LoadModel(_obj_path.c_str());
|
||||||
std::filesystem::path texture_path(texture);
|
std::filesystem::path texture_path(texture);
|
||||||
_texture_path = to_utf8(asset_path / texture_path);
|
_texture_path = to_utf8(asset_path / texture_path);
|
||||||
_texture = rl::LoadTexture(_texture_path.c_str());
|
_texture = LoadTexture(_texture_path.c_str());
|
||||||
_model.materials[0].maps[rl::MATERIAL_MAP_DIFFUSE].texture = _texture;
|
_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = _texture;
|
||||||
_position = {0.0f, 0.0f, 0.0f};
|
_position = {0.0f, 0.0f, 0.0f};
|
||||||
}
|
}
|
||||||
|
|
||||||
Model::~Model() {
|
cModel::~cModel() {
|
||||||
rl::UnloadTexture(_texture);
|
UnloadTexture(_texture);
|
||||||
rl::UnloadModel(_model);
|
UnloadModel(_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
Model Model::create(const std::string &obj_path,
|
cModel cModel::create(const std::string &obj_path,
|
||||||
const std::string &texture_path) {
|
const std::string &texture_path) {
|
||||||
return Model(obj_path, texture_path);
|
return cModel(obj_path, texture_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Ley
|
} // namespace Ley
|
||||||
|
|||||||
@@ -15,54 +15,52 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <imgui.h>
|
||||||
namespace rl {
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
} // namespace rl
|
|
||||||
|
|
||||||
int main(int ac, char **av) {
|
int main(int ac, char **av) {
|
||||||
rl::InitWindow(1920, 1080, &av[0][2]);
|
InitWindow(1920, 1080, &av[0][2]);
|
||||||
|
|
||||||
// Initializing a camera
|
// Initializing a camera
|
||||||
rl::Camera camera = {0};
|
Camera camera = {0};
|
||||||
camera.position = (rl::Vector3){1.0f, 10.0f, 1.0f};
|
camera.position = (Vector3){1.0f, 10.0f, 1.0f};
|
||||||
camera.target = (rl::Vector3){0.0f, 10.0f, 0.0f};
|
camera.target = (Vector3){0.0f, 10.0f, 0.0f};
|
||||||
camera.up = (rl::Vector3){0.0f, 1.0f, 0.0f};
|
camera.up = (Vector3){0.0f, 1.0f, 0.0f};
|
||||||
camera.fovy = 90.0f;
|
camera.fovy = 90.0f;
|
||||||
camera.projection = rl::CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
{ // model lifetime scope
|
{ // model lifetime scope
|
||||||
auto can_model = Ley::Model::create("can.obj", "can_unwrapped_text.png");
|
auto can_model = Ley::cModel::create("can.obj", "can_unwrapped_text.png");
|
||||||
auto crow_model = Ley::Model::create("crow.obj", "crow_tex.png");
|
auto crow_model = Ley::cModel::create("crow.obj", "crow_tex.png");
|
||||||
|
|
||||||
// rl::Model pos
|
// Model pos
|
||||||
can_model.setPosition({0.0f, 0.0f, 0.0f});
|
can_model.setPosition({0.0f, 0.0f, 0.0f});
|
||||||
crow_model.setPosition({-0.5f, 3.8f, 0.0f});
|
crow_model.setPosition({-0.5f, 3.8f, 0.0f});
|
||||||
|
|
||||||
rl::BoundingBox box = rl::GetModelBoundingBox(can_model.getModel());
|
BoundingBox box = GetModelBoundingBox(can_model.getModel());
|
||||||
|
|
||||||
rl::DisableCursor();
|
DisableCursor();
|
||||||
|
|
||||||
while (!rl::WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
// Update
|
// Update
|
||||||
UpdateCamera(&camera, rl::CAMERA_FREE);
|
UpdateCamera(&camera, CAMERA_FREE);
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
rl::BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(rl::GRAY);
|
ClearBackground(GRAY);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
can_model.Draw(rl::WHITE);
|
can_model.Draw(WHITE);
|
||||||
crow_model.Draw(rl::WHITE);
|
crow_model.Draw(WHITE);
|
||||||
|
|
||||||
rl::DrawGrid(20, 10.0f); // Draw a grid
|
DrawGrid(20, 10.0f); // Draw a grid
|
||||||
|
|
||||||
rl::EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
rl::DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
rl::EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
} // Unload model
|
} // Unload model
|
||||||
rl::CloseWindow();
|
CloseWindow();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user