Subtract working, but reflected normals being returned... and where did my plane and cyl go?
git-svn-id: svn://anubis/fart/trunk@159 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
ef25fe4a5b
commit
5035c80d94
@ -28,7 +28,7 @@ Color Lighting::computePhong(const refptr<Material> material,
|
|||||||
directionToLight.reflect(surfaceNormal);
|
directionToLight.reflect(surfaceNormal);
|
||||||
|
|
||||||
/* calculate the diffuse term */
|
/* calculate the diffuse term */
|
||||||
double diffuse_coef = directionToLight % surfaceNormal;
|
double diffuse_coef = fabs(directionToLight % surfaceNormal);
|
||||||
if (diffuse_coef > 0.0)
|
if (diffuse_coef > 0.0)
|
||||||
{
|
{
|
||||||
result += diffuseColor
|
result += diffuseColor
|
||||||
|
@ -45,6 +45,29 @@ void Scene::load(const char * filename)
|
|||||||
m_transform.rotate(-20, 0, 1, 0);
|
m_transform.rotate(-20, 0, 1, 0);
|
||||||
m_transform.translate(2, 2, 1);
|
m_transform.translate(2, 2, 1);
|
||||||
|
|
||||||
|
m = new Material();
|
||||||
|
m->setDiffuseColor(Color::magenta);
|
||||||
|
m->setAmbientColor(Color::magenta);
|
||||||
|
|
||||||
|
m_transform.translate(2.5, 1, -1.5);
|
||||||
|
shape1 = new Box(new Vector(1, 1, 1));
|
||||||
|
shape1->setMaterial(m);
|
||||||
|
shape1->setTransform(m_transform);
|
||||||
|
|
||||||
|
m = new Material();
|
||||||
|
m->setDiffuseColor(Color::yellow);
|
||||||
|
m->setAmbientColor(Color::yellow);
|
||||||
|
|
||||||
|
shape2 = new Sphere(0.6);
|
||||||
|
m_transform.translate(-0.5, -0.5, 0.5);
|
||||||
|
shape2->setTransform(m_transform);
|
||||||
|
shape2->setMaterial(m);
|
||||||
|
|
||||||
|
shape = new Subtract(shape1, shape2);
|
||||||
|
m_shapes.push_back(shape);
|
||||||
|
|
||||||
|
m_transform.translate(-2.0, 0.5, 1.0);
|
||||||
|
|
||||||
m = new Material();
|
m = new Material();
|
||||||
m->setDiffuseColor(Color::blue);
|
m->setDiffuseColor(Color::blue);
|
||||||
m->setAmbientColor(Color::blue);
|
m->setAmbientColor(Color::blue);
|
||||||
|
@ -180,10 +180,10 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
|||||||
refptr<Shape> shape = intersections[i].shape;
|
refptr<Shape> shape = intersections[i].shape;
|
||||||
const Vector & isect_point = intersections[i].vector;
|
const Vector & isect_point = intersections[i].vector;
|
||||||
Vector normal = shape->getNormalAt(isect_point);
|
Vector normal = shape->getNormalAt(isect_point);
|
||||||
double dot = normal % ray.getDirection();
|
// double dot = normal % ray.getDirection();
|
||||||
double intersect_dist = (isect_point - 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();
|
||||||
if (transparency == 0.0 &&
|
if (transparency == 0.0 &&
|
||||||
(minSolidDist == 0.0 || minSolidDist > intersect_dist))
|
(minSolidDist == 0.0 || minSolidDist > intersect_dist))
|
||||||
@ -194,7 +194,7 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
|||||||
{
|
{
|
||||||
hits.push_back(ShapeDistance(shape, intersect_dist));
|
hits.push_back(ShapeDistance(shape, intersect_dist));
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,31 +26,21 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
|
|||||||
double dot = - (ray.getDirection() % normal);
|
double dot = - (ray.getDirection() % normal);
|
||||||
bool front = dot > 0.0;
|
bool front = dot > 0.0;
|
||||||
bool left = merged[i].left;
|
bool left = merged[i].left;
|
||||||
if (front)
|
if (left)
|
||||||
{
|
in1 = front;
|
||||||
if (left)
|
|
||||||
in1 = true;
|
|
||||||
else
|
|
||||||
in2 = true;
|
|
||||||
if (!in_bool && in1 && !in2)
|
|
||||||
{
|
|
||||||
/* we found an intersection point with the boolean object */
|
|
||||||
in_bool = true;
|
|
||||||
res.add( merged[i].intersection );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
in2 = front;
|
||||||
|
if (!in_bool && in1 && !in2)
|
||||||
{
|
{
|
||||||
if (left)
|
/* we found an intersection point with the boolean object */
|
||||||
in1 = false;
|
in_bool = true;
|
||||||
else
|
res.add( merged[i].intersection );
|
||||||
in2 = false;
|
}
|
||||||
if (in_bool && !(in1 && !in2))
|
else if (in_bool && !(in1 && !in2))
|
||||||
{
|
{
|
||||||
/* we found an intersection point with the boolean object */
|
/* we found an intersection point with the boolean object */
|
||||||
res.add( merged[i].intersection );
|
res.add( merged[i].intersection );
|
||||||
in_bool = false;
|
in_bool = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user