41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
#include "util.hpp"
|
|
|
|
using namespace std;
|
|
|
|
bool read_file(string* s, const char* filepath) {
|
|
ifstream file(filepath);
|
|
if (!file.is_open()) {
|
|
return false;
|
|
}
|
|
*s = { istreambuf_iterator<char>(file), istreambuf_iterator<char>() };
|
|
return true;
|
|
}
|
|
|
|
vector<string> split_str(string s, char delim) {
|
|
vector<string> res;
|
|
string cur_word;
|
|
istringstream ss(s);
|
|
while (getline(ss, cur_word, delim)) {
|
|
res.push_back(cur_word);
|
|
}
|
|
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);
|
|
}
|
|
|
|
float randf() { return (float)abs(rand()) / (float)RAND_MAX; }
|