#include #include #include #include #include #include #include #include #include #include "camera_poses.hpp" #define LINE_BUF_SIZE 256 #define NUM_SPHERES_PER_AXE 25 #define SPACE_PER_SPHERE 10.0f glm::vec4 red_color = glm::vec4(1, 0, 0, 1); glm::vec4 green_color = glm::vec4(0, 1, 0, 1); glm::vec4 blue_color = glm::vec4(0, 0, 1, 1); bool parse_poses(Array* bodies_out, const char* filepath) { FILE* fp; if (fopen_s(&fp, filepath, "rb")) { printf("Error parsing %s\n", filepath); return false; } char delim = ','; char line[LINE_BUF_SIZE]; // because clang refuses to cooperate with my append implementation and generate the function code... *bodies_out = { (Body*)malloc(sizeof(Body) * 3 * NUM_SPHERES_PER_AXE * 14), 3 * NUM_SPHERES_PER_AXE * 14 }; // read in header fgets(line, LINE_BUF_SIZE, fp); fgets(line, LINE_BUF_SIZE, fp); for (int camera_i = 0; !feof(fp); camera_i++) { Array words = split_str(line, delim); float x = atof(words[0]); float y = atof(words[1]); float z = atof(words[2]); float w = atof(words[3]); float i = atof(words[4]); float j = atof(words[5]); float k = atof(words[6]); glm::mat4 pose = glm::translate(quat_to_mat4(glm::quat(w, i, j, k)), glm::vec3(x, y, z)); // Generate axis spheres for (int i = 0; i < 3; i++) { for (int j = 0; j < NUM_SPHERES_PER_AXE; j++) { Body b; create_new_sphere(&b); // How far along the axis is this ball glm::vec3 trans = glm::vec3(0, 0, 0); trans[i] = (float)j * SPACE_PER_SPHERE; // Now move the translated pose via the camera's pose 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; bodies_out->data[camera_i*3*NUM_SPHERES_PER_AXE + i*NUM_SPHERES_PER_AXE + j] = b; } } fgets(line, LINE_BUF_SIZE, fp); } return true; }