updating IntersectList to new Shape::IntersectionList format
git-svn-id: svn://anubis/fart/branches/2009-02-23_Shape_IntersectList_Update@144 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
3b3a153559
commit
0c7f85db96
@ -171,15 +171,17 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
|||||||
it != m_shapes.end();
|
it != m_shapes.end();
|
||||||
it++)
|
it++)
|
||||||
{
|
{
|
||||||
Shape::IntersectList intersections = (*it)->intersect(ray);
|
Shape::IntersectionList intersections = (*it)->intersect(ray);
|
||||||
|
|
||||||
for (int i = 0, num_results = intersections.size();
|
for (int i = 0, num_results = intersections.size();
|
||||||
i < num_results;
|
i < num_results;
|
||||||
i++)
|
i++)
|
||||||
{
|
{
|
||||||
Vector normal = (*it)->getNormalAt(intersections[i]);
|
refptr<Shape> shape = intersections[i].first;
|
||||||
|
refptr<Vector> isect_point = intersections[i].second;
|
||||||
|
Vector normal = shape->getNormalAt(*isect_point);
|
||||||
double dot = normal % ray.getDirection();
|
double dot = normal % ray.getDirection();
|
||||||
double intersect_dist = (intersections[i] - ray.getOrigin()).mag();
|
double intersect_dist = ((*isect_point) - ray.getOrigin()).mag();
|
||||||
if (dot < 0.0) /* cull back faces */
|
if (dot < 0.0) /* cull back faces */
|
||||||
{
|
{
|
||||||
double transparency = (*it)->getTransparency();
|
double transparency = (*it)->getTransparency();
|
||||||
@ -190,7 +192,7 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
|||||||
}
|
}
|
||||||
if (minSolidDist == 0.0 || minSolidDist >= intersect_dist)
|
if (minSolidDist == 0.0 || minSolidDist >= intersect_dist)
|
||||||
{
|
{
|
||||||
hits.push_back(ShapeDistance(*it, intersect_dist));
|
hits.push_back(ShapeDistance(shape, intersect_dist));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,11 @@ Box::Box(refptr<Vector> size)
|
|||||||
m_size[2] = fabs(m_size[2]) / 2.0;
|
m_size[2] = fabs(m_size[2]) / 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape::IntersectList Box::intersect(const Ray & ray)
|
Shape::IntersectionList Box::intersect(refptr<Shape> _this, const Ray & ray)
|
||||||
{
|
{
|
||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
|
|
||||||
IntersectList res;
|
IntersectionList res;
|
||||||
/*
|
/*
|
||||||
* Ray equation: R = R0 + tRd
|
* Ray equation: R = R0 + tRd
|
||||||
* x = R0x + tRdx
|
* x = R0x + tRdx
|
||||||
@ -45,7 +45,11 @@ Shape::IntersectList Box::intersect(const Ray & ray)
|
|||||||
&& (dim == 1 || fabs(isect_point[1]) <= m_size[1])
|
&& (dim == 1 || fabs(isect_point[1]) <= m_size[1])
|
||||||
&& (dim == 2 || fabs(isect_point[2]) <= m_size[2]) )
|
&& (dim == 2 || fabs(isect_point[2]) <= m_size[2]) )
|
||||||
{
|
{
|
||||||
res.push_back(m_transform.transform_point(isect_point));
|
res.push_back(
|
||||||
|
Intersection(_this,
|
||||||
|
m_transform.transform_point(
|
||||||
|
isect_point))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Box : public Shape
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Box(refptr<Vector> size);
|
Box(refptr<Vector> size);
|
||||||
IntersectList intersect(const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
Vector getNormalAt(const Vector & pt);
|
Vector getNormalAt(const Vector & pt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -19,10 +19,10 @@ Cyl::Cyl(double bottom_radius, double top_radius, double height)
|
|||||||
m_slope = (m_top_radius - m_bottom_radius) / m_height; /* rise over run */
|
m_slope = (m_top_radius - m_bottom_radius) / m_height; /* rise over run */
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape::IntersectList Cyl::intersect(const Ray & ray)
|
Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
|
||||||
{
|
{
|
||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
IntersectList res;
|
IntersectionList res;
|
||||||
|
|
||||||
/* First intersect with the bottom plane, if it has positive area */
|
/* First intersect with the bottom plane, if it has positive area */
|
||||||
if (m_bottom_radius > 0.0)
|
if (m_bottom_radius > 0.0)
|
||||||
@ -36,7 +36,10 @@ Shape::IntersectList Cyl::intersect(const Ray & ray)
|
|||||||
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
|
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
|
||||||
< m_bottom_radius_2)
|
< m_bottom_radius_2)
|
||||||
{
|
{
|
||||||
res.push_back(m_transform.transform_point(isect_point));
|
res.push_back(
|
||||||
|
Intersection(_this,
|
||||||
|
m_transform.transform_point(isect_point))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +56,10 @@ Shape::IntersectList Cyl::intersect(const Ray & ray)
|
|||||||
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
|
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
|
||||||
< m_top_radius_2)
|
< m_top_radius_2)
|
||||||
{
|
{
|
||||||
res.push_back(m_transform.transform_point(isect_point));
|
res.push_back(
|
||||||
|
Intersection(_this,
|
||||||
|
m_transform.transform_point(isect_point))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +103,10 @@ Shape::IntersectList Cyl::intersect(const Ray & ray)
|
|||||||
Vector isect_point = ray_inv[solutions.results[i]];
|
Vector isect_point = ray_inv[solutions.results[i]];
|
||||||
if (isect_point[2] >= 0.0 && isect_point[2] <= m_height)
|
if (isect_point[2] >= 0.0 && isect_point[2] <= m_height)
|
||||||
{
|
{
|
||||||
res.push_back(m_transform.transform_point(isect_point));
|
res.push_back(
|
||||||
|
Intersection(_this,
|
||||||
|
m_transform.transform_point(isect_point))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Cyl : public Shape
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Cyl(double bottom_radius, double top_radius, double height);
|
Cyl(double bottom_radius, double top_radius, double height);
|
||||||
IntersectList intersect(const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
Vector getNormalAt(const Vector & pt);
|
Vector getNormalAt(const Vector & pt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -7,12 +7,13 @@ Intersect::Intersect(refptr<Shape> shape1, refptr<Shape> shape2)
|
|||||||
m_shape2 = shape2;
|
m_shape2 = shape2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape::IntersectList Intersect::intersect(const Ray & ray)
|
Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ray)
|
||||||
{
|
{
|
||||||
IntersectList res;
|
IntersectionList res;
|
||||||
IntersectList res1 = m_shape1->intersect(ray);
|
IntersectionList res1 = m_shape1->intersect(ray);
|
||||||
IntersectList res2 = m_shape2->intersect(ray);
|
IntersectionList res2 = m_shape2->intersect(ray);
|
||||||
|
|
||||||
|
/* TODO: finish */
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Intersect : public Shape
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Intersect(refptr<Shape> shape1, refptr<Shape> shape2);
|
Intersect(refptr<Shape> shape1, refptr<Shape> shape2);
|
||||||
IntersectList intersect(const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
Vector getNormalAt(const Vector & pt);
|
Vector getNormalAt(const Vector & pt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -13,11 +13,11 @@ Plane::Plane(double a, double b, double c, double d)
|
|||||||
m_d = d;
|
m_d = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape::IntersectList Plane::intersect(const Ray & ray)
|
Shape::IntersectionList Plane::intersect(refptr<Shape> _this, const Ray & ray)
|
||||||
{
|
{
|
||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
|
|
||||||
IntersectList res;
|
IntersectionList res;
|
||||||
/*
|
/*
|
||||||
* Plane equation: ax + by + cz + d = 0
|
* Plane equation: ax + by + cz + d = 0
|
||||||
* Ray equation: R = R0 + tRd
|
* Ray equation: R = R0 + tRd
|
||||||
@ -38,7 +38,10 @@ Shape::IntersectList Plane::intersect(const Ray & ray)
|
|||||||
Solver::Result solutions = solver.solve();
|
Solver::Result solutions = solver.solve();
|
||||||
if (solutions.numResults > 0)
|
if (solutions.numResults > 0)
|
||||||
{
|
{
|
||||||
res.push_back(m_transform.transform_point(ray_inv[solutions.results[0]]));
|
Vector isect_point = ray_inv[solutions.results[0]];
|
||||||
|
res.push_back(
|
||||||
|
Intersection(_this, m_transform.transform_point(isect_point))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Plane : public Shape
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Plane(double a, double b, double c, double d);
|
Plane(double a, double b, double c, double d);
|
||||||
IntersectList intersect(const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
Vector getNormalAt(const Vector & pt);
|
Vector getNormalAt(const Vector & pt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -9,15 +9,18 @@
|
|||||||
#include "util/Material.h"
|
#include "util/Material.h"
|
||||||
#include "util/refptr.h"
|
#include "util/refptr.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class Shape
|
class Shape
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::vector<Vector> IntersectList;
|
typedef std::pair< refptr<Shape> , Vector > Intersection;
|
||||||
|
typedef std::vector< Intersection > IntersectionList;
|
||||||
|
|
||||||
Shape();
|
Shape();
|
||||||
virtual ~Shape();
|
virtual ~Shape();
|
||||||
virtual IntersectList intersect(const Ray & ray) = 0;
|
virtual IntersectionList intersect(refptr<Shape> _this,
|
||||||
|
const Ray & ray) = 0;
|
||||||
virtual Vector getNormalAt(const Vector & pt) = 0;
|
virtual Vector getNormalAt(const Vector & pt) = 0;
|
||||||
|
|
||||||
void setTransform(Transform & t)
|
void setTransform(Transform & t)
|
||||||
|
@ -11,11 +11,11 @@ Sphere::Sphere(double radius)
|
|||||||
m_radius2 = radius * radius;
|
m_radius2 = radius * radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape::IntersectList Sphere::intersect(const Ray & ray)
|
Shape::IntersectionList Sphere::intersect(refptr<Shape> _this, const Ray & ray)
|
||||||
{
|
{
|
||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
|
|
||||||
IntersectList res;
|
IntersectionList res;
|
||||||
QuadraticSolver solver(1.0,
|
QuadraticSolver solver(1.0,
|
||||||
2 * ( ray_inv.getOrigin()[0] * ray_inv.getDirection()[0]
|
2 * ( ray_inv.getOrigin()[0] * ray_inv.getDirection()[0]
|
||||||
+ ray_inv.getOrigin()[1] * ray_inv.getDirection()[1]
|
+ ray_inv.getOrigin()[1] * ray_inv.getDirection()[1]
|
||||||
@ -29,8 +29,10 @@ Shape::IntersectList Sphere::intersect(const Ray & ray)
|
|||||||
{
|
{
|
||||||
if (quadSolutions.results[i] >= 0.0)
|
if (quadSolutions.results[i] >= 0.0)
|
||||||
{
|
{
|
||||||
res.push_back(m_transform.transform_point(
|
Vector isect_point = ray_inv[quadSolutions.results[i]];
|
||||||
ray_inv[quadSolutions.results[i]]));
|
res.push_back(
|
||||||
|
Intersection(_this, m_transform.transform_point(isect_point))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -8,7 +8,7 @@ class Sphere : public Shape
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Sphere(double radius);
|
Sphere(double radius);
|
||||||
IntersectList intersect(const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
Vector getNormalAt(const Vector & pt);
|
Vector getNormalAt(const Vector & pt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user