From 8c2e538f33f222ce9263d019c207bae967e4b18d Mon Sep 17 00:00:00 2001 From: hodasemi Date: Mon, 18 Jun 2018 08:52:06 +0200 Subject: [PATCH] Fix build --- CGII/build/cmake/CMakeLists.txt | 3 +-- CGII/src/AtomicTransform.cpp | 8 +------- CGII/src/IKViewer.cpp | 26 ++++++++++++++++---------- CGII/src/IKViewer.h | 1 + CGII/src/SkeletonViewer.cpp | 1 - CGII/src/debughelpers.cpp | 23 ----------------------- CGII/src/debughelpers.h | 11 ----------- 7 files changed, 19 insertions(+), 54 deletions(-) delete mode 100644 CGII/src/debughelpers.cpp delete mode 100644 CGII/src/debughelpers.h diff --git a/CGII/build/cmake/CMakeLists.txt b/CGII/build/cmake/CMakeLists.txt index e90fb69..1144f37 100644 --- a/CGII/build/cmake/CMakeLists.txt +++ b/CGII/build/cmake/CMakeLists.txt @@ -33,8 +33,7 @@ cgv_add_module(CGII ../../src/Skeleton.cpp ../../src/SkeletonViewer.cpp ../../src/SkinnedMeshViewer.cpp - ../../src/main.cpp - ../../src/debughelpers.cpp) + ../../src/main.cpp) # Set include directories include_directories( diff --git a/CGII/src/AtomicTransform.cpp b/CGII/src/AtomicTransform.cpp index 9cd619b..c0c20ab 100644 --- a/CGII/src/AtomicTransform.cpp +++ b/CGII/src/AtomicTransform.cpp @@ -96,13 +96,7 @@ void AtomicRotationTransform::optimize_value(const Vec3 &local_vector, const Vec { /*Task: Implement parameter optimization*/ - // target into local_target - // get dofs - // project target into plane decided by which dofs exist - // scal mult local_target and local_vector - - // use only degrees defined by dofs - // if inverse == true use -angle with set_value() + // optimize this that: target = this->calculate_matrix() * local_vector; double result = 0.0; diff --git a/CGII/src/IKViewer.cpp b/CGII/src/IKViewer.cpp index b4f9598..4141d2d 100644 --- a/CGII/src/IKViewer.cpp +++ b/CGII/src/IKViewer.cpp @@ -5,7 +5,6 @@ #include "IKViewer.h" #include "math_helper.h" -#include "debughelpers.h" #include @@ -13,6 +12,11 @@ #include #include +Vec3 into_vec3(const Vec4 &v) +{ + return Vec3(v.x(), v.y(), v.z()); +} + IKViewer::IKViewer(DataStore *data) : node("IK Viewer"), data(data), modifying(false), target_position(0, 0, 0, 1), max_iterations(20) { @@ -192,9 +196,11 @@ void IKViewer::calculate_kinematic_chain(Bone *base, Bone *endeffector) kinematic_chain.emplace_front(inverse_static); current_endeffector_matrix.identity(); + kinematic_vector.clear(); for (auto &transform : kinematic_chain) { + kinematic_vector.emplace_back(transform); current_endeffector_matrix = current_endeffector_matrix * transform->calculate_matrix(); } @@ -212,37 +218,37 @@ void IKViewer::optimize() /*Task 3.3: Implement CCD */ for (int i = 0; i < max_iterations; i++) { - int kc_size = kinematic_chain.size(); + int kc_size = kinematic_vector.size(); // reverse iterate through kinematic chain for (int j = kc_size - 1; j >= 0; j--) { - auto before_dof = current_base_matrix; + Mat4 before_dof = current_base_matrix; for (int k = 0; k < j; k++) { - before_dof = before_dof * kinematic_chain[k]; + before_dof = before_dof * kinematic_vector[k]->calculate_matrix(); } - auto after_dof; + Mat4 after_dof; after_dof.identity(); int after_dof_index = j + 1; for (int k = j + 1; k < kc_size; k++) { - after_dof = after_dof * kinematic_chain[k]; + after_dof = after_dof * kinematic_vector[k]->calculate_matrix(); } // now we got 3 matrices - // (1) before dof: base_matrix * kinematic_chain[0...j-1] - // (2) dof: kinematic_chain[j] - // (3) after_dof: kinematic_chain[j+1...kc_size-1] + // (1) before dof: base_matrix * kinematic_vector[0...j-1] + // (2) dof: kinematic_vector[j] + // (3) after_dof: kinematic_vector[j+1...kc_size-1] auto v_local = after_dof * Vec4(0.0f, 0.0f, 0.0f, 1.0f); auto v_target = inv(before_dof) * target_position; - it->optimize_value(v_local, v_target); + kinematic_vector[j]->optimize_value(into_vec3(v_local), into_vec3(v_target)); } current_endeffector_matrix.identity(); diff --git a/CGII/src/IKViewer.h b/CGII/src/IKViewer.h index 1684139..3b2b699 100644 --- a/CGII/src/IKViewer.h +++ b/CGII/src/IKViewer.h @@ -48,6 +48,7 @@ class IKViewer : public node, public drawable, public provider, public event_han unsigned int max_iterations; std::list> kinematic_chain; + std::vector> kinematic_vector; void optimize(); diff --git a/CGII/src/SkeletonViewer.cpp b/CGII/src/SkeletonViewer.cpp index 057c92e..28130df 100644 --- a/CGII/src/SkeletonViewer.cpp +++ b/CGII/src/SkeletonViewer.cpp @@ -12,7 +12,6 @@ #include #include "math_helper.h" -#include "debughelpers.h" using namespace cgv::utils; diff --git a/CGII/src/debughelpers.cpp b/CGII/src/debughelpers.cpp deleted file mode 100644 index 9662c00..0000000 --- a/CGII/src/debughelpers.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "debughelpers.h" - -#include - -void print_vec3(const Vec3 &v) -{ - std::cout << "(" << v.x() << ", " << v.y() << ", " << v.z() << ")" << std::endl; -} - -void print_vec3(const Vec4 &v) -{ - print_vec3(into_vec3(v)); -} - -Vec3 into_vec3(const Vec4 &v) -{ - return Vec3(v.x(), v.y(), v.z()); -} - -Vec4 into_vec4(const Vec3 &v) -{ - return Vec4(v.x(), v.y(), v.z(), 1.0f); -} \ No newline at end of file diff --git a/CGII/src/debughelpers.h b/CGII/src/debughelpers.h deleted file mode 100644 index 836285e..0000000 --- a/CGII/src/debughelpers.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "math_helper.h" - -void print_vec3(const Vec3 &v); - -void print_vec3(const Vec4 &v); - -Vec3 into_vec3(const Vec4 &v); - -Vec4 into_vec4(const Vec3 &v); \ No newline at end of file