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(); }