adding in the axes for all the camera poses. failing to read the file properly though

This commit is contained in:
2025-08-21 23:54:05 -05:00
parent 8b816f8296
commit 19f786ee7c
10 changed files with 177 additions and 69 deletions

71
src/camera_poses.cpp Normal file
View File

@@ -0,0 +1,71 @@
#include <body.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <glm/glm.hpp>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/vector_float3.hpp>
#include <glm/matrix.hpp>
#include <util.hpp>
#include "camera_poses.hpp"
#define LINE_BUF_SIZE 128
#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<Body>* bodies_out, const char* filepath) {
FILE* fp;
if (!fopen_s(&fp, filepath, "rb")) {
printf("Error parsing poses csv: %s\n", filepath);
return false;
}
char delim = ',';
char line[LINE_BUF_SIZE];
// read in header
fgets(line, LINE_BUF_SIZE, fp);
while (!feof(fp)) {
fgets(line, LINE_BUF_SIZE, fp);
Array<char*> 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));
// 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 };
// Generate axis spheres
for (int i = 0; i < 3; i++) {
for (int j = 0; j < NUM_SPHERES_PER_AXE; j++) {
Body b;
if (!load_body(&b, "Icosphere.obj")) {
return false;
}
// 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);
bodies_out->data[i*j + j] = b;
}
}
}
}