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/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" },
]

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);
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);
}
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

View File

@@ -1,3 +1,4 @@
#include <iostream>
#include <string>
#include <map>
@@ -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<string> 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<string> 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);
}
}
}

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.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;

View File

@@ -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; }

View File

@@ -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