TEST(SphereTest, HitTest){ Sphere s = Sphere(Vec3(1, 1, 0), 1, new Lambertian(Vec3(0.8, 0.3, 0.3))); Ray r = Ray(Vec3(-1, 1, 0), Vec3(1, 0, 0)); hit_record rec; EXPECT_EQ(s.hit(r, 0, MAXFLOAT, rec), true); }
Color trace(Ray * ray, vector<Sphere> balls, int depth){ if (depth == 0){ return Color(0.0f, 0.0f, 0.0f); } float closest_t = 999999999999999999; //FIX ME MAX FLOAT Sphere * closest_sphere = 0; bool hit = false; int id = 0; for (int x = 0; x < balls.size(); x++){ Sphere sphere = ((balls)[x]); if (sphere.hit(ray) == 1){ hit = true; float intersect = sphere.intersect(ray); if (intersect < closest_t){ closest_t = intersect; closest_sphere = &((balls)[x]); id = x; } } } Color rgb(0.0f, 0.0f, 0.0f); if (hit){ //return closest_sphere->diffuse(ray, closest_t) + closest_sphere->specular(ray, closest_t)+trace(; /* for (int a = 0.0f; a < alights.size(); a++){ rgb.red += .3f*alights[a].red; rgb.green += .15*alights[a].green; rgb.blue += 0.0f*alights[a].blue; } */ for (int a = 0.0f; a < plights.size(); a++){ rgb.red += .3f*plights[a].red; rgb.green += .15*plights[a].green; rgb.blue += 0.0f*plights[a].blue; } rgb= rgb + closest_sphere->diffspec(ray, closest_t, id); } return rgb;; }