diff --git a/bin/LivePlotter.exp b/bin/LivePlotter.exp index f369791..f37678f 100644 Binary files a/bin/LivePlotter.exp and b/bin/LivePlotter.exp differ diff --git a/bin/LivePlotter.lib b/bin/LivePlotter.lib index d9febab..ed8983b 100644 --- a/bin/LivePlotter.lib +++ b/bin/LivePlotter.lib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:720a87c22d2acdb782341eea896fadec28cb3485f71026f37efab264e8702229 +oid sha256:d3493c95ff50fb289d73875d4c862070cb134cce84349bd9c802dfd7aa500d41 size 2986 diff --git a/compile_commands.json b/compile_commands.json index 7fc0065..fca3073 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,8 +1,8 @@ [ -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/body.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/body.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/camera.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/camera.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/demo/demo.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/demo/demo.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/live_plotter.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/live_plotter.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/shaders.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/shaders.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/util.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/util.cpp" }, +{ "directory": "C:/Users/seth/Documents/repos/LivePlotter", "command": "cl src/body.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/body.cpp" }, +{ "directory": "C:/Users/seth/Documents/repos/LivePlotter", "command": "cl src/camera.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/camera.cpp" }, +{ "directory": "C:/Users/seth/Documents/repos/LivePlotter", "command": "cl src/demo/demo.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/demo/demo.cpp" }, +{ "directory": "C:/Users/seth/Documents/repos/LivePlotter", "command": "cl src/live_plotter.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/live_plotter.cpp" }, +{ "directory": "C:/Users/seth/Documents/repos/LivePlotter", "command": "cl src/shaders.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/shaders.cpp" }, +{ "directory": "C:/Users/seth/Documents/repos/LivePlotter", "command": "cl src/util.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/util.cpp" }, ] diff --git a/demo.gif b/demo.gif new file mode 100644 index 0000000..0711527 Binary files /dev/null and b/demo.gif differ diff --git a/ext/glfw b/ext/glfw index 8e15281..63a7e8b 160000 --- a/ext/glfw +++ b/ext/glfw @@ -1 +1 @@ -Subproject commit 8e15281d34a8b9ee9271ccce38177a3d812456f8 +Subproject commit 63a7e8b7f82497b0459acba5c1ce7f39aa2bc0e8 diff --git a/inc/body.hpp b/inc/body.hpp index 9214bc9..7507b7d 100644 --- a/inc/body.hpp +++ b/inc/body.hpp @@ -25,4 +25,4 @@ struct Body { bool load_body(Body* out_body, std::string filepath); void draw_body(const Body& b); -void create_new_sphere(Body* b, float scale=1.0f); +void create_new_sphere(Body* b, float scale, glm::vec4 color); diff --git a/src/body.cpp b/src/body.cpp index e4c4db4..db4ca64 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -69,9 +69,10 @@ void draw_body(const Body& b) { glDrawElements(GL_TRIANGLES, b.data.faces_len, GL_UNSIGNED_INT, 0); } -void create_new_sphere(Body* b, float scale) { +void create_new_sphere(Body* b, float scale, glm::vec4 color) { assert(load_body(b, "Icosphere.obj")); b->scale = scale; + b->color = color; } // I need to write a good obj file parser at some point. This is basically garbage diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index 6b4a03f..67aae0d 100644 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -58,40 +59,35 @@ int main() { } start(800, 800); - pointid id = create_point(0, 0, 0); - set_color(id, 1, 1, 1); - set_scale(id, 10); - while (true) - ; - - //for (int i = 0; i < camera_pose_axes.size(); i++) { - // glm::vec3 p = camera_pose_axes[i][0]; - // glm::vec3 color = camera_pose_axes[i][1]; - // pointid id = create_point(p.x, p.y, p.z); - // set_color(id, color.x, color.y, color.z); - // set_scale(id, 10); - //} + for (int i = 0; i < camera_pose_axes.size(); i++) { + glm::vec3 p = camera_pose_axes[i][0]; + glm::vec3 color = camera_pose_axes[i][1]; + pointid id = create_point(p.x, p.y, p.z); + set_color(id, color.x, color.y, color.z); + set_scale(id, 10); + } - //while (true) { - // string line; - // getline(cin, line); - // vector words = split_str(line, ' '); - // if (!words.size() == 4) - // return NULL; - // printf("Received: %s, %s, %s, %s\n", words[0].c_str(), words[1].c_str(), words[2].c_str(), - // words[3].c_str()); // echo for debugging - // string name = words[0]; - // float x = stof(words[1]); - // float y = stof(words[2]); - // float z = stof(words[3]); + while (true) { + string line; + getline(cin, line); + vector words = split_str(line, ' '); + if (words.size() != 4) + return NULL; + printf("Received: %s, %s, %s, %s\n", words[0].c_str(), words[1].c_str(), words[2].c_str(), - // if (auto it = name_to_id.find(name); it != name_to_id.end()) { - // update_point(it->second, x, y, z); - // } else { - // name_to_id[name] = create_point(x, y, z); - // set_lifetime(name_to_id[name], 0.2); - // set_scale(name_to_id[name], 15); - // } - //} + words[3].c_str()); // echo for debugging + string name = words[0]; + float x = stof(words[1]); + float y = stof(words[2]); + float z = stof(words[3]); + + if (auto it = name_to_id.find(name); it != name_to_id.end()) { + update_point(it->second, x, y, z); + } else { + name_to_id[name] = create_point(x, y, z); + set_lifetime(name_to_id[name], 0.2); + set_scale(name_to_id[name], 15); + } + } } diff --git a/src/live_plotter.cpp b/src/live_plotter.cpp index 17255dc..5bd612a 100644 --- a/src/live_plotter.cpp +++ b/src/live_plotter.cpp @@ -138,7 +138,6 @@ extern DllExport pointid __cdecl create_point(float x, float y, float z) { }; point_buf[slot].b.scale = 1.0f; point_buf[slot].b.color = glm::vec4(randf() + 0.1, randf() + 0.1, randf() + 0.1, 1); - unlock(m); return slot; } @@ -208,9 +207,9 @@ void _scroll_cb(GLFWwindow* win, double xoffset, double yoffset) { zoom_camera(c DWORD _win_thread(LPVOID args) { glm::vec2* winsize = (glm::vec2*)args; - camera = make_camera({ 0, 0, 0 }, 10); - camera.theta = glm::radians(0.0f); - camera.phi = glm::radians(0.0f); + camera = make_camera({ 182.20, -787.72, -817.17 }, 2720); + camera.theta = 4.96; + camera.phi = 0.842; viewport = make_viewport(winsize->x, winsize->y, 45.0f); if (!_glfw_setup()) { printf("Failed to initialize glfw window\n"); @@ -237,6 +236,7 @@ DWORD _win_thread(LPVOID args) { printf("Failed to compile shaders\n"); return -1; } + use_shader(shader); // This swapping bit is probably unnecessary now that I clear in the loop. // I was getting a flashing issue during the tutorial... @@ -274,7 +274,6 @@ bool _glfw_setup() { glfwSetMouseButtonCallback(win, _mouse_button_cb); glfwSetScrollCallback(win, _scroll_cb); - _cursor_pos_cb(win, 0, 0); return true; } @@ -284,11 +283,6 @@ void _refresh_win() { set_uniform(shader, "camera_t", world_to_camera(camera)); set_uniform(shader, "projection_t", camera_to_projection(viewport)); - /*glm::mat4 cam = world_to_camera(camera); - glm::mat4 view = camera_to_projection(viewport); - glUniformMatrix4fv(glGetUniformLocation(shader, "camera_t"), 1, GL_FALSE, glm::value_ptr(cam)); - glUniformMatrix4fv(glGetUniformLocation(shader, "projection_t"), 1, GL_FALSE, glm::value_ptr(view));*/ - if (trylock(m)) { for (int i = 0; i < point_buf_len; i++) { Point &p = point_buf[i]; @@ -296,7 +290,7 @@ void _refresh_win() { // Initialize if not done so yet if (!p.initialized) { - create_new_sphere(&p.b, p.b.scale); + create_new_sphere(&p.b, p.b.scale, p.b.color); p.b.shader = shader; p.b.pose = glm::translate(glm::mat4(1), p.startloc); p.initialized = true; diff --git a/src/util.cpp b/src/util.cpp index cb45249..319fa87 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -41,4 +41,4 @@ glm::mat4 quat_to_mat4(glm::quat q) { return glm::mat4(col0, col1, col2, col3); } -float randf() { return (float)rand() / (float)RAND_MAX; } +float randf() { return (float)abs(rand()) / (float)RAND_MAX; } diff --git a/tester.py b/tester.py index a4fc1df..9fb06cb 100644 --- a/tester.py +++ b/tester.py @@ -3,10 +3,10 @@ import subprocess from pathlib import Path import time -p = subprocess.Popen(Path("bin", "x64", "Debug", "LivePlotter.exe"), stdin=subprocess.PIPE) +p = subprocess.Popen(Path("bin", "demo.exe"), cwd="bin", stdin=subprocess.PIPE) lines = None -with open("gpoints_rotate.obj", "r") as f: +with open("assets/gpoints_rotate.obj", "r") as f: lines = f.readlines() period = 0.01