Fix build
This commit is contained in:
parent
4905a5ff8a
commit
8c2e538f33
7 changed files with 19 additions and 54 deletions
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "IKViewer.h"
|
||||
|
||||
#include "math_helper.h"
|
||||
#include "debughelpers.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
|
@ -13,6 +12,11 @@
|
|||
#include <cgv/math/inv.h>
|
||||
#include <cgv/math/mat.h>
|
||||
|
||||
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();
|
||||
|
|
|
@ -48,6 +48,7 @@ class IKViewer : public node, public drawable, public provider, public event_han
|
|||
unsigned int max_iterations;
|
||||
|
||||
std::list<std::shared_ptr<Transform>> kinematic_chain;
|
||||
std::vector<std::shared_ptr<Transform>> kinematic_vector;
|
||||
|
||||
void optimize();
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <cgv/base/find_action.h>
|
||||
|
||||
#include "math_helper.h"
|
||||
#include "debughelpers.h"
|
||||
|
||||
using namespace cgv::utils;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
Loading…
Reference in a new issue