X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fmain.cc;h=4e6677adbe09132acd32c9cc8c8bd65e3ce0ef4b;hb=0da7a98f74d00bfa6cf0d47fd7cf0f687eeba5f6;hp=2926420e0280f8954b4d237917b3807ade77c245;hpb=64e2adbbab48320b6cd792e515b44cea112a3be4;p=demo diff --git a/src/main.cc b/src/main.cc index 2926420..4e6677a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -3,6 +3,12 @@ #include #include +/* TODO: fix those */ +#include "camera.h" +#include "mesh.h" +#include "object.h" +#include "scene.h" + #include "opengl/opengl.h" #include "vulkan/vk.h" @@ -14,12 +20,21 @@ 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; + +Camera *camera; /* variables */ +// TODO: remove just for test: +static Scene scene; int main(int argc, char **argv) { @@ -43,6 +58,8 @@ int main(int argc, char **argv) } glfwSetKeyCallback(win, key_clbk); + glfwSetCursorPosCallback(win, motion_clbk); + glfwSetMouseButtonCallback(win, mouse_clbk); while(!glfwWindowShouldClose(win)) { display(); @@ -57,6 +74,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; @@ -66,6 +90,20 @@ static bool init() return false; } + camera = new Camera(25, 25, 4, 45); + + if(!scene.load("data/spot/spot_control_mesh.obj")) { + fprintf(stderr, "Failed to load scene.\n"); + return false; + } + + for(size_t i=0; imesh->name.c_str()); + printf("material: %s\n", scene.objects[i]->material->name.c_str()); + printf("transform:\n"); + scene.objects[i]->transform.print(); + } return true; } @@ -77,6 +115,8 @@ static void cleanup() else { cleanup_opengl(); } + + delete camera; } static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods) @@ -86,6 +126,38 @@ static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mod } } +static double prev_x, prev_y; +static int bnstate[8]; + +static void motion_clbk(GLFWwindow *win, double x, double y) +{ + int dx = x - prev_x; + int dy = y - prev_y; + + prev_x = x; + prev_y = y; + + if(!dx && !dy) return; + + if(bnstate[0]) { + camera->theta += dx * 0.5; + camera->phi += dy * 0.5; + + if(camera->phi < -90) camera->phi = -90; + if(camera->phi > 90) camera->phi = 90; + } + if(bnstate[2]) { + camera->distance += dy * 0.1; + if(camera->distance < 0.0) camera->distance = 0.0; + } +} + +static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods) +{ + bnstate[bn - GLFW_MOUSE_BUTTON_LEFT] = action == GLFW_PRESS ? 1 : 0; + glfwGetCursorPos(win, &prev_x, &prev_y); +} + static void display() { if(use_vulkan) { @@ -94,4 +166,4 @@ static void display() else { display_opengl(); } -} +} \ No newline at end of file