adding in the axes for all the camera poses. failing to read the file properly though
This commit is contained in:
79
src/main.cpp
79
src/main.cpp
@@ -15,6 +15,7 @@
|
||||
#include "util.hpp"
|
||||
#include "shaders.hpp"
|
||||
#include "body.hpp"
|
||||
#include "camera_poses.hpp"
|
||||
|
||||
static GLFWwindow* window;
|
||||
static float width, height;
|
||||
@@ -31,7 +32,7 @@ void process_input() {
|
||||
}
|
||||
|
||||
static uint shader;
|
||||
void create_new_sphere(body* b, float scale=1) {
|
||||
void create_new_sphere(Body* b, float scale = 1) {
|
||||
assert(load_body(b, "Icosphere.obj"));
|
||||
b->shader = shader;
|
||||
b->scale = scale;
|
||||
@@ -40,16 +41,18 @@ void create_new_sphere(body* b, float scale=1) {
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
void *process_cin(void* args) {
|
||||
void* process_cin(void* args) {
|
||||
std::string line;
|
||||
while (true) {
|
||||
std::getline(std::cin, line);
|
||||
array<char*> words = split_str(line.c_str());
|
||||
Array<char*> words = split_str(line.c_str());
|
||||
assert(words.len == 4);
|
||||
printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
|
||||
printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
|
||||
float x = atof(words[1]);
|
||||
float y = atof(words[2]);
|
||||
float z = atof(words[3]);
|
||||
@@ -58,21 +61,23 @@ void *process_cin(void* args) {
|
||||
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
|
||||
glm::vec4& transl = std::get<1>(camera_bodies[i])->pose[3];
|
||||
transl = 0.9f * transl + 0.1f * glm::vec4(new_loc, 1); // 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<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;
|
||||
found_match = true;
|
||||
} else if (std::get<1>(camera_bodies[i])) {
|
||||
float &cur_hp = std::get<2>(camera_bodies[i]);
|
||||
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);
|
||||
float& cur_hp = std::get<2>(camera_bodies[i]);
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (!found_match) {
|
||||
auto t = std::make_tuple(words[0], (body*)NULL, max_hp);
|
||||
auto t = std::make_tuple(words[0], (Body*)NULL, max_hp);
|
||||
camera_bodies.push_back(t);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
@@ -91,7 +96,6 @@ static glm::vec3 camera_loc = glm::vec3(0, 0, -1);
|
||||
static glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
static glm::mat4 world_to_camera = glm::lookAt(camera_loc, focal_point, up);
|
||||
|
||||
|
||||
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) {
|
||||
float dx = (xpos - prev_cursor_x);
|
||||
float dy = (ypos - prev_cursor_y);
|
||||
@@ -104,8 +108,8 @@ static void cursor_position_callback(GLFWwindow* window, double xpos, double ypo
|
||||
prev_cursor_y = ypos;
|
||||
|
||||
if (mouse_pressed) {
|
||||
phi += glm::radians(dx * (360/width));// * glm::radians(360.0);
|
||||
theta += glm::radians(dy * (360/height));// * glm::radians(360.0);
|
||||
phi += glm::radians(dx * (360 / width)); // * glm::radians(360.0);
|
||||
theta += glm::radians(dy * (360 / height)); // * glm::radians(360.0);
|
||||
double len = glm::length(camera_loc - focal_point);
|
||||
camera_loc.x = focal_point.x + (len * glm::cos(theta) * glm::cos(-phi));
|
||||
camera_loc.y = focal_point.y + (len * glm::sin(theta));
|
||||
@@ -185,15 +189,9 @@ int main() {
|
||||
glfwSwapBuffers(window); // front buffer is now back
|
||||
glClear(GL_COLOR_BUFFER_BIT); // Write to back buffer again (former front buf)
|
||||
|
||||
body b;
|
||||
assert(load_body(&b, "Icosphere.obj"));
|
||||
b.shader = shader;
|
||||
b.pose = glm::translate(b.pose, glm::vec3(5, 5, 5));
|
||||
b.color = glm::vec4(1, 0, 0, 1);
|
||||
|
||||
body b2;
|
||||
/*Body b2;
|
||||
create_new_sphere(&b2);
|
||||
b2.color = glm::vec4(0, 0.5, 0, 1);
|
||||
b2.color = glm::vec4(0, 0.5, 0, 1);*/
|
||||
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
// set_uniform(shader, "color", glm::vec4 { sin(time), sin(time + glm::radians(45.0f)), sin(time +
|
||||
@@ -208,28 +206,33 @@ int main() {
|
||||
pthread_t thread_id;
|
||||
pthread_create(&thread_id, NULL, process_cin, NULL);
|
||||
|
||||
Array<Body> camera_pose_axes;
|
||||
if (!parse_poses(&camera_pose_axes, "poses.csv")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
process_input();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
set_uniform(shader, "camera_t", world_to_camera);
|
||||
set_uniform(shader, "projection_t", projection_t);
|
||||
|
||||
draw_body(b);
|
||||
draw_body(b2);
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
|
||||
for (int i = 0; i < camera_bodies.size(); i++) {
|
||||
if (!std::get<1>(camera_bodies[i])) {
|
||||
body* b = (body*)malloc(sizeof(body));
|
||||
create_new_sphere(b);
|
||||
b->color = glm::vec4(i & 0x4, i& 0x2, i & 0x1, max_hp);
|
||||
std::get<1>(camera_bodies[i]) = b;
|
||||
}
|
||||
draw_body(*std::get<1>(camera_bodies[i]));
|
||||
for (int i = 0; i < camera_pose_axes.len; i++) {
|
||||
draw_body(camera_pose_axes[i]);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
if (pthread_mutex_trylock(&lock)) {
|
||||
for (int i = 0; i < camera_bodies.size(); i++) {
|
||||
if (!std::get<1>(camera_bodies[i])) {
|
||||
Body* b = (Body*)malloc(sizeof(Body));
|
||||
create_new_sphere(b);
|
||||
b->color = glm::vec4(i & 0x4, i & 0x2, i & 0x1, max_hp);
|
||||
std::get<1>(camera_bodies[i]) = b;
|
||||
}
|
||||
draw_body(*std::get<1>(camera_bodies[i]));
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
Reference in New Issue
Block a user