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


C++ Vec3f::Fix255方法代码示例

本文整理汇总了C++中Vec3f::Fix255方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3f::Fix255方法的具体用法?C++ Vec3f::Fix255怎么用?C++ Vec3f::Fix255使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vec3f的用法示例。


在下文中一共展示了Vec3f::Fix255方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RayTracer

Vec3f Scene::RayTracer(Line l,Vec3f& IntersectPoint,double strength) const{
    if (strength < 0.01)
        return Vec3f(0,0,0);
    Vec3f N;
    Material material;
    Vec3f Color;
    if (getIntersection(l,N,IntersectPoint,Color,material)){
        double len = (IntersectPoint - l.start_point).Len();
        if ((l.start_point + l.dir * len - IntersectPoint).Len() > EPS){
            qDebug() << "fuck" << (l.start_point + l.dir * len - IntersectPoint).Len();
            l.start_point.debug();
            l.dir.debug();
            IntersectPoint.debug();
        }
        if (material.refract_n > 1)
            strength *= exp(0.05 -len * material.absorptivity);
        double I = 0;
        /*for (unsigned i = 0; i < _lightsources.size();i++){
            Line light(IntersectPoint,_lightsources[i] - IntersectPoint);
            if (!getIntersection(light,a,b,c,d,Len(_lightsources[i] - IntersectPoint)- EPS)){
                Vec3f Ref =  light.dir - N * 2 * (light.dir * N);
                double Ii = material.Kd * abs(N * light.dir);
                if (Ref * l.dir > EPS)
                    Ii += material.Ks * pow(Ref * l.dir,material.Ksn);
                I += Ii * Ii/_lightsources.size();
            }
        }*/
        Line light(IntersectPoint,_lightsources[0] - IntersectPoint);
        Vec3f Ref =  light.dir - N * 2 * (light.dir * N);
        double Ii = material.Kd * abs(N * light.dir);
        if (Ref * l.dir > EPS)
            Ii += material.Ks * pow(Ref * l.dir,material.Ksn);
        double Brightness;
        if (softshape){
            bools Done,Reach;
            memset(Done,0,sizeof(Done));
            //Brightness = getBrightness(LightUL,LightUR,LightDR,LightDL,IntersectPoint);
            Brightness = getBrightness(0,LightNum,0,LightNum,IntersectPoint,Done,Reach);
        }
        else{
            Vec3f a,b,c;
            Material d;
            Brightness = getIntersection(light,a,b,c,d,Len(_lightsources[0] - IntersectPoint)- EPS)?0:1;
        }
        I = Ii * Brightness + material.Ka;
        if (I > 1 - EPS){
            I = 1 - EPS;
        }
        I = I * strength;
        double Cosi = l.dir * N;
        double Sini = abs(Cosi) < 1 - EPS?sqrt(1 - Cosi * Cosi):0;
        double Sinr = Sini * material.refract_n;
        Line reflect(IntersectPoint,l.dir - N * 2 * Cosi);
        Line refract = reflect;
        if (Sinr < 1 - EPS){
            double Cosr = sqrt(1 - Sinr * Sinr);
            Vec3f tmp = l.dir - N * Cosi;
            tmp.Normalize();
            Vec3f rf =  N * Cosr + tmp * Sinr;
            refract = Line(IntersectPoint,rf);
        }
        if (REF){
            Vec3f iii;
            Color = Color * I * material.diffuse_reflectance
                    + Color.mul(RayTracer(reflect,iii,material.reflect_rate * strength))
                    + Color.mul(RayTracer(refract,iii,material.refract_rate * strength));
        }
        else
            Color = Color * I * material.diffuse_reflectance;
        Color.Fix255();
        return Color;
    }
    else{
        double I = 1;
        for (unsigned i = 0; i < _lightsources.size();i++){

        }
        return Vec3f(0,0,0) * I * strength;
    }
}
开发者ID:nbajiaoshi,项目名称:RayTrace,代码行数:80,代码来源:scene.cpp


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