sorting Extrude intersection results, still buggy intersect() though
git-svn-id: svn://anubis/fart/trunk@274 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
1 parent
0b36fa79a0
commit
9bed134733
2 files changed
+81
-11
No files matched your search
+28
-11
@@ -2,6 +2,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm> /* sort() */
|
||||
|
||||
#include "Extrude.h"
|
||||
#include "util/Polygon.h"
|
||||
@@ -15,6 +16,21 @@ Extrude::Extrude()
|
||||
{
|
||||
}
|
||||
|
||||
class IntersectListComparator
|
||||
{
|
||||
public:
|
||||
IntersectListComparator(Vector start) : m_start(start) {}
|
||||
bool operator()(const Shape::Intersection & i1,
|
||||
const Shape::Intersection & i2) const
|
||||
{
|
||||
double d1 = (i1.position - m_start).mag2();
|
||||
double d2 = (i2.position - m_start).mag2();
|
||||
return d1 < d2;
|
||||
}
|
||||
protected:
|
||||
Vector m_start;
|
||||
};
|
||||
|
||||
Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
{
|
||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||
@@ -54,19 +70,16 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
+ c * ray_inv.getOrigin()[2]
|
||||
+ d);
|
||||
Solver::Result solutions = solver.solve();
|
||||
if (solutions.numResults > 0)
|
||||
if (solutions.numResults > 0 && solutions.results[0] > 0.0)
|
||||
{
|
||||
if (solutions.results[0] > 0.0)
|
||||
Vector ipoint = ray_inv[solutions.results[0]];
|
||||
Polygon quad;
|
||||
quad.add(p1).add(p2).add(p3).add(p4);
|
||||
if (quad.containsPoint(ipoint))
|
||||
{
|
||||
Vector ipoint = ray_inv[solutions.results[0]];
|
||||
Polygon quad;
|
||||
quad.add(p1).add(p2).add(p3).add(p4);
|
||||
if (quad.containsPoint(ipoint))
|
||||
{
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(ipoint),
|
||||
m_transform.transform_normal(normal)));
|
||||
}
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(ipoint),
|
||||
m_transform.transform_normal(normal)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +90,10 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
}
|
||||
}
|
||||
|
||||
vector<Intersection> m;
|
||||
|
||||
sort(m.begin(), m.end(), IntersectListComparator(ray.getOrigin()));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user