Reformat tuple into a struct.
This commit is contained in:
@@ -120,11 +120,9 @@ void draw_body(const Body& b) {
|
||||
set_uniform(b.shader, "color", b.color);
|
||||
glBindVertexArray(b.vao);
|
||||
glDrawElements(GL_TRIANGLES, b.faces.len, GL_UNSIGNED_INT, 0);
|
||||
//glDisableVertexAttribArray(0);
|
||||
}
|
||||
|
||||
void create_new_sphere(Body* b, float scale) {
|
||||
assert(load_body(b, "Icosphere.obj"));
|
||||
b->scale = scale;
|
||||
b->pose = glm::translate(b->pose, glm::vec3(0, 0, 0));
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ bool parse_poses(Array<Body>* bodies_out, const char* filepath) {
|
||||
b.pose = pose * glm::translate(b.pose, trans);
|
||||
b.color = glm::vec4(i == 0 ? 1 : 0, i == 1 ? 1 : 0, i == 2 ? 1 : 0, 1);
|
||||
b.scale = 3;
|
||||
printf("%d, ", camera_i * 3 * NUM_SPHERES_PER_AXE + i * NUM_SPHERES_PER_AXE + j);
|
||||
bodies_out->data[camera_i*3*NUM_SPHERES_PER_AXE + i*NUM_SPHERES_PER_AXE + j] = b;
|
||||
}
|
||||
}
|
||||
|
||||
53
src/main.cpp
53
src/main.cpp
@@ -35,11 +35,15 @@ static bool stop = false;
|
||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
const float max_hp
|
||||
= 10; // Number of scans (without a particular barcode) for which the sphere will still be visible
|
||||
static std::vector<std::tuple<char*, Body*, float>>
|
||||
camera_bodies; // I would use my array here, but was getting a linking error
|
||||
|
||||
struct BarcodeRead {
|
||||
char* name;
|
||||
Body* b;
|
||||
float hp;
|
||||
};
|
||||
static std::vector<BarcodeRead> camera_bodies; // I would use my array here, but was getting a linking error
|
||||
|
||||
void* process_cin(void* args) {
|
||||
return NULL;
|
||||
std::string line;
|
||||
while (true) {
|
||||
std::getline(std::cin, line);
|
||||
@@ -53,25 +57,25 @@ void* process_cin(void* args) {
|
||||
bool found_match = false;
|
||||
pthread_mutex_lock(&lock);
|
||||
for (int i = 0; i < camera_bodies.size(); i++) {
|
||||
if (strcmp(words[0], std::get<0>(camera_bodies[i])) == 0 && std::get<1>(camera_bodies[i])) {
|
||||
glm::vec4& transl = std::get<1>(camera_bodies[i])->pose[3];
|
||||
transl = 0.9f * transl + 0.1f * glm::vec4(new_loc, 1); // filter
|
||||
|
||||
if (strcmp(words[0], camera_bodies[i].name) == 0 && camera_bodies[i].b) {
|
||||
Body& b = *camera_bodies[i].b;
|
||||
glm::vec4& transl = b.pose[3];
|
||||
transl = 0.9f * transl + 0.1f * glm::vec4(new_loc, 1); // lp filter
|
||||
int color_i = i + 1;
|
||||
std::get<1>(camera_bodies[i])->color
|
||||
= glm::vec4(color_i & 0x4, color_i & 0x2, color_i & 0x1, 1);
|
||||
std::get<2>(camera_bodies[i]) = max_hp;
|
||||
b.color = glm::vec4(color_i & 0x4, color_i & 0x2, color_i & 0x1, 1); // reset alpha to 1
|
||||
b.pose = glm::translate(b.pose, glm::vec3(transl));
|
||||
camera_bodies[i].hp = max_hp;
|
||||
found_match = true;
|
||||
} else if (std::get<1>(camera_bodies[i])) {
|
||||
float& cur_hp = std::get<2>(camera_bodies[i]);
|
||||
} else if (camera_bodies[i].b) {
|
||||
float& cur_hp = camera_bodies[i].hp;
|
||||
if (cur_hp > 0)
|
||||
cur_hp -= 1;
|
||||
std::get<1>(camera_bodies[i])->color = glm::vec4(i & 0x4, i & 0x2, i & 0x1, cur_hp / max_hp);
|
||||
camera_bodies[i].b->color = glm::vec4(i & 0x4, i & 0x2, i & 0x1, cur_hp / max_hp);
|
||||
}
|
||||
}
|
||||
if (!found_match) {
|
||||
auto t = std::make_tuple(words[0], (Body*)NULL, max_hp);
|
||||
camera_bodies.push_back(t);
|
||||
auto read = BarcodeRead { words[0], (Body*)NULL, max_hp };
|
||||
camera_bodies.push_back(read);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
@@ -84,8 +88,8 @@ static double prev_cursor_x, prev_cursor_y;
|
||||
static double theta = 0.0; // angle of camera trans vect wrt x-z plane
|
||||
static double phi = glm::radians(270.0); // angle of camera trans vect wrt x-axis
|
||||
|
||||
static glm::vec3 focal_point = glm::vec3(0, 0, 0);
|
||||
static glm::vec3 camera_loc = glm::vec3(0, 0, -1);
|
||||
static glm::vec3 focal_point = glm::vec3(0, 0, 500);
|
||||
static glm::vec3 camera_loc = glm::vec3(0, 4000, 0);
|
||||
static glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
static glm::mat4 world_to_camera = glm::lookAt(camera_loc, focal_point, up);
|
||||
|
||||
@@ -111,7 +115,7 @@ static void cursor_position_callback(GLFWwindow* window, double xpos, double ypo
|
||||
}
|
||||
|
||||
if (scroll_pressed) {
|
||||
glm::vec4 move_vec = (float)len * (- strafe_x * (dx / 500) + strafe_y * (dy / 500));
|
||||
glm::vec4 move_vec = glm::max((float)len, 20.0f) * (- strafe_x * (dx / 500) + strafe_y * (dy / 500));
|
||||
focal_point += move_vec;
|
||||
camera_loc += move_vec;
|
||||
}
|
||||
@@ -203,11 +207,11 @@ int main() {
|
||||
camera_pose_axes[i].shader = shader;
|
||||
}
|
||||
|
||||
Body b;
|
||||
/*Body b;
|
||||
create_new_sphere(&b);
|
||||
b.pose = glm::mat4(1);
|
||||
b.color = glm::vec4(1, 1, 1, 1);
|
||||
b.shader = shader;
|
||||
b.shader = shader;*/
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
process_input();
|
||||
@@ -215,7 +219,7 @@ int main() {
|
||||
set_uniform(shader, "camera_t", world_to_camera);
|
||||
set_uniform(shader, "projection_t", projection_t);
|
||||
|
||||
draw_body(b);
|
||||
//draw_body(b);
|
||||
|
||||
for (int i = 0; i < camera_pose_axes.len; i++) {
|
||||
draw_body(camera_pose_axes[i]);
|
||||
@@ -223,13 +227,14 @@ int main() {
|
||||
|
||||
if (pthread_mutex_trylock(&lock) == 0) {
|
||||
for (int i = 0; i < camera_bodies.size(); i++) {
|
||||
if (!std::get<1>(camera_bodies[i])) {
|
||||
if (!camera_bodies[i].b) {
|
||||
Body* b = (Body*)malloc(sizeof(Body));
|
||||
create_new_sphere(b);
|
||||
b->color = glm::vec4((i+1) & 0x4, (i+1) & 0x2, (i+1) & 0x1, max_hp);
|
||||
std::get<1>(camera_bodies[i]) = b;
|
||||
b->scale = 20;
|
||||
camera_bodies[i].b = b;
|
||||
}
|
||||
draw_body(*std::get<1>(camera_bodies[i]));
|
||||
draw_body(*camera_bodies[i].b);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
|
||||
29
tester.py
29
tester.py
@@ -1,23 +1,22 @@
|
||||
import time
|
||||
import numpy as np
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
p = subprocess.Popen(Path("bin", "x64", "Debug", "LivePlotter.exe"), stdin=subprocess.PIPE)
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
z = 0
|
||||
t = 0
|
||||
period = 0.1
|
||||
while True:
|
||||
lines = None
|
||||
with open("gpoints_rotate.obj", "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
period = 0.25
|
||||
|
||||
for i in range(len(lines)):
|
||||
time.sleep(period)
|
||||
x = 10*np.cos(t)
|
||||
y = 10*np.sin(t)
|
||||
z = 0
|
||||
t += period
|
||||
p.stdin.write(f"test {x} {y} {z}\n".encode("utf8"))
|
||||
p.stdin.write(f"test2 {x} {-y} {z}\n".encode("utf8"))
|
||||
p.stdin.write(f"test3 {-x} {y} {z}\n".encode("utf8"))
|
||||
p.stdin.write(f"test4 {-x} {-y} {z}\n".encode("utf8"))
|
||||
words = lines[i].split()
|
||||
x = words[1]
|
||||
y = words[2]
|
||||
z = words[3]
|
||||
name = "".join(words[4:])
|
||||
p.stdin.write(f"{name} {x} {y} {z}\n".encode("utf8"))
|
||||
p.stdin.flush()
|
||||
|
||||
Reference in New Issue
Block a user