Fix build

This commit is contained in:
hodasemi 2018-06-18 08:52:06 +02:00
parent 4905a5ff8a
commit 8c2e538f33
7 changed files with 19 additions and 54 deletions

View file

@ -33,8 +33,7 @@ cgv_add_module(CGII
../../src/Skeleton.cpp ../../src/Skeleton.cpp
../../src/SkeletonViewer.cpp ../../src/SkeletonViewer.cpp
../../src/SkinnedMeshViewer.cpp ../../src/SkinnedMeshViewer.cpp
../../src/main.cpp ../../src/main.cpp)
../../src/debughelpers.cpp)
# Set include directories # Set include directories
include_directories( include_directories(

View file

@ -96,13 +96,7 @@ void AtomicRotationTransform::optimize_value(const Vec3 &local_vector, const Vec
{ {
/*Task: Implement parameter optimization*/ /*Task: Implement parameter optimization*/
// target into local_target // optimize this that: target = this->calculate_matrix() * local_vector;
// 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()
double result = 0.0; double result = 0.0;

View file

@ -5,7 +5,6 @@
#include "IKViewer.h" #include "IKViewer.h"
#include "math_helper.h" #include "math_helper.h"
#include "debughelpers.h"
#include <unordered_set> #include <unordered_set>
@ -13,6 +12,11 @@
#include <cgv/math/inv.h> #include <cgv/math/inv.h>
#include <cgv/math/mat.h> #include <cgv/math/mat.h>
Vec3 into_vec3(const Vec4 &v)
{
return Vec3(v.x(), v.y(), v.z());
}
IKViewer::IKViewer(DataStore *data) IKViewer::IKViewer(DataStore *data)
: node("IK Viewer"), data(data), modifying(false), target_position(0, 0, 0, 1), max_iterations(20) : 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); kinematic_chain.emplace_front(inverse_static);
current_endeffector_matrix.identity(); current_endeffector_matrix.identity();
kinematic_vector.clear();
for (auto &transform : kinematic_chain) for (auto &transform : kinematic_chain)
{ {
kinematic_vector.emplace_back(transform);
current_endeffector_matrix = current_endeffector_matrix * transform->calculate_matrix(); current_endeffector_matrix = current_endeffector_matrix * transform->calculate_matrix();
} }
@ -212,37 +218,37 @@ void IKViewer::optimize()
/*Task 3.3: Implement CCD */ /*Task 3.3: Implement CCD */
for (int i = 0; i < max_iterations; i++) 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 // reverse iterate through kinematic chain
for (int j = kc_size - 1; j >= 0; j--) 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++) 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(); after_dof.identity();
int after_dof_index = j + 1; int after_dof_index = j + 1;
for (int k = j + 1; k < kc_size; k++) 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 // now we got 3 matrices
// (1) before dof: base_matrix * kinematic_chain[0...j-1] // (1) before dof: base_matrix * kinematic_vector[0...j-1]
// (2) dof: kinematic_chain[j] // (2) dof: kinematic_vector[j]
// (3) after_dof: kinematic_chain[j+1...kc_size-1] // (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_local = after_dof * Vec4(0.0f, 0.0f, 0.0f, 1.0f);
auto v_target = inv(before_dof) * target_position; 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(); current_endeffector_matrix.identity();

View file

@ -48,6 +48,7 @@ class IKViewer : public node, public drawable, public provider, public event_han
unsigned int max_iterations; unsigned int max_iterations;
std::list<std::shared_ptr<Transform>> kinematic_chain; std::list<std::shared_ptr<Transform>> kinematic_chain;
std::vector<std::shared_ptr<Transform>> kinematic_vector;
void optimize(); void optimize();

View file

@ -12,7 +12,6 @@
#include <cgv/base/find_action.h> #include <cgv/base/find_action.h>
#include "math_helper.h" #include "math_helper.h"
#include "debughelpers.h"
using namespace cgv::utils; using namespace cgv::utils;

View file

@ -1,23 +0,0 @@
#include "debughelpers.h"
#include <iostream>
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);
}

View file

@ -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);