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);
|
set_uniform(b.shader, "color", b.color);
|
||||||
glBindVertexArray(b.vao);
|
glBindVertexArray(b.vao);
|
||||||
glDrawElements(GL_TRIANGLES, b.faces.len, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, b.faces.len, GL_UNSIGNED_INT, 0);
|
||||||
//glDisableVertexAttribArray(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_new_sphere(Body* b, float scale) {
|
void create_new_sphere(Body* b, float scale) {
|
||||||
assert(load_body(b, "Icosphere.obj"));
|
assert(load_body(b, "Icosphere.obj"));
|
||||||
b->scale = scale;
|
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.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.color = glm::vec4(i == 0 ? 1 : 0, i == 1 ? 1 : 0, i == 2 ? 1 : 0, 1);
|
||||||
b.scale = 3;
|
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;
|
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;
|
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
const float max_hp
|
const float max_hp
|
||||||
= 10; // Number of scans (without a particular barcode) for which the sphere will still be visible
|
= 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) {
|
void* process_cin(void* args) {
|
||||||
return NULL;
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (true) {
|
while (true) {
|
||||||
std::getline(std::cin, line);
|
std::getline(std::cin, line);
|
||||||
@@ -53,25 +57,25 @@ void* process_cin(void* args) {
|
|||||||
bool found_match = false;
|
bool found_match = false;
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
for (int i = 0; i < camera_bodies.size(); i++) {
|
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])) {
|
if (strcmp(words[0], camera_bodies[i].name) == 0 && camera_bodies[i].b) {
|
||||||
glm::vec4& transl = std::get<1>(camera_bodies[i])->pose[3];
|
Body& b = *camera_bodies[i].b;
|
||||||
transl = 0.9f * transl + 0.1f * glm::vec4(new_loc, 1); // filter
|
glm::vec4& transl = b.pose[3];
|
||||||
|
transl = 0.9f * transl + 0.1f * glm::vec4(new_loc, 1); // lp filter
|
||||||
int color_i = i + 1;
|
int color_i = i + 1;
|
||||||
std::get<1>(camera_bodies[i])->color
|
b.color = glm::vec4(color_i & 0x4, color_i & 0x2, color_i & 0x1, 1); // reset alpha to 1
|
||||||
= glm::vec4(color_i & 0x4, color_i & 0x2, color_i & 0x1, 1);
|
b.pose = glm::translate(b.pose, glm::vec3(transl));
|
||||||
std::get<2>(camera_bodies[i]) = max_hp;
|
camera_bodies[i].hp = max_hp;
|
||||||
found_match = true;
|
found_match = true;
|
||||||
} else if (std::get<1>(camera_bodies[i])) {
|
} else if (camera_bodies[i].b) {
|
||||||
float& cur_hp = std::get<2>(camera_bodies[i]);
|
float& cur_hp = camera_bodies[i].hp;
|
||||||
if (cur_hp > 0)
|
if (cur_hp > 0)
|
||||||
cur_hp -= 1;
|
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) {
|
if (!found_match) {
|
||||||
auto t = std::make_tuple(words[0], (Body*)NULL, max_hp);
|
auto read = BarcodeRead { words[0], (Body*)NULL, max_hp };
|
||||||
camera_bodies.push_back(t);
|
camera_bodies.push_back(read);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&lock);
|
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 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 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 focal_point = glm::vec3(0, 0, 500);
|
||||||
static glm::vec3 camera_loc = glm::vec3(0, 0, -1);
|
static glm::vec3 camera_loc = glm::vec3(0, 4000, 0);
|
||||||
static glm::vec3 up = glm::vec3(0, 1, 0);
|
static glm::vec3 up = glm::vec3(0, 1, 0);
|
||||||
static glm::mat4 world_to_camera = glm::lookAt(camera_loc, focal_point, up);
|
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) {
|
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;
|
focal_point += move_vec;
|
||||||
camera_loc += move_vec;
|
camera_loc += move_vec;
|
||||||
}
|
}
|
||||||
@@ -203,11 +207,11 @@ int main() {
|
|||||||
camera_pose_axes[i].shader = shader;
|
camera_pose_axes[i].shader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
Body b;
|
/*Body b;
|
||||||
create_new_sphere(&b);
|
create_new_sphere(&b);
|
||||||
b.pose = glm::mat4(1);
|
b.pose = glm::mat4(1);
|
||||||
b.color = glm::vec4(1, 1, 1, 1);
|
b.color = glm::vec4(1, 1, 1, 1);
|
||||||
b.shader = shader;
|
b.shader = shader;*/
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
process_input();
|
process_input();
|
||||||
@@ -215,7 +219,7 @@ int main() {
|
|||||||
set_uniform(shader, "camera_t", world_to_camera);
|
set_uniform(shader, "camera_t", world_to_camera);
|
||||||
set_uniform(shader, "projection_t", projection_t);
|
set_uniform(shader, "projection_t", projection_t);
|
||||||
|
|
||||||
draw_body(b);
|
//draw_body(b);
|
||||||
|
|
||||||
for (int i = 0; i < camera_pose_axes.len; i++) {
|
for (int i = 0; i < camera_pose_axes.len; i++) {
|
||||||
draw_body(camera_pose_axes[i]);
|
draw_body(camera_pose_axes[i]);
|
||||||
@@ -223,13 +227,14 @@ int main() {
|
|||||||
|
|
||||||
if (pthread_mutex_trylock(&lock) == 0) {
|
if (pthread_mutex_trylock(&lock) == 0) {
|
||||||
for (int i = 0; i < camera_bodies.size(); i++) {
|
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));
|
Body* b = (Body*)malloc(sizeof(Body));
|
||||||
create_new_sphere(b);
|
create_new_sphere(b);
|
||||||
b->color = glm::vec4((i+1) & 0x4, (i+1) & 0x2, (i+1) & 0x1, max_hp);
|
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);
|
pthread_mutex_unlock(&lock);
|
||||||
}
|
}
|
||||||
|
|||||||
29
tester.py
29
tester.py
@@ -1,23 +1,22 @@
|
|||||||
import time
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import time
|
||||||
|
|
||||||
p = subprocess.Popen(Path("bin", "x64", "Debug", "LivePlotter.exe"), stdin=subprocess.PIPE)
|
p = subprocess.Popen(Path("bin", "x64", "Debug", "LivePlotter.exe"), stdin=subprocess.PIPE)
|
||||||
|
|
||||||
x = 0
|
lines = None
|
||||||
y = 0
|
with open("gpoints_rotate.obj", "r") as f:
|
||||||
z = 0
|
lines = f.readlines()
|
||||||
t = 0
|
|
||||||
period = 0.1
|
period = 0.25
|
||||||
while True:
|
|
||||||
|
for i in range(len(lines)):
|
||||||
time.sleep(period)
|
time.sleep(period)
|
||||||
x = 10*np.cos(t)
|
words = lines[i].split()
|
||||||
y = 10*np.sin(t)
|
x = words[1]
|
||||||
z = 0
|
y = words[2]
|
||||||
t += period
|
z = words[3]
|
||||||
p.stdin.write(f"test {x} {y} {z}\n".encode("utf8"))
|
name = "".join(words[4:])
|
||||||
p.stdin.write(f"test2 {x} {-y} {z}\n".encode("utf8"))
|
p.stdin.write(f"{name} {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"))
|
|
||||||
p.stdin.flush()
|
p.stdin.flush()
|
||||||
|
|||||||
Reference in New Issue
Block a user