bool sub-objects using relative coordinates, shape definitions using relative coordinates, this allows transform blocks in each, and shape references to combine absolute transform with the relative transform

git-svn-id: svn://anubis/fart/trunk@287 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2010-07-09 19:37:05 +00:00
1 parent b4a2c8ef8e
commit b0dfa2ee1f
7 files changed
+46 -30

No files matched your search

+8 -7
View File
@@ -31,9 +31,10 @@ Intersect::Intersect(const vector< refptr<Shape> > & shapes)
Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ray)
{
IntersectionList res1 = m_shape1->intersect(m_shape1, ray);
IntersectionList res2 = m_shape2->intersect(m_shape2, ray);
BoolIntersectionList merged(res1, res2, ray.getOrigin());
Ray ray_inv = m_inverse.transform_ray(ray);
IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv);
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
IntersectionList res;
bool in1 = false, in2 = false;
@@ -45,7 +46,7 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
double dot = - (ray_inv.getDirection() % normal);
bool back = dot < 0.0;
bool left = merged[i].left;
if (back)
@@ -65,7 +66,7 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
for (int i = 0, sz = merged.size(); i < sz; i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
double dot = - (ray_inv.getDirection() % normal);
bool front = dot > 0.0;
bool left = merged[i].left;
if (front)
@@ -78,7 +79,7 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
{
/* we found an intersection point with the boolean object */
in_bool = true;
res.add( merged[i].intersection );
res.add( merged[i].intersection.transform(m_transform) );
}
}
else
@@ -86,7 +87,7 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
if (in_bool && in1 && in2)
{
/* we found an intersection point with the boolean object */
res.add( merged[i].intersection );
res.add( merged[i].intersection.transform(m_transform) );
}
if (left)
in1 = false;
+8 -2
View File
@@ -29,6 +29,12 @@ class Shape
refptr<Shape> shape;
Vector position;
Vector normal;
Intersection transform(Transform & t)
{
return Intersection(shape,
t.transform_point(position),
t.transform_normal(normal));
}
};
class BoolIntersection
{
@@ -103,10 +109,10 @@ class Shape
const Ray & ray) = 0;
virtual refptr<Shape> clone() = 0;
void setTransform(Transform & t)
void setTransform(const Transform & t)
{
m_transform = t;
m_inverse = t.getInverse();
m_inverse = m_transform.getInverse();
}
Transform & getTransform() { return m_transform; }
+8 -7
View File
@@ -31,9 +31,10 @@ Subtract::Subtract(const vector< refptr<Shape> > & shapes)
Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray)
{
IntersectionList res1 = m_shape1->intersect(m_shape1, ray);
IntersectionList res2 = m_shape2->intersect(m_shape2, ray);
BoolIntersectionList merged(res1, res2, ray.getOrigin());
Ray ray_inv = m_inverse.transform_ray(ray);
IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv);
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
IntersectionList res;
bool in1 = false, in2 = false;
@@ -45,7 +46,7 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
double dot = - (ray_inv.getDirection() % normal);
bool back = dot < 0.0;
bool left = merged[i].left;
if (back)
@@ -65,7 +66,7 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
for (int i = 0, sz = merged.size(); i < sz; i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
double dot = - (ray_inv.getDirection() % normal);
bool front = dot > 0.0;
bool left = merged[i].left;
if (left)
@@ -81,7 +82,7 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
Intersection i = bi.intersection;
if ( ! left ) /* if this point came from object B (A - B) */
i.normal = - i.normal;
res.add(i);
res.add(i.transform(m_transform));
}
else if (in_bool && !(in1 && !in2))
{
@@ -91,7 +92,7 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
Intersection i = bi.intersection;
if ( ! left ) /* if this point came from object B (A - B) */
i.normal = - i.normal;
res.add(i);
res.add(i.transform(m_transform));
in_bool = false;
}
}
+8 -7
View File
@@ -32,9 +32,10 @@ Union::Union(const vector< refptr<Shape> > & shapes)
Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
{
IntersectionList res1 = m_shape1->intersect(m_shape1, ray);
IntersectionList res2 = m_shape2->intersect(m_shape2, ray);
BoolIntersectionList merged(res1, res2, ray.getOrigin());
Ray ray_inv = m_inverse.transform_ray(ray);
IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv);
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
IntersectionList res;
bool in1 = false, in2 = false;
@@ -46,7 +47,7 @@ Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
double dot = - (ray_inv.getDirection() % normal);
bool back = dot < 0.0;
bool left = merged[i].left;
if (back)
@@ -66,7 +67,7 @@ Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
for (int i = 0, sz = merged.size(); i < sz; i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
double dot = - (ray_inv.getDirection() % normal);
bool front = dot > 0.0;
bool left = merged[i].left;
if (front)
@@ -79,7 +80,7 @@ Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
{
/* we found an intersection point with the boolean object */
in_bool = true;
res.add( merged[i].intersection );
res.add( merged[i].intersection.transform(m_transform) );
}
}
else
@@ -91,7 +92,7 @@ Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
if (in_bool && !(in1 || in2))
{
/* we found an intersection point with the boolean object */
res.add( merged[i].intersection );
res.add( merged[i].intersection.transform(m_transform) );
in_bool = false;
}
}