CCD attempt

This commit is contained in:
hodasemi 2018-06-20 09:38:06 +02:00
parent 8c2e538f33
commit a3ef9b44fc
2 changed files with 36 additions and 1 deletions

BIN
CG2_SS18_04_IK.pdf Normal file

Binary file not shown.

View file

@ -92,13 +92,48 @@ T clamp(T &v, T &c1, T &c2)
return v; return v;
} }
float angle(const Vec3 &v1, const Vec3 &v2)
{
float d = dot(v1, v2);
float v1_length = length(v1);
float v2_length = length(v2);
return std::acos(d / (v1_length * v2_length));
}
/*
fn angle(v1
: cgmath::Vector2<f32>)
->f32
{
let dot = v1.x * DEFAULT_DIRECTION.x + v1.y * DEFAULT_DIRECTION.y;
let v1_len = ((v1.x * v1.x) + (v1.y * v1.y)).sqrt();
let v2_len = ((DEFAULT_DIRECTION.x * DEFAULT_DIRECTION.x) + (DEFAULT_DIRECTION.y * DEFAULT_DIRECTION.y))
.sqrt();
let angle = (dot / (v1_len * v2_len)).acos();
if
v1.x < 0.0
{
-angle
}
else
{
angle
}
}
*/
void AtomicRotationTransform::optimize_value(const Vec3 &local_vector, const Vec3 &target, bool inverse) void AtomicRotationTransform::optimize_value(const Vec3 &local_vector, const Vec3 &target, bool inverse)
{ {
/*Task: Implement parameter optimization*/ /*Task: Implement parameter optimization*/
// optimize this that: target = this->calculate_matrix() * local_vector; // optimize this that: target = this->calculate_matrix() * local_vector;
double result = 0.0; double result = angle(local_vector, target);
if (inverse) if (inverse)
result = -result; result = -result;