From f33e6769f43d8e0e38c8cb1f4f19b5db7489d98e Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Fri, 18 Jan 2019 22:04:14 +0100 Subject: [PATCH] still not yet there --- src/core/CMakeLists.txt | 2 +- src/core/include/pw/core/axisangle.hpp | 4 ++-- src/core/include/pw/core/quaternion.hpp | 10 +++++----- src/core/include/pw/core/serialize.hpp | 6 +++--- src/core/include/pw/core/vector.hpp | 17 ++++++++++++++++- src/core/tests/CMakeLists.txt | 10 +++++----- src/core/tests/pwcore_test_axisangle.cpp | 2 +- 7 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e5cd101..2c4bdef 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,7 +1,7 @@ set(hdrs include/pw/core/debug.hpp -# include/pw/core/axisangle.hpp + include/pw/core/axisangle.hpp include/pw/core/core.hpp include/pw/core/math.hpp include/pw/core/matrixbase.hpp diff --git a/src/core/include/pw/core/axisangle.hpp b/src/core/include/pw/core/axisangle.hpp index 36144ff..48bfa1c 100644 --- a/src/core/include/pw/core/axisangle.hpp +++ b/src/core/include/pw/core/axisangle.hpp @@ -62,8 +62,8 @@ public: const T _fCos = cos(_angle); - matrix_<3,1,T> _vCos(_axis * (1 - _fCos)); - matrix_<3,1,T> _vSin(_axis * sin(_angle)); + vector3_ _vCos(_axis * (1 - _fCos)); + vector3_ _vSin(_axis * sin(_angle)); // R.at(0) = (_axis(0,0) * _vCos(0,0)) + _fCos; // R.at(4) = (T) ((vec(0,0) * _vCos(1,0)) - _vSin(2,0)); diff --git a/src/core/include/pw/core/quaternion.hpp b/src/core/include/pw/core/quaternion.hpp index b0e6767..22e7a9a 100644 --- a/src/core/include/pw/core/quaternion.hpp +++ b/src/core/include/pw/core/quaternion.hpp @@ -123,10 +123,10 @@ public: inline void normalize() { *this = this->normalized(); } //! conversion from a matrix - inline static const quaternion_ from_matrix(const matrix_<4,4,T> &m); + inline static const quaternion_ from_matrix(const matrix_ &m); //! conversion to a matrix - const matrix_<4,4,T> to_matrix() const; + const matrix_ to_matrix() const; //! return identiy quaternion static const quaternion_ identity(); @@ -170,7 +170,7 @@ const T quaternion_::_sqrt90 = std::sqrt(0.5); template -const quaternion_ quaternion_::from_matrix(const matrix_<4,4,T> &m) { +const quaternion_ quaternion_::from_matrix(const matrix_ &m) { using std::sqrt; @@ -185,9 +185,9 @@ const quaternion_ quaternion_::from_matrix(const matrix_<4,4,T> &m) { } template -const matrix_<4,4,T> quaternion_::to_matrix() const { +const matrix_ quaternion_::to_matrix() const { - matrix_<4,4,T> m; m.set_identity(); + matrix_ m; m.set_identity(); T xx = x() * x(); T xy = x() * y(); diff --git a/src/core/include/pw/core/serialize.hpp b/src/core/include/pw/core/serialize.hpp index e63bfef..dd61b22 100644 --- a/src/core/include/pw/core/serialize.hpp +++ b/src/core/include/pw/core/serialize.hpp @@ -23,7 +23,7 @@ #ifndef PW_CORE_SERIALIZE_HPP #define PW_CORE_SERIALIZE_HPP -#include +#include #include @@ -33,8 +33,8 @@ namespace pw { struct serialize { - template - inline static std::string matrix(const matrixbase& m) { + template + inline static std::string matrix(const matrix_& m) { std::stringstream ss; for (int r = 0; r < m.rows();r++) { diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index cb9e07c..cfac3f8 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -64,12 +64,27 @@ auto dot(const vector_& a, const vector_& b) } +template +struct vector3_ : vector_ { + + using vector_::vector_; + + inline static vector3_ forward() { return vector3_ ( T(0), T(0),-T(1) ); } + inline static vector3_ backward() { return vector3_( T(0), T(0), T(1) ); } + inline static vector3_ right() { return vector3_ ( T(1), T(0), T(0) ); } + inline static vector3_ left() { return vector3_ ( -T(1), T(0), T(0) ); } + inline static vector3_ up() { return vector3_ ( T(0), T(1), T(0) ); } + inline static vector3_ down() { return vector3_ ( T(0),-T(1), T(0) ); } + +}; + + // // // template using vector2_ = vector_; -template using vector3_ = vector_; +//template using vector3_ = vector_; template using vector4_ = vector_; using vector2f = vector2_; diff --git a/src/core/tests/CMakeLists.txt b/src/core/tests/CMakeLists.txt index 517f07a..b414871 100644 --- a/src/core/tests/CMakeLists.txt +++ b/src/core/tests/CMakeLists.txt @@ -21,9 +21,9 @@ target_link_libraries(pwcore_test_matrix # pwcore) -#add_executable(pwcore_test_axisangle -# pwcore_test_axisangle.cpp -# ) +add_executable(pwcore_test_axisangle + pwcore_test_axisangle.cpp + ) -#target_link_libraries(pwcore_test_axisangle -# pwcore) +target_link_libraries(pwcore_test_axisangle + pwcore) diff --git a/src/core/tests/pwcore_test_axisangle.cpp b/src/core/tests/pwcore_test_axisangle.cpp index da495be..648d3b8 100644 --- a/src/core/tests/pwcore_test_axisangle.cpp +++ b/src/core/tests/pwcore_test_axisangle.cpp @@ -10,7 +10,7 @@ int main(int argc,char **argv) { pw::quaternionf qf = pw::quaternionf::from_axisangle(aa); - std::cout << "aa as quaternion as vector = " << pw::serialize::matrix(qf.as_vector()) << std::endl; +// std::cout << "aa as quaternion as vector = " << pw::serialize::matrix(qf.as_vector()) << std::endl; // std::cout << "aa.matrix() = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;