added models and stuff
This commit is contained in:
63
src/main.cpp
63
src/main.cpp
@@ -7,6 +7,8 @@
|
||||
#include "glm/ext/matrix_clip_space.hpp"
|
||||
#include "glm/ext/matrix_transform.hpp"
|
||||
|
||||
#include "entt/entt.hpp"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "FreeCamera.h"
|
||||
#include "InputManager.h"
|
||||
@@ -32,6 +34,8 @@ float gMouseSensitivity = 0.1f;
|
||||
|
||||
FreeCamera gCamera {};
|
||||
|
||||
entt::registry gRegistry{};
|
||||
|
||||
void glfw_error_callback(int error, const char* description);
|
||||
void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
void glfw_framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
@@ -42,6 +46,8 @@ void load_gl();
|
||||
void init_camera();
|
||||
void load_default_textures();
|
||||
void load_shaders();
|
||||
void load_inputs();
|
||||
void load_default_models();
|
||||
void loop();
|
||||
|
||||
std::shared_ptr<Model> load_model(std::string_view _path);
|
||||
@@ -67,18 +73,9 @@ int main() {
|
||||
|
||||
load_shaders();
|
||||
|
||||
InputManager::generate_input_action("move_forward", {{GLFW_KEY_W, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_backward", {{GLFW_KEY_S, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_right", {{GLFW_KEY_D, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_left", {{GLFW_KEY_A, KEY_DOWN}});
|
||||
load_inputs();
|
||||
|
||||
InputManager::generate_input_action("exit_application", {{GLFW_KEY_ESCAPE, KEY_DOWN}});
|
||||
|
||||
spdlog::info("loading models");
|
||||
ModelManager::models["cube"] = ModelManager::load_from_file("./resources/cube.obj");
|
||||
ModelManager::models["backpack"] = ModelManager::load_from_file("./resources/backpack/backpack.obj");
|
||||
ModelManager::models["male"] = ModelManager::load_from_file("./resources/male.obj");
|
||||
spdlog::info("done");
|
||||
load_default_models();
|
||||
|
||||
loop();
|
||||
|
||||
@@ -132,7 +129,9 @@ void create_main_window()
|
||||
|
||||
glfwSetFramebufferSizeCallback(gWindow, glfw_framebuffer_size_callback);
|
||||
|
||||
#ifndef GLFW_CONTEXT_DEBUG
|
||||
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
#endif
|
||||
}
|
||||
|
||||
void load_gl()
|
||||
@@ -183,19 +182,33 @@ void load_shaders() {
|
||||
}
|
||||
}
|
||||
|
||||
void load_inputs() {
|
||||
InputManager::generate_input_action("move_forward", {{GLFW_KEY_W, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_backward", {{GLFW_KEY_S, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_right", {{GLFW_KEY_D, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_left", {{GLFW_KEY_A, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_up", {{GLFW_KEY_SPACE, KEY_DOWN}});
|
||||
InputManager::generate_input_action("move_down", {{GLFW_KEY_LEFT_SHIFT, KEY_DOWN}});
|
||||
InputManager::generate_input_action("exit_application", {{GLFW_KEY_ESCAPE, KEY_DOWN}});
|
||||
}
|
||||
|
||||
void load_default_models() {
|
||||
spdlog::info("loading default models");
|
||||
ModelManager::models["cube"] = ModelManager::load_from_file("./resources/cube.obj");
|
||||
ModelManager::models["vette"] = ModelManager::load_from_file("./resources/c4/C4Fixed.obj");
|
||||
ModelManager::models["male"] = ModelManager::load_from_file("./resources/male.obj");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
std::shared_ptr<Texture> defaultDiffuse = TextureManager::textures["default_diffuse"];
|
||||
std::shared_ptr<Texture> defaultSpecular = TextureManager::textures["default_specular"];
|
||||
std::shared_ptr<ShaderProgram> shader = ShaderManager::shaders["phong_shader"];
|
||||
|
||||
const auto vette = ModelManager::models["vette"];
|
||||
auto model = glm::identity<glm::mat4>();
|
||||
model = glm::scale(model, glm::vec3(.1f, .1f, .1f));
|
||||
|
||||
ShaderProgram* shader = ShaderManager::shaders["phong_shader"].get();
|
||||
|
||||
const auto cube = ModelManager::models["cube"];
|
||||
const auto backpack = ModelManager::models["backpack"];
|
||||
const auto male = ModelManager::models["male"];
|
||||
|
||||
const auto& activeModel = backpack;
|
||||
const auto& activeModel = vette;
|
||||
|
||||
while (!glfwWindowShouldClose(gWindow)) {
|
||||
glfwPollEvents();
|
||||
@@ -222,6 +235,14 @@ void loop() {
|
||||
gCamera.move(CAMERA_MOVEMENT::RIGHT, .05);
|
||||
}
|
||||
|
||||
if (InputManager::check_action_performed("move_up")) {
|
||||
gCamera.move(CAMERA_MOVEMENT::UP, .05);
|
||||
}
|
||||
|
||||
if (InputManager::check_action_performed("move_down")) {
|
||||
gCamera.move(CAMERA_MOVEMENT::DOWN, .05);
|
||||
}
|
||||
|
||||
// gl frame prep
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -237,18 +258,18 @@ void loop() {
|
||||
shader->setVec3("viewPosition", gCamera.position());
|
||||
|
||||
shader->setVec3("lightPosition", glm::vec3{-2.f, 0, 2.0f});
|
||||
shader->setVec3("lightDirection", glm::vec3(1, -1, -1));
|
||||
shader->setVec3("lightDirection", glm::vec3(1, -1, 1));
|
||||
shader->setVec3("lightAmbient", glm::vec3(0.3f, 0.3f, 0.3f));
|
||||
shader->setVec3("lightDiffuse", glm::vec3(0.5f, 0.5f, 0.5f));
|
||||
shader->setVec3("lightSpecular", glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
|
||||
for (const auto& mesh: activeModel->meshes) {
|
||||
unsigned int materialId = mesh->materialId;
|
||||
unsigned int materialId = 0;
|
||||
if (materialId >= activeModel->materials.size()) {
|
||||
materialId = 0;
|
||||
}
|
||||
|
||||
const std::shared_ptr<Material> mat = activeModel->materials[1];
|
||||
const std::shared_ptr<Material> mat = activeModel->materials[materialId];
|
||||
|
||||
shader->setVec3("phongAmbient", mat->phong.ambient);
|
||||
shader->setVec3("phongDiffuse", mat->phong.diffuse);
|
||||
|
||||
Reference in New Issue
Block a user