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