demo worthy. Plenty more work could be done, but not terrible

This commit is contained in:
2025-09-11 13:21:53 -05:00
parent 2821847ce2
commit 6d47b81b1f
11 changed files with 48 additions and 57 deletions

Binary file not shown.

BIN
bin/LivePlotter.lib (Stored with Git LFS)

Binary file not shown.

View File

@@ -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/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/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/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/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/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/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/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/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/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/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/util.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/util.cpp" },
] ]

BIN
demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 KiB

View File

@@ -25,4 +25,4 @@ struct Body {
bool load_body(Body* out_body, std::string filepath); bool load_body(Body* out_body, std::string filepath);
void draw_body(const Body& b); 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);

View File

@@ -69,9 +69,10 @@ void draw_body(const Body& b) {
glDrawElements(GL_TRIANGLES, b.data.faces_len, GL_UNSIGNED_INT, 0); 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")); assert(load_body(b, "Icosphere.obj"));
b->scale = scale; b->scale = scale;
b->color = color;
} }
// I need to write a good obj file parser at some point. This is basically garbage // I need to write a good obj file parser at some point. This is basically garbage

View File

@@ -1,3 +1,4 @@
#include <iostream>
#include <string> #include <string>
#include <map> #include <map>
@@ -58,40 +59,35 @@ int main() {
} }
start(800, 800); 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];
//for (int i = 0; i < camera_pose_axes.size(); i++) { pointid id = create_point(p.x, p.y, p.z);
// glm::vec3 p = camera_pose_axes[i][0]; set_color(id, color.x, color.y, color.z);
// glm::vec3 color = camera_pose_axes[i][1]; set_scale(id, 10);
// 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) { while (true) {
// string line; string line;
// getline(cin, line); getline(cin, line);
// vector<string> words = split_str(line, ' '); vector<string> words = split_str(line, ' ');
// if (!words.size() == 4) if (words.size() != 4)
// return NULL; return NULL;
// printf("Received: %s, %s, %s, %s\n", words[0].c_str(), words[1].c_str(), words[2].c_str(), 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]);
// if (auto it = name_to_id.find(name); it != name_to_id.end()) { words[3].c_str()); // echo for debugging
// update_point(it->second, x, y, z); string name = words[0];
// } else { float x = stof(words[1]);
// name_to_id[name] = create_point(x, y, z); float y = stof(words[2]);
// set_lifetime(name_to_id[name], 0.2); float z = stof(words[3]);
// set_scale(name_to_id[name], 15);
// } 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);
}
}
} }

View File

@@ -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.scale = 1.0f;
point_buf[slot].b.color = glm::vec4(randf() + 0.1, randf() + 0.1, randf() + 0.1, 1); point_buf[slot].b.color = glm::vec4(randf() + 0.1, randf() + 0.1, randf() + 0.1, 1);
unlock(m); unlock(m);
return slot; return slot;
} }
@@ -208,9 +207,9 @@ void _scroll_cb(GLFWwindow* win, double xoffset, double yoffset) { zoom_camera(c
DWORD _win_thread(LPVOID args) { DWORD _win_thread(LPVOID args) {
glm::vec2* winsize = (glm::vec2*)args; glm::vec2* winsize = (glm::vec2*)args;
camera = make_camera({ 0, 0, 0 }, 10); camera = make_camera({ 182.20, -787.72, -817.17 }, 2720);
camera.theta = glm::radians(0.0f); camera.theta = 4.96;
camera.phi = glm::radians(0.0f); camera.phi = 0.842;
viewport = make_viewport(winsize->x, winsize->y, 45.0f); viewport = make_viewport(winsize->x, winsize->y, 45.0f);
if (!_glfw_setup()) { if (!_glfw_setup()) {
printf("Failed to initialize glfw window\n"); printf("Failed to initialize glfw window\n");
@@ -237,6 +236,7 @@ DWORD _win_thread(LPVOID args) {
printf("Failed to compile shaders\n"); printf("Failed to compile shaders\n");
return -1; return -1;
} }
use_shader(shader);
// This swapping bit is probably unnecessary now that I clear in the loop. // This swapping bit is probably unnecessary now that I clear in the loop.
// I was getting a flashing issue during the tutorial... // I was getting a flashing issue during the tutorial...
@@ -274,7 +274,6 @@ bool _glfw_setup() {
glfwSetMouseButtonCallback(win, _mouse_button_cb); glfwSetMouseButtonCallback(win, _mouse_button_cb);
glfwSetScrollCallback(win, _scroll_cb); glfwSetScrollCallback(win, _scroll_cb);
_cursor_pos_cb(win, 0, 0); _cursor_pos_cb(win, 0, 0);
return true; return true;
} }
@@ -284,11 +283,6 @@ void _refresh_win() {
set_uniform(shader, "camera_t", world_to_camera(camera)); set_uniform(shader, "camera_t", world_to_camera(camera));
set_uniform(shader, "projection_t", camera_to_projection(viewport)); 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)) { if (trylock(m)) {
for (int i = 0; i < point_buf_len; i++) { for (int i = 0; i < point_buf_len; i++) {
Point &p = point_buf[i]; Point &p = point_buf[i];
@@ -296,7 +290,7 @@ void _refresh_win() {
// Initialize if not done so yet // Initialize if not done so yet
if (!p.initialized) { 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.shader = shader;
p.b.pose = glm::translate(glm::mat4(1), p.startloc); p.b.pose = glm::translate(glm::mat4(1), p.startloc);
p.initialized = true; p.initialized = true;

View File

@@ -41,4 +41,4 @@ glm::mat4 quat_to_mat4(glm::quat q) {
return glm::mat4(col0, col1, col2, col3); return glm::mat4(col0, col1, col2, col3);
} }
float randf() { return (float)rand() / (float)RAND_MAX; } float randf() { return (float)abs(rand()) / (float)RAND_MAX; }

View File

@@ -3,10 +3,10 @@ import subprocess
from pathlib import Path from pathlib import Path
import time 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 lines = None
with open("gpoints_rotate.obj", "r") as f: with open("assets/gpoints_rotate.obj", "r") as f:
lines = f.readlines() lines = f.readlines()
period = 0.01 period = 0.01