我有这些类Sphere
,Triangle
它们都是Intersectable
. Intersectable
有一个公共成员变量colour
。考虑以下代码片段:
float t_min = 100000.0f;
pair<float, f3Vector> point_hit;
Intersectable * object_hit;
Triangle triangle;
Sphere sphere_trans;
bool hit = false;
//loop through triangles
for(unsigned int i = 0; i < mesh->tvi.size(); i++){
...
triangle = Triangle((fRGB)mesh->color[mesh->tci[i].c0], va.toVector3(), vb.toVector3(), vc.toVector3());
point_hit = triangle.intersect(orig, dir, c_near, c_far);
if(point_hit.first != 0.0f && point_hit.first < t_min){
object_hit = ▵
std::cout << "color1 " << object_hit->color << std::endl;
hit = true;
...
}
}
// loop through spheres
for(unsigned int j = 0; j < spheres.size(); j++){
...
sphere_trans = Sphere(sphere.color, center3, sphere.getRadius());
point_hit = sphere_trans.intersect(orig, dir, c_near, c_far);
if(point_hit.first != 0 && point_hit.first < t_min){
object_hit = &sphere_trans;
std::cout << "color1 " << object_hit->color << std::endl;
hit = true;
...
}
}
if(hit){
std::cout << "color2 " << object_hit->color << std::endl;
}
我期待如果我有一个输出,color1 (1 0 0)
并且下一个输出是一个输出color2 (...)
颜色的值应该是相同的。但是,这不会发生。事实上,我总是得到相同的输出color2 (...)
。你能告诉我我做错了什么吗?谢谢!