Moving from gitlab
This commit is contained in:
29
srcs/Model.cpp
Normal file
29
srcs/Model.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <FilesystemHelper.hpp>
|
||||
#include <Model.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
namespace Ley {
|
||||
|
||||
Model::Model(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());
|
||||
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;
|
||||
_position = {0.0f, 0.0f, 0.0f};
|
||||
}
|
||||
|
||||
Model::~Model() {
|
||||
rl::UnloadTexture(_texture);
|
||||
rl::UnloadModel(_model);
|
||||
}
|
||||
|
||||
Model Model::create(const std::string &obj_path,
|
||||
const std::string &texture_path) {
|
||||
return Model(obj_path, texture_path);
|
||||
}
|
||||
|
||||
} // namespace Ley
|
||||
68
srcs/main.cpp
Normal file
68
srcs/main.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* / ) */
|
||||
/* main.cpp (\__/) ( ( */
|
||||
/* ) ( ) ) */
|
||||
/* By: lejulien <leo.julien.42@gmail.com> ={ }= / / */
|
||||
/* ) `-------/ / */
|
||||
/* Created: 2023/01/09 12:17:58 by lejulien ( / */
|
||||
/* Updated: 2023/01/14 17:12:27 by lejulien \ | */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include <Model.hpp>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace rl {
|
||||
#include "raylib.h"
|
||||
} // namespace rl
|
||||
|
||||
int main(int ac, char **av) {
|
||||
rl::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.fovy = 90.0f;
|
||||
camera.projection = rl::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");
|
||||
|
||||
// rl::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());
|
||||
|
||||
rl::DisableCursor();
|
||||
|
||||
while (!rl::WindowShouldClose()) {
|
||||
// Update
|
||||
UpdateCamera(&camera, rl::CAMERA_FREE);
|
||||
|
||||
// Draw
|
||||
rl::BeginDrawing();
|
||||
ClearBackground(rl::GRAY);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
can_model.Draw(rl::WHITE);
|
||||
crow_model.Draw(rl::WHITE);
|
||||
|
||||
rl::DrawGrid(20, 10.0f); // Draw a grid
|
||||
|
||||
rl::EndMode3D();
|
||||
|
||||
rl::DrawFPS(10, 10);
|
||||
rl::EndDrawing();
|
||||
}
|
||||
} // Unload model
|
||||
rl::CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user