Start first task

This commit is contained in:
hodasemi 2019-01-24 23:55:44 +01:00
parent 4aebb5f172
commit 3ac15a7649
2 changed files with 28 additions and 3 deletions

View file

@ -392,6 +392,16 @@ class AABBTree
assert(IsCompleted());
if (root == nullptr)
return ResultEntry();
AABBNode* node = root;
while(1) {
// TODO: dynamic cast to check for leaf- or split-node
// if split node: check BB of childs
// -> node = child with shorter distance
// if leaf node: iterate through primitives
}
/* Task 3.2.1 */
return ClosestPrimitiveLinearSearch(q);
}

View file

@ -91,9 +91,24 @@ bool LineSegment::Overlaps(const Box &b) const
//returns the point with smallest distance topoint p which lies on the line segment
Eigen::Vector3f LineSegment::ClosestPoint(const Eigen::Vector3f &p) const
{
//the two endpoints of the line segment are v0,v1
/* Task 3.2.1 */
return Eigen::Vector3f(0, 0, 0);
Eigen::Vector3f v = v1 - v0;
Eigen::Vector3f w = p - v0;
float c1 = w.dot(v);
float c2 = v.dot(v);
if (c1 <= 0.0) {
return v0;
}
if (c2 <= c1) {
return v1;
}
float b = c1 / c2;
Eigen::Vector3f Pb = v0 + b * v;
return Pb;
}
//returns the squared distance between point p and the line segment