X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fmain.cc;h=50eea418a7b8aff72e0c93ff0986feba69e5f041;hb=fcd6773bc770425ede4b47a84eef7cc78342542c;hp=dc3440d8cb72359ce54f46dccd31658d464de52b;hpb=7a8a3e835aa4fefb930b843466db1566621e1fbe;p=demo diff --git a/src/main.cc b/src/main.cc index dc3440d..50eea41 100644 --- a/src/main.cc +++ b/src/main.cc @@ -3,9 +3,14 @@ #include #include -#include "object.h" +#include "global.h" + +/* TODO: fix those */ +#include "camera.h" #include "mesh.h" +#include "object.h" #include "scene.h" +#include "shader_manager.h" #include "opengl/opengl.h" #include "vulkan/vk.h" @@ -18,12 +23,25 @@ static void display(); /* glfw callbacks */ static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods); +static void motion_clbk(GLFWwindow *win, double x, double y); +static void mouse_clbk(GLFWwindow *win, int button, int action, int mods); /* global variables */ bool use_vulkan; + GLFWwindow *win; +int win_w = 800; +int win_h = 600; + +OrbitCamera *camera; +ShaderManager *sdr_man; /* variables */ +static float phi = 25; +static float theta = 0; +static float dist = 4; + +// TODO: remove just for test: static Scene scene; int main(int argc, char **argv) @@ -48,6 +66,8 @@ int main(int argc, char **argv) } glfwSetKeyCallback(win, key_clbk); + glfwSetCursorPosCallback(win, motion_clbk); + glfwSetMouseButtonCallback(win, mouse_clbk); while(!glfwWindowShouldClose(win)) { display(); @@ -62,6 +82,13 @@ int main(int argc, char **argv) static bool init() { + /* TODO */ + /* + TODO changes: + 1- create cam + 2- scene + 3- renderers + */ if(use_vulkan) { if(!init_vulkan()) return false; @@ -71,6 +98,11 @@ static bool init() return false; } + sdr_man = new ShaderManager; + + camera = new OrbitCamera; + camera->set_orbit_params(phi, theta, dist); + if(!scene.load("data/spot/spot_control_mesh.obj")) { fprintf(stderr, "Failed to load scene.\n"); return false; @@ -88,6 +120,9 @@ static bool init() static void cleanup() { + delete sdr_man; + delete camera; + if(use_vulkan) { cleanup_vulkan(); } @@ -103,6 +138,41 @@ static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mod } } +static double prev_x, prev_y; +static int button; + +static void motion_clbk(GLFWwindow *win, double x, double y) +{ + switch(button) { + case GLFW_MOUSE_BUTTON_LEFT: + theta += x - prev_x; + phi += y - prev_y; + + if(phi < -90) + phi = -90; + if(phi > 90) + phi = 90; + + break; + + case GLFW_MOUSE_BUTTON_RIGHT: + dist *= (y - prev_y) * 0.01 + 1; + if(dist < 0.0) { + dist = 0.0; + } + break; + } + + prev_x = x; + prev_y = y; +} + +static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods) +{ + button = bn; + glfwGetCursorPos(win, &prev_x, &prev_y); +} + static void display() { if(use_vulkan) { @@ -110,5 +180,6 @@ static void display() } else { display_opengl(); + scene.objects[0]->mesh->draw(); } -} +} \ No newline at end of file