本文整理汇总了C++中Sphere::hit方法的典型用法代码示例。如果您正苦于以下问题:C++ Sphere::hit方法的具体用法?C++ Sphere::hit怎么用?C++ Sphere::hit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sphere
的用法示例。
在下文中一共展示了Sphere::hit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Sphere
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);
}
示例2: trace
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;;
}