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

View File

@@ -3,12 +3,14 @@
#include <cstring>
#include <cwctype>
#include <stdlib.h>
#include <glm/ext/quaternion_float.hpp>
#include <glm/mat4x4.hpp>
#include "util.hpp"
array<char*> _split_str_inner(const char* s, char delim, bool just_check_ws);
Array<char*> _split_str_inner(const char* s, char delim, bool just_check_ws);
template<class T> void append(array<T>& a, T el) {
template<class T> void append(Array<T>& a, T el) {
if (a.len == a.cap) {
resize(a, max(8, a.cap * 2));
}
@@ -16,13 +18,13 @@ template<class T> void append(array<T>& a, T el) {
a.len++;
}
template<class T> T pop(array<T>& a) {
template<class T> T pop(Array<T>& a) {
assert(a.len >= 1);
a.len--;
return a.data[a.len + 1];
}
template<class T> void resize(array<T>& a, size_t new_cap) {
template<class T> void resize(Array<T>& a, size_t new_cap) {
T* new_data = (T*)malloc(sizeof(T) * new_cap);
if (a.len > 0) {
memcpy(new_data, a.data, min(a.len, new_cap));
@@ -33,11 +35,11 @@ template<class T> void resize(array<T>& a, size_t new_cap) {
a.cap = new_cap;
}
template<class T> void clear(array<T>& a) {
template<class T> void clear(Array<T>& a) {
a.len = 0;
}
bool read_file(array<char>* out, const char* filepath) {
bool read_file(Array<char>* out, const char* filepath) {
FILE* fp = NULL;
if (fopen_s(&fp, filepath, "rb") != 0) {
printf("ERROR Failed to open file %s\n", filepath);
@@ -56,16 +58,16 @@ bool read_file(array<char>* out, const char* filepath) {
return true;
}
array<char*> split_str(const char* s, char delimiter) { return _split_str_inner(s, delimiter, false); }
Array<char*> split_str(const char* s, char delimiter) { return _split_str_inner(s, delimiter, false); }
array<char*> split_str(const char* s) { return _split_str_inner(s, ' ', true); }
Array<char*> split_str(const char* s) { return _split_str_inner(s, ' ', true); }
array<char*> _split_str_inner(const char* s, char delim, bool just_check_ws) {
array<char*> res = { NULL, 0, 0 };
Array<char*> _split_str_inner(const char* s, char delim, bool just_check_ws) {
Array<char*> res = { NULL, 0, 0 };
char c;
int i = 0;
array<char> cur_word = { NULL, 0, 0 };
Array<char> cur_word = { NULL, 0, 0 };
while (true) {
c = s[i++];
bool is_delim = just_check_ws ? iswspace(c) : c == delim;
@@ -89,3 +91,20 @@ array<char*> _split_str_inner(const char* s, char delim, bool just_check_ws) {
}
return res;
}
// https://songho.ca/opengl/gl_quaternion.html
glm::mat4 quat_to_mat4(glm::quat q) {
glm::vec4 col0 = glm::vec4(
1 - 2 * q.y * q.y - 2 * q.z * q.z, 2 * q.x * q.y + 2 * q.w * q.z, 2 * q.x * q.z - 2 * q.w * q.y, 0);
glm::vec4 col1 = glm::vec4(
2 * q.x * q.y - 2 * q.w * q.z, 1 - 2 * q.x * q.x - 2 * q.z * q.z, 2 * q.y * q.z + 2 * q.w * q.x, 0);
glm::vec4 col2 = glm::vec4(
2 * q.x * q.z + 2 * q.w * q.y, 2 * q.y * q.z - 2 * q.w * q.x, 1 - 2 * q.x * q.x - 2 * q.y * q.y, 0);
glm::vec4 col3 = glm::vec4(0, 0, 0, 1);
return glm::mat4(col0, col1, col2, col3);
}