本文整理汇总了C++中Primitive::isLight方法的典型用法代码示例。如果您正苦于以下问题:C++ Primitive::isLight方法的具体用法?C++ Primitive::isLight怎么用?C++ Primitive::isLight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Primitive
的用法示例。
在下文中一共展示了Primitive::isLight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Color
Primitive *Engine::raytrace(const Ray &ray, Color &acc, unsigned int depth, double rIndex, double &dist)
{
if (depth > TRACEDEPTH) return nullptr;
// trace primary ray
dist = std::numeric_limits<double>::max();
Vector3 pi;
primitives &primitives = scene.getPrimitives();
Primitive *prim = nullptr;
hitStatus result = MISS;
// find the nearest intersection
for (primitives::iterator s = primitives.begin(); s != primitives.end(); s++)
{
hitStatus res;
if ((res = (*s)->Intersect(ray, dist)) != MISS)
{
prim = s->get();
result = res; // 0 = miss, 1 = hit, -1 = hit from inside primitive
}
}
// no hit, terminate ray
if (!prim) return nullptr;
// handle intersection
if (prim->isLight())
{
// we hit a light, stop tracing
acc = Color(1.0, 1.0, 1.0);
}
else
{
// determine color at point of intersection
pi = ray.getOrigin() + (ray.getDirection() * dist);
// trace lights
for (primitives::iterator l = primitives.begin(); l != primitives.end(); l++)
{
if ((*l)->isLight())
{
Primitive *light = l->get();
// calculate diffuse shading
Vector3 L = ((Sphere *)light)->getCenter() - pi;
L.normalize();
Vector3 N = prim->getNormal(pi);
if (prim->getMaterial().getDiffuse() > 0)
{
double dot = N.dot(L);
if (dot > 0)
{
double diff = dot * prim->getMaterial().getDiffuse();
// add diffuse component to ray color
acc += diff * (prim->getMaterial().getColor() * light->getMaterial().getColor());
}
}
}
}
}
// return pointer to primitive hit by primary ray
return prim;
}