当前位置: 首页>>代码示例>>C++>>正文


C++ Ray::GetPos方法代码示例

本文整理汇总了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;
}
开发者ID:heyx3,项目名称:heyx3RT,代码行数:9,代码来源:Material_Medium.cpp

示例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);
}
开发者ID:heyx3,项目名称:heyx3RT,代码行数:12,代码来源:BoundingBox.cpp

示例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;
}
开发者ID:heyx3,项目名称:heyx3RT,代码行数:49,代码来源:Material_Dielectric.cpp

示例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;
}
开发者ID:heyx3,项目名称:heyx3RT,代码行数:36,代码来源:Mesh.cpp


注:本文中的Ray::GetPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。