updated getRayHits(), fixed bug in Scene::ShapeDistance(Shape *, double)
git-svn-id: svn://anubis/fart/trunk@53 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
ecace9f5e8
commit
f4781e2889
@ -172,6 +172,7 @@ Vector Scene::traceRay(const Ray & ray)
|
|||||||
vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
||||||
{
|
{
|
||||||
vector<ShapeDistance> hits;
|
vector<ShapeDistance> hits;
|
||||||
|
double minSolidDist = 0.0;
|
||||||
|
|
||||||
/* loop through all shapes in the scene */
|
/* loop through all shapes in the scene */
|
||||||
for (vector<Shape *>::iterator it = m_shapes.begin();
|
for (vector<Shape *>::iterator it = m_shapes.begin();
|
||||||
@ -187,7 +188,19 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
|||||||
double dot = normal % ray.getDirection();
|
double dot = normal % ray.getDirection();
|
||||||
if (dot < 0.0) /* cull back faces */
|
if (dot < 0.0) /* cull back faces */
|
||||||
{
|
{
|
||||||
hits.push_back(ShapeDistance(*it, intersections.results[i]));
|
double transparency = (*it)->getTransparency();
|
||||||
|
if (transparency == 0.0 &&
|
||||||
|
(minSolidDist == 0.0
|
||||||
|
|| minSolidDist > intersections.results[i]))
|
||||||
|
{
|
||||||
|
minSolidDist = intersections.results[i];
|
||||||
|
}
|
||||||
|
if (minSolidDist == 0.0
|
||||||
|
|| minSolidDist >= intersections.results[i])
|
||||||
|
{
|
||||||
|
hits.push_back(ShapeDistance(*it,
|
||||||
|
intersections.results[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,6 +208,28 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
|||||||
/* now that we have ALL the hits, sort them by distance */
|
/* now that we have ALL the hits, sort them by distance */
|
||||||
sort(hits.begin(), hits.end());
|
sort(hits.begin(), hits.end());
|
||||||
|
|
||||||
|
double transparency = 1.0;
|
||||||
|
/* now go through them all until we get to the maximum number
|
||||||
|
* of hits, or until the transparency left is below the threshold */
|
||||||
|
for (unsigned int hits_index = 0, sz = hits.size();
|
||||||
|
hits_index < sz;
|
||||||
|
hits_index++)
|
||||||
|
{
|
||||||
|
transparency *= hits[hits_index].first->getTransparency();
|
||||||
|
if (hits_index >= (SCENE_MAX_TRANSPARENT_HITS - 1)
|
||||||
|
|| transparency < SCENE_TRANSPARENCY_THRESHOLD)
|
||||||
|
{
|
||||||
|
/* delete the rest of the hits */
|
||||||
|
for (int i = 0, num_to_del = sz - hits_index - 1;
|
||||||
|
i < num_to_del;
|
||||||
|
i++)
|
||||||
|
{
|
||||||
|
hits.pop_back();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ class Scene
|
|||||||
class ShapeDistance : public std::pair<Shape *, double>
|
class ShapeDistance : public std::pair<Shape *, double>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShapeDistance(Shape *, double) : std::pair<Shape *, double>()
|
ShapeDistance(Shape * shape, double dist)
|
||||||
|
: std::pair<Shape *, double>(shape, dist)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user