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


C++ Cylinder::intersect方法代码示例

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


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

示例1: writeTest

void IntersectionUI::writeTest() const {
    // creates a deterministic sequence of ray positions and directions
    // and writes the resulting intersections to a file
    // you must add the proper intersect calls for this file to be generated
    
    double invBase[5] = {1.0 / 2.0, 1.0 / 3.0, 1.0 / 5.0, 1.0 / 7.0, 1.0 / 11.0};
    double values[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
    std::ofstream file("../intersections.txt");
    file.precision(4);

    const int seed = static_cast<int>(intersectionUI->m_iSeed->value());
    // generate a halton sequence to pick position/ray combinations
    // skip the first 'seed' values
    for (int i = 0; i < seed; i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
    }
    for (int i = seed; i < (seed + 1638); i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
        // create the ray from the five random values
        // compute ray origin
        Point3 p;
        p[0] = values[4] * sin(values[0] * M_PI) * cos(values[1] * 2.0 * M_PI);
        p[1] = values[4] * sin(values[0] * M_PI) * sin(values[1] * 2.0 * M_PI);
        p[2] = values[4] * cos(values[0] * M_PI);
        // compute ray direction
        Vector3 dir;
        dir[0] = sin(values[2] * M_PI) * cos(values[3] * 2.0 * M_PI);
        dir[1] = sin(values[2] * M_PI) * sin(values[3] * 2.0 * M_PI);
        dir[2] = cos(values[2] * M_PI);
        
        HitRecord cubeHr, cylinderHr, coneHr, sphereHr;
        // ToDo: intersect with your shapes here and store the result
        // in the appropriate hit record
        //cube.intersect(p, dir);
		Cube cube = Cube(1);
		cubeHr = *(cube.intersect(p, dir));
        //cylinder.intersect(p, dir);
		Cylinder cylinder = Cylinder(1, 1);
		cylinderHr = *(cylinder.intersect(p, dir));
        //coneHr = cone.intersect(p, dir);
		Cone cone = Cone(1, 1);
		coneHr = *(cone.intersect(p, dir));
        //sphereHr = sphere.intersect(p, dir);
		Sphere sphere = Sphere(1);
		sphereHr = *(sphere.intersect(p, dir));

        // write out
        file << i << " Cube     " << cubeHr     << std::endl;
        file << i << " Cylinder " << cylinderHr << std::endl;
        file << i << " Cone     " << coneHr     << std::endl;
        file << i << " Sphere   " << sphereHr   << std::endl;
    }
    file.close();
}
开发者ID:mdally,项目名称:RayTracer,代码行数:80,代码来源:IntersectionUI.cpp


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