本文整理汇总了C++中Ray::GetPos方法的典型用法代码示例。如果您正苦于以下问题:C++ Ray::GetPos方法的具体用法?C++ Ray::GetPos怎么用?C++ Ray::GetPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ray
的用法示例。
在下文中一共展示了Ray::GetPos方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Scatter
bool Material_Medium::Scatter(const Ray& rIn, const Vertex& surface,
const Shape& shpe, FastRand& prng,
Vector3f& attenuation, Vector3f& emission,
Ray& rOut) const
{
attenuation = Albedo->GetValue(rIn, prng, &shpe, &surface);
rOut = Ray(rIn.GetPos(), prng.NextUnitVector3());
return true;
}
示例2: RayIntersects
bool BoundingBox::RayIntersects(const Ray& ray, float tMin, float tMax) const
{
Vector3f dirFrac = ray.GetDir().Reciprocal();
Vector3f minD = (Min - ray.GetPos()) * dirFrac,
maxD = (Max - ray.GetPos()) * dirFrac;
float _tMin = max(max(min(minD.x, maxD.x), min(minD.y, maxD.y)), min(minD.z, maxD.z)),
_tMax = min(min(max(minD.x, maxD.x), max(minD.y, maxD.y)), max(minD.z, maxD.z));
return (_tMin >= tMin && _tMin <= tMax) ||
(_tMax >= tMin && _tMax <= tMax);
}
示例3: Scatter
bool Material_Dielectric::Scatter(const Ray& rIn, const Vertex& surface,
const Shape& shpe, FastRand& prng,
Vector3f& attenuation, Vector3f& emission,
Ray& rOut) const
{
float indexOfRefraction = (float)IndexOfRefraction->GetValue(rIn, prng, &shpe, &surface);
float ratioOfIndices;
Vector3f outwardNormal;
float cosAngle;
if (surface.Normal.Dot(rIn.GetDir()) > 0.0f)
{
ratioOfIndices = indexOfRefraction;
outwardNormal = -surface.Normal;
cosAngle = indexOfRefraction * rIn.GetDir().Dot(surface.Normal) / rIn.GetDir().Length();
}
else
{
ratioOfIndices = 1.0f / indexOfRefraction;
outwardNormal = surface.Normal;
cosAngle = -rIn.GetDir().Dot(surface.Normal) / rIn.GetDir().Length();
}
//Try refracting. Possibly reflect instead.
float reflectionChance;
Vector3f refracted;
if (rIn.GetDir().Refract(outwardNormal, ratioOfIndices, refracted))
{
//Approximation of chance of refraction by Christophe Schlick:
float r0 = (1.0f - indexOfRefraction) / (1.0f + indexOfRefraction);
r0 *= r0;
reflectionChance = r0 + ((1.0f - r0) * std::powf((1.0f - cosAngle), 5.0f));
}
else
{
reflectionChance = 1.01f;
}
if (prng.NextFloat() < reflectionChance)
rOut = Ray(surface.Pos, rIn.GetDir().Reflect(surface.Normal));
else
rOut = Ray(surface.Pos, refracted);
//Move the ray forward a tiny bit to get off the surface.
rOut.SetPos(rOut.GetPos() + (rOut.GetDir() * PushoffDist));
attenuation = Vector3f(1.0f, 1.0f, 1.0f);
return true;
}
示例4: CastRay
bool Mesh::CastRay(const Ray& ray, Vertex& outHit, FastRand& prng,
float tMin, float tMax) const
{
//TODO: Try not bothering to normalize the local ray's direction.
Ray newRay(Tr.Point_WorldToLocal(ray.GetPos()),
Tr.Dir_WorldToLocal(ray.GetDir()).Normalize());
if (!bounds.RayIntersects(newRay, tMin, tMax))
return false;
const Triangle* closest = nullptr;
float hitDist = std::numeric_limits<float>().infinity();
for (size_t i = 0; i < Tris.GetSize(); ++i)
{
float tempT;
Vector3f tempPos;
if (Tris[i].RayIntersect(newRay, tempPos, tempT, tMin, tMax))
{
if (tempT < hitDist)
{
hitDist = tempT;
outHit.Pos = tempPos;
closest = &Tris[i];
}
}
}
if (closest != nullptr)
{
closest->GetMoreData(outHit, Tr);
return true;
}
return false;
}