This commit is contained in:
Hartmut Seichter 2024-07-13 00:29:47 +02:00
parent 2919c47e99
commit 114f17a499
13 changed files with 327 additions and 519 deletions

View file

@ -1,15 +1,13 @@
macro(make_test arg1)
add_executable(${arg1}
${arg1}.cpp
)
target_link_libraries(${arg1}
pwcore)
add_executable(${arg1} ${arg1}.cpp)
target_link_libraries(${arg1} pwcore)
endmacro()
# make_test(pwcore_test_matrix)
make_test(pwcore_test_vector)
make_test(pwcore_test_matrix)
make_test(pwcore_test_axisangle)
# make_test(pwcore_test_quaternion)
make_test(pwcore_test_quaternion)
make_test(pwcore_test_color)
# make_test(pwcore_test_transform_tools)
# make_test(pwcore_test_mesh)

View file

@ -0,0 +1,20 @@
#include <cstdio>
#include <pw/core/color.hpp>
#include <pw/core/debug.hpp>
#include <pw/core/serialize.hpp>
auto main() -> int {
pw::debug::d() << "pixwerx.color.test\n";
auto col = pw::color::from_rgb8888(255,0,0,255);
pw::debug::d() << "col -> \n" << pw::serialize::to_string(col);
auto col_hx = pw::color::from_rgb8888(0xFF'EE'BB'AA);
pw::debug::d() << "col_hx(0xFFAABBAA) -> \n" << pw::serialize::to_string(col_hx);
return 0;
}

View file

@ -1,130 +1,41 @@
#include <pw/core/matrix.hpp>
#include <pw/core/vector.hpp>
#include <pw/core/serialize.hpp>
#include <pw/core/debug.hpp>
#include <pw/core/matrix.hpp>
#include <pw/core/serialize.hpp>
#include <pw/core/vector.hpp>
#include <iostream>
#include <sstream>
auto main() -> int {
pw::debug::d() << "pixwerx.matrix.test\n";
int main(int argc,char **argv) {
auto m22 = pw::matrix<float, 2, 2>{};
pw::debug::d() << "matrix<2,2>{} -> \n" << pw::serialize::to_string(m22);
using namespace pw;
m22[0][0] = 1;
m22[0][1] = 2;
m22[1][0] = 3;
m22[1][1] = 4;
matrix2x2f m22; m22.zero();
pw::debug::d() << "matrix<2,2>{1,2,3,4} -> \n"
<< pw::serialize::to_string(m22);
auto m22_inv = m22.inverse();
m22(0,0) = 1; m22(0,1) = 2;
m22(1,0) = 3; m22(1,1) = 4;
pw::debug::d() << "matrix<2,2>{1,2,3,4}.inverse() -> \n"
<< pw::serialize::to_string(m22_inv);
vector2f v2;
v2[0] = 1; v2[1] = 3;
auto m22_inv_inv = m22_inv.inverse();
pw::debug::d() << "matrix<2,2>{1,2,3,4}.inverse().inverse() -> \n"
<< pw::serialize::to_string(m22_inv_inv);
vector2f v3( { 1.f,2.f } );
auto row_1 = m22_inv[1];
pw::debug::d() << "matrix<2,2>{1,2,3,4}.inverse()[1] -> \n"
<< pw::serialize::to_string(row_1);
auto m22_tp = m22.transposed();
pw::debug::d() << "matrix<2,2>{1,2,3,4}.transposed() -> \n"
<< pw::serialize::to_string(m22_tp);
auto m22_inv = m22.inverse();
auto m22_id = m22_inv * m22;
auto v2_t = m22_id * v2;
auto v3_t = m22_id * v3;
auto v2_f = m22 * v2;
auto v2_b = m22_inv * v2_f;
vector2_<float> r_m22 = m22.row(0).transposed();
vector2_<float> c_m22 = m22.column(1);
auto r_m22_h = r_m22.homogenous();
debug::d() << "offset(0,1) col-major " << m22.offset(0,1);
debug::d() << "det " << m22.determinant();
std::cout << "m22 " << pw::serialize::matrix(m22) << std::endl;
std::cout << "m22-1 " << pw::serialize::matrix(m22_inv) << std::endl;
std::cout << "m22-i " << pw::serialize::matrix(m22_id) << std::endl;
std::cout << "v22_t " << pw::serialize::matrix(v2_t) << std::endl;
std::cout << "v3_t " << pw::serialize::matrix(v3_t) << std::endl;
std::cout << "v2_f " << pw::serialize::matrix(v2_f) << std::endl;
std::cout << "v2_b " << pw::serialize::matrix(v2_b) << std::endl;
std::cout << "v2_b.norm " << v2_b.norm() << std::endl;
// v2_b.normalize();
std::cout << "v2_b.normalized " << pw::serialize::matrix(v2_b.normalized()) << std::endl;
// std::cout << "v2_b~v3_t " << rad_to_deg(vector2f::angle_between(v2,v3)) << std::endl;
// vector2f v2 = m22.slice<2,1>(0,0);
// m22.set_slice<2,1>(v2,0,0);
// v2 *= 2;
// v2 += 1;
// m22 *= 3;
// m22.determinant();
// debug::d() << sizeof(v2);
// auto m22_i = m22.inverse();
#if 0
pw::matrix4x4d m;
m.set_identity();
std::cout << "m = " << pw::serialize::matrix(m) << std::endl;
std::cout << "row_stride() : " << m.row_stride() << std::endl;
std::cout << "col_stride() : " << m.col_stride() << std::endl;
std::cout << "rows() : " << m.rows() << std::endl;
std::cout << "cols() : " << m.cols() << std::endl;
std::cout << "data() : " << m.data() << std::endl;
std::cout << "data()[0] : " << m.data()[0] << std::endl;
std::cout << "at(0,0) : " << m.at(0,0) << std::endl;
std::cout << "determinant(): " << m.determinant() << std::endl;
pw::matrix4x4d mi = m.get_inverse();
std::cout << "mi.at(0,0) : " << mi.at(0,0) << std::endl;
pw::matrix4x4d mscale = m * 4.2;
std::cout << "mscale = " << pw::serialize::matrix(mscale) << std::endl;
pw::matrix4x4d a;
for (int r = 0; r < m.rows(); r++) {
for (int c = 0; c < m.cols(); c++) {
a.at(r,c) = r * m.cols() + c;
}
}
std::cout << "a = " << pw::serialize::matrix(a) << std::endl;
pw::matrix4x4d r = a * mscale;
std::cout << "a * mscale = " << pw::serialize::matrix(r) << std::endl;
return 0;
#endif
auto m22_tp_col1 = m22_tp.column(1);
pw::debug::d() << "matrix<2,2>{1,2,3,4}.transposed().column(1) -> \n"
<< pw::serialize::to_string(m22_tp_col1);
}

View file

@ -1,29 +1,36 @@
#include <pw/core/debug.hpp>
#include <pw/core/quaternion.hpp>
#include <pw/core/serialize.hpp>
#include <iostream>
auto main() -> int {
int main(int argc,char **argv) {
pw::debug::d() << "pixwerx.quaternion.test\n";
pw::quaternion_<float> qf;
auto q0 = pw::quaternion<float>{};
auto q1 = pw::quaternion{1.f, 2.f, 3.f, 4.f};
std::cout << "qf = " << pw::serialize::matrix(qf) << std::endl;
std::cout << "qf.matrix() = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;
pw::debug::d() << "q0 = quaternion{} -> \n" << pw::serialize::to_string(q0);
pw::debug::d() << "q1 = quaternion{1,2,3,4} -> \n"
<< pw::serialize::to_string(q1);
std::cout << "qf.squared_norm() = " << qf.squared_norm() << std::endl;
// std::cout << "qf.dot(qf) = " << qf.dot(qf) << std::endl;
std::cout << "qf.conjugate() = " << pw::serialize::matrix(qf.conjugate()) << std::endl;
auto q0_x_q1 = q0 * q1;
pw::debug::d() << "q0 * q1 -> \n" << pw::serialize::to_string(q0_x_q1);
pw::quaternionf qc = qf.conjugate();
std::cout << "qf.conjugate() (qc) = " << pw::serialize::matrix(qc.to_matrix()) << std::endl;
auto q1_conj = q1.conjugate();
pw::debug::d() << "q1.conjugate() -> \n"
<< pw::serialize::to_string(q1_conj);
pw::quaternionf qi = qf.inverse();
std::cout << "qf.inverse() (qi) = " << pw::serialize::matrix(qi.to_matrix()) << std::endl;
pw::quaternionf qmid = pw::quaternionf::normalized_lerp(qi,qf,0.5f);
// std::cout << "qmid.dot() (half between qf and qi) = " << pw::rad_to_deg(quaternionf::angle_between()) << std::endl;
auto q1_conj_nml = q1_conj.normalized();
pw::debug::d() << "q1.conjugate().normalized() -> \n"
<< pw::serialize::to_string(q1_conj_nml);
auto q1_conj_inv = q1_conj.inverse();
pw::debug::d() << "q1.conjugate().inverse() -> \n"
<< pw::serialize::to_string(q1_conj_inv);
auto lerp_q0_q1_half = decltype(q0)::lerp(q0, q1, 0.5f);
pw::debug::d() << "quaternion::lerp(q0,q1,0.5) -> \n"
<< pw::serialize::to_string(lerp_q0_q1_half);
return 0;