fixing axisangle and vector
This commit is contained in:
parent
3989c0f68e
commit
2919c47e99
7 changed files with 283 additions and 197 deletions
|
@ -7,9 +7,9 @@ macro(make_test arg1)
|
|||
endmacro()
|
||||
|
||||
|
||||
make_test(pwcore_test_matrix)
|
||||
# make_test(pwcore_test_matrix)
|
||||
make_test(pwcore_test_vector)
|
||||
# make_test(pwcore_test_axisangle)
|
||||
make_test(pwcore_test_axisangle)
|
||||
# make_test(pwcore_test_quaternion)
|
||||
# make_test(pwcore_test_transform_tools)
|
||||
# make_test(pwcore_test_mesh)
|
||||
|
|
|
@ -1,53 +1,46 @@
|
|||
#include <pw/core/axisangle.hpp>
|
||||
#include <pw/core/quaternion.hpp>
|
||||
#include <pw/core/serialize.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc,char **argv) {
|
||||
auto main() -> int {
|
||||
|
||||
pw::axisangle_<float> aa = pw::axisangle_<float>();
|
||||
|
||||
// pw::quaternionf qf = pw::quaternionf::from_axisangle(aa);
|
||||
// std::cout << "aa as quaternion as matrix = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;
|
||||
// std::cout << "aa.matrix() = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;
|
||||
auto aa = pw::axisangle<float>();
|
||||
|
||||
std::cout << "x-axis" << std::endl;
|
||||
|
||||
aa.axis = pw::vector3::x_axis();
|
||||
aa.axis = pw::vector3f::x_axis();
|
||||
aa.angle = pw::deg_to_rad(45.f);
|
||||
|
||||
std::cout << "aa.matrix() = " << std::endl << pw::serialize::matrix(aa.to_matrix()) << std::endl;
|
||||
|
||||
std::cout << "aa.matrix() = " << std::endl
|
||||
<< pw::serialize::to_string(aa.to_matrix()) << std::endl;
|
||||
std::cout << "y-axis" << std::endl;
|
||||
|
||||
aa.axis = pw::vector3::y_axis();
|
||||
aa.axis = pw::vector3f::y_axis();
|
||||
aa.angle = pw::deg_to_rad(45.f);
|
||||
|
||||
std::cout << "aa.matrix() = " << std::endl << pw::serialize::matrix(aa.to_matrix()) << std::endl;
|
||||
std::cout << "aa.matrix() = " << std::endl
|
||||
<< pw::serialize::to_string(aa.to_matrix()) << std::endl;
|
||||
|
||||
std::cout << "z-axis" << std::endl;
|
||||
|
||||
aa.axis = pw::vector3f::z_axis();
|
||||
aa.angle = pw::deg_to_rad(45.f);
|
||||
|
||||
std::cout << "z-axis" << std::endl;
|
||||
std::cout << "aa.matrix() = " << std::endl
|
||||
<< pw::serialize::to_string(aa.to_matrix()) << std::endl;
|
||||
|
||||
aa.axis = pw::vector3::z_axis();
|
||||
aa.angle = pw::deg_to_rad(45.f);
|
||||
std::cout << "from matrix" << std::endl;
|
||||
|
||||
std::cout << "aa.matrix() = " << std::endl << pw::serialize::matrix(aa.to_matrix()) << std::endl;
|
||||
|
||||
|
||||
std::cout << "from matrix" << std::endl;
|
||||
|
||||
pw::matrix4x4f mrot; mrot.zero();
|
||||
mrot(0,0) = 1;
|
||||
mrot(2,1) = 1;
|
||||
mrot(1,2) = -1;
|
||||
|
||||
pw::axisanglef aa_fm = pw::axisangle::from_matrix(mrot);
|
||||
|
||||
std::cout << pw::serialize::matrix(aa_fm.axis.transposed()) << " " << pw::rad_to_deg(aa_fm.angle) << "deg" << std::endl;
|
||||
auto mrot = pw::matrix<float, 4, 4>{};
|
||||
mrot[0][0] = 1;
|
||||
mrot[2][1] = 1;
|
||||
mrot[1][2] = -1;
|
||||
|
||||
auto aa_fm = pw::axisanglef::from_matrix(mrot);
|
||||
|
||||
std::cout << pw::serialize::to_string(aa_fm.axis) << " "
|
||||
<< pw::rad_to_deg(aa_fm.angle) << "deg" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,51 +1,65 @@
|
|||
|
||||
#include <pw/core/vector.hpp>
|
||||
#include <pw/core/serialize.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
|
||||
int main(int ,char **) {
|
||||
auto main() -> int {
|
||||
|
||||
pw::vector2_<float> v2_A = { 3.2, 1.2 };
|
||||
pw::vector2_<float> v2_B = { 3.2, 1.2 };
|
||||
auto v2_A = pw::vector{3.2, 1.2};
|
||||
auto v2_B = pw::vector{6.4, 2.4};
|
||||
|
||||
auto AB_lerp = pw::vector2f::lerp(v2_A,v2_B,0.5);
|
||||
auto AB_lerp = decltype(v2_A)::lerp(v2_A, v2_B, 0.5);
|
||||
|
||||
pw::vector4_<float> v4;
|
||||
pw::vector3f v = pw::vector3f::backward();
|
||||
std::print("lerp A:({}) B:({}) t:({}) -> {}\n",
|
||||
pw::serialize::to_string(v2_A), pw::serialize::to_string(v2_B),
|
||||
0.5, pw::serialize::to_string(AB_lerp));
|
||||
|
||||
v4.fill(1.5);
|
||||
auto v4_14 = pw::vector4<float>::all(1.4);
|
||||
auto v4_sq = pw::vector4<float>::sequence(1.4);
|
||||
auto v3_fw = pw::vector3f::forward();
|
||||
|
||||
std::cout << "v4 = " << pw::serialize::matrix(v4) << std::endl;
|
||||
std::print("all(1.4) -> {}\n", pw::serialize::to_string(v4_14));
|
||||
std::print("sequence(1.4) -> {}\n", pw::serialize::to_string(v4_sq));
|
||||
std::print("forward() -> {}\n", pw::serialize::to_string(v3_fw));
|
||||
|
||||
// std::cout << "rows() : " << v4.rows() << std::endl;
|
||||
// std::cout << "cols() : " << v4.cols() << std::endl;
|
||||
std::cout << "ptr() : " << v4.ptr() << std::endl;
|
||||
std::cout << "ptr()[0] : " << v4.ptr()[0] << std::endl;
|
||||
std::cout << "(0,0) : " << v4(0,0) << std::endl;
|
||||
auto v3_sw_1 = v4_sq.swizzle(0, 1); // xy
|
||||
auto v3_sw_2 = v4_sq.swizzle(1, 0); // yx
|
||||
auto v3_sw_3 = v4_sq.swizzle(0, 2); // xz
|
||||
|
||||
auto v3 = v4.xyz();
|
||||
std::print("swizzle(0,1) aka xy -> {}\n",
|
||||
pw::serialize::to_string(v3_sw_1));
|
||||
std::print("swizzle(1,0) aka yx -> {}\n",
|
||||
pw::serialize::to_string(v3_sw_2));
|
||||
std::print("swizzle(0,2) aka xz -> {}\n",
|
||||
pw::serialize::to_string(v3_sw_3));
|
||||
|
||||
auto v3_p = v4.project();
|
||||
auto v3_up_1 = v3_fw.unproject(1);
|
||||
auto v3_pj_1 = v3_up_1.project();
|
||||
|
||||
auto v3_h = v.homogenous();
|
||||
std::print("unproject(1) -> {}\n", pw::serialize::to_string(v3_up_1));
|
||||
std::print("project() -> {}\n", pw::serialize::to_string(v3_pj_1));
|
||||
|
||||
// auto v3_lerp = vector4f::
|
||||
auto v3_nlz = v3_up_1.normalized();
|
||||
std::print("normalized() -> {}\n", pw::serialize::to_string(v3_nlz));
|
||||
|
||||
std::cout << "v3 = " << pw::serialize::matrix(v3) << std::endl;
|
||||
|
||||
std::cout << "v3.normalized() = " << pw::serialize::matrix(v3.normalized()) << std::endl;
|
||||
|
||||
auto e1 = pw::vector3 { 2.0, 0.0, 0.0 };
|
||||
auto e2 = pw::vector3 { 0.0, 0.0, 2.0 };
|
||||
auto e1 = pw::vector{2.0, 0.0, 0.0};
|
||||
auto e2 = pw::vector{0.0, 0.0, 2.0};
|
||||
|
||||
auto e2_e1 = e1 - e2;
|
||||
|
||||
auto n_e1_e2 = pw::vector3::cross(e1,e2);
|
||||
std::print("{} - {} -> {}\n", pw::serialize::to_string(e1),
|
||||
pw::serialize::to_string(e2), pw::serialize::to_string(e2_e1));
|
||||
|
||||
std::cout << "e1xe2 " << pw::serialize::matrix(n_e1_e2) << std::endl;
|
||||
auto e1_cross_e2 = e1.cross(e2);
|
||||
std::print("{} x {} -> {}\n", pw::serialize::to_string(e1),
|
||||
pw::serialize::to_string(e2),
|
||||
pw::serialize::to_string(e1_cross_e2));
|
||||
|
||||
std::cout << "e1xe2 " << pw::serialize::matrix(e2_e1) << std::endl;
|
||||
auto e1_dot_e2 = e1.dot(e2);
|
||||
|
||||
std::print("{} * {} -> {}\n", pw::serialize::to_string(e1),
|
||||
pw::serialize::to_string(e2), e1_dot_e2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue