end caps on extrudes working!
git-svn-id: svn://anubis/fart/trunk@279 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
da47ae6fd3
commit
53ebaeec3e
@ -37,7 +37,7 @@ scene
|
||||
<-3, -3>
|
||||
<-1, -2>
|
||||
<1, -4>
|
||||
<2, -1>
|
||||
<1, -1>
|
||||
}
|
||||
offset 3
|
||||
material { color <1, 0.7, 0> }
|
||||
|
@ -83,7 +83,7 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
Vector ipoint = ray_inv[solutions.results[0]];
|
||||
Polygon quad;
|
||||
quad.add(p1).add(p2).add(p3).add(p4);
|
||||
if (quad.containsPoint(ipoint))
|
||||
if (quad.containsPointConvex(ipoint))
|
||||
{
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(ipoint),
|
||||
@ -115,7 +115,7 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
for (int p = 0; p < n_polygons; p++)
|
||||
{
|
||||
refptr<Polygon> polygon = m_polygons[p];
|
||||
if (polygon->containsPoint(ipoint))
|
||||
if (polygon->containsPoint2D(ipoint))
|
||||
{
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(ipoint),
|
||||
@ -126,7 +126,7 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
}
|
||||
if (scale[0] > 0.0 && scale[1] > 0.0)
|
||||
{
|
||||
a = 0, b = 0, c = 1.0, d = distance;
|
||||
a = 0, b = 0, c = 1.0, d = -distance;
|
||||
if (ray_inv.getDirection() % Vector(a, b, c) < 0)
|
||||
{
|
||||
LinearSolver solver( a * ray_inv.getDirection()[0]
|
||||
@ -148,7 +148,7 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
tp[i] = new Vector(tp[i]->mult(scale) + shift);
|
||||
(*tp[i])[2] += distance;
|
||||
}
|
||||
if (tp.containsPoint(ipoint))
|
||||
if (tp.containsPoint2D(ipoint))
|
||||
{
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(ipoint),
|
||||
|
@ -5,7 +5,41 @@
|
||||
|
||||
#define FP_EQUAL(x,y) (fabs((x)-(y)) < 1E-6)
|
||||
|
||||
bool Polygon::containsPoint(const Vector & v)
|
||||
/*
|
||||
* from http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
|
||||
* Return the angle between two vectors on a plane
|
||||
* The angle is from vector 1 to vector 2, positive anticlockwise
|
||||
* The result is between -pi -> pi
|
||||
*/
|
||||
double angle2D(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
double dtheta, theta1, theta2;
|
||||
|
||||
theta1 = atan2(y1,x1);
|
||||
theta2 = atan2(y2,x2);
|
||||
dtheta = theta2 - theta1;
|
||||
while (dtheta > M_PI)
|
||||
dtheta -= 2.0 * M_PI;
|
||||
while (dtheta < -M_PI)
|
||||
dtheta += 2.0 * M_PI;
|
||||
|
||||
return dtheta;
|
||||
}
|
||||
|
||||
bool Polygon::containsPoint2D(const Vector & v) const
|
||||
{
|
||||
double angle_sum = 0.0;
|
||||
for (int i = 0, sz = size(); i < sz; i++)
|
||||
{
|
||||
Vector v1 = *(*this)[i] - v;
|
||||
Vector v2 = *(*this)[(i+1) % sz] - v;
|
||||
double angle = angle2D(v1[0], v1[1], v2[0], v2[1]);
|
||||
angle_sum += angle;
|
||||
}
|
||||
return FP_EQUAL(angle_sum, 2.0 * M_PI);
|
||||
}
|
||||
|
||||
bool Polygon::containsPointConvex(const Vector & v) const
|
||||
{
|
||||
double angle_sum = 0.0;
|
||||
for (int i = 0, sz = size(); i < sz; i++)
|
||||
|
@ -20,7 +20,8 @@ class Polygon : public std::vector< refptr<Vector> >
|
||||
push_back(v);
|
||||
return *this;
|
||||
}
|
||||
bool containsPoint(const Vector & v);
|
||||
bool containsPoint2D(const Vector & v) const;
|
||||
bool containsPointConvex(const Vector & v) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user