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:
parent
0b36fa79a0
commit
9bed134733
53
scenes/extrudes.fart
Normal file
53
scenes/extrudes.fart
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
scene
|
||||||
|
{
|
||||||
|
options
|
||||||
|
{
|
||||||
|
multisample 3
|
||||||
|
exposure 1.2
|
||||||
|
}
|
||||||
|
|
||||||
|
camera
|
||||||
|
{
|
||||||
|
position <0, -10, 10>
|
||||||
|
look_at <0, 0, 1>
|
||||||
|
}
|
||||||
|
|
||||||
|
light { position <10, -12, 8> }
|
||||||
|
|
||||||
|
plane
|
||||||
|
{
|
||||||
|
position <0, 0, 1>, 0
|
||||||
|
material
|
||||||
|
{
|
||||||
|
color <0, 0.5, 0.1>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extrude
|
||||||
|
{
|
||||||
|
polygon
|
||||||
|
{
|
||||||
|
<3, 0>
|
||||||
|
<1, 1>
|
||||||
|
<2, 3>
|
||||||
|
<-1, 1>
|
||||||
|
<-3, 2>
|
||||||
|
<-2, -1>
|
||||||
|
<-3, -3>
|
||||||
|
<-1, -2>
|
||||||
|
<1, -4>
|
||||||
|
<2, -1>
|
||||||
|
}
|
||||||
|
offset 3
|
||||||
|
material { color <1, 0.7, 0> }
|
||||||
|
translate <-2, 0, 0>
|
||||||
|
}
|
||||||
|
|
||||||
|
extrude
|
||||||
|
{
|
||||||
|
ngon 5, 2
|
||||||
|
offset 1
|
||||||
|
translate <2, 0, 0>
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm> /* sort() */
|
||||||
|
|
||||||
#include "Extrude.h"
|
#include "Extrude.h"
|
||||||
#include "util/Polygon.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)
|
Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||||
{
|
{
|
||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
@ -54,9 +70,7 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
+ c * ray_inv.getOrigin()[2]
|
+ c * ray_inv.getOrigin()[2]
|
||||||
+ d);
|
+ d);
|
||||||
Solver::Result solutions = solver.solve();
|
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]];
|
Vector ipoint = ray_inv[solutions.results[0]];
|
||||||
Polygon quad;
|
Polygon quad;
|
||||||
@ -70,13 +84,16 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
distance += offset.distance;
|
distance += offset.distance;
|
||||||
scale = offset.scale;
|
scale = offset.scale;
|
||||||
shift = offset.shift;
|
shift = offset.shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<Intersection> m;
|
||||||
|
|
||||||
|
sort(m.begin(), m.end(), IntersectListComparator(ray.getOrigin()));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user