本文整理汇总了C++中Light::IsDirectional方法的典型用法代码示例。如果您正苦于以下问题:C++ Light::IsDirectional方法的具体用法?C++ Light::IsDirectional怎么用?C++ Light::IsDirectional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Light
的用法示例。
在下文中一共展示了Light::IsDirectional方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsLightUnblocked
bool Scene::IsLightUnblocked(const Light& light, const Point<float>& point) const
{
Point<float> lightPosition = light.GetPosition();
Vector3<float> lightDirection = light.IsDirectional() ? Vector3<>(lightPosition.x, lightPosition.y, lightPosition.z) : lightPosition - point;
// Create a ray to cast at the direction of the light:
Ray ray(point, lightDirection);
// Add a little bit of offset to handle the numeric errors:
ray.origin = ray.origin + ray.direction * 0.00001f;
// Calculate distance between the light and the intersection point:
float lightDistance = lightDirection.length();
// Find if there is any object between the light and the object:
if (!IsLightUnblocked<Sphere>(m_spheres, light, lightDistance, ray) ||
!IsLightUnblocked<GenericMesh>(m_genericMeshes, light, lightDistance, ray)
)
return false;
return true;
}
示例2:
void
TerrainPatch::Illuminate(Color ambient, List<Light>& lights)
{
if (!model || model->NumVerts() < 1) return;
Surface* s = model->GetSurfaces().first();
if (!s) return;
illuminating = true;
// clear the solid lights to ambient:
VertexSet* vset = s->GetVertexSet();
int nverts = vset->nverts;
DWORD aval = ambient.Value();
for (int i = 0; i < nverts; i++) {
vset->diffuse[i] = aval;
}
TerrainRegion* trgn = terrain->GetRegion();
bool eclipsed = false;
bool first = terrain->IsFirstPatch(this);
if (trgn && !first) {
eclipsed = trgn->IsEclipsed();
}
// for sun and back lights:
ListIter<Light> iter = lights;
while (++iter) {
Light* light = iter.value();
if (!light->IsDirectional()) // only do sun and
continue; // back lights
if (light->CastsShadow() && first) {
eclipsed = light->Location().y < -100 || // has sun set, or
scene->IsLightObscured(vset->loc[0], // is sun in eclipse
light->Location(), // by orbital body
radius); // such as a moon?
}
if (!light->CastsShadow() || !eclipsed) {
Vec3 vl = light->Location();
vl.Normalize();
for (int i = 0; i < nverts; i++) {
Vec3& nrm = vset->nrm[i];
double val = 0;
double gain = vl * nrm;
if (gain > 0) {
val = light->Intensity() * (0.85 * gain);
if (val > 1)
val = 1;
}
if (val > 0.01)
vset->diffuse[i] = ((light->GetColor().dim(val)) + vset->diffuse[i]).Value();
}
}
}
// combine blend weights:
if (ndetail >= 2) {
for (int i = 0; i < nverts; i++) {
vset->diffuse[i] = vset->specular[i] | (vset->diffuse[i] & 0x00ffffff);
}
}
if (trgn && first) {
trgn->SetEclipsed(eclipsed);
}
InvalidateSurfaceData();
illuminating = false;
}