Add test for matrix, works fine, generic template as well

v1
Brett 2023-03-08 21:33:34 -05:00
parent 5db2224f93
commit 1770113f1f
2 changed files with 26 additions and 11 deletions

View File

@ -228,6 +228,16 @@ namespace blt {
return ret;
}
template<typename T, unsigned long size>
inline vec4 operator*(const mat4x4& left, const vec<T, size>& right){
vec4 ret{0,0,0,0};
for (int i = 0; i < size; i++)
ret[i] = (float)right[i];
return left * ret;
}
// multiplies the const c with each element in the mat4x4 v
inline mat4x4 operator*(float c, const mat4x4& v) {
mat4x4 mat{};

View File

@ -5,20 +5,11 @@
#include "profiling_tests.h"
#include "nbt_tests.h"
#include "queue_tests.h"
#include "blt/math/vectors.h"
#include "blt/math/matrix.h"
#include <bitset>
int main() {
int data = 0;
int index = 2;
data = data | index << (32 - 2);
auto fdata = *reinterpret_cast<float*>(&data);
auto back_to_int = *reinterpret_cast<int*>(&fdata);
std::string bits = std::bitset<32>((unsigned long long) back_to_int).to_string();
std::cout << bits << "\n";
return 0;
binaryTreeTest();
run_logging();
@ -36,5 +27,19 @@ int main() {
test_queues();
blt::vec4 v{2, 5, 1, 8};
blt::mat4x4 m{};
m.m(0,0, 1);
m.m(0,2, 2);
m.m(1, 1, 3);
m.m(1, 3, 4);
m.m(2, 2, 5);
m.m(3, 0, 6);
m.m(3, 3, 7);
auto result = m * v;
std::cout << result.x() << " " << result.y() << " " << result.z() << " " << result.w() << std::endl;
return 0;
}