File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -22,18 +22,20 @@ Mesh::Mesh(ObjReader& reader):material(std::move(reader.curMaterial)){
2222bool Mesh::hit (const Ray& ray, double t_min, double t_max, HitRecord& rec) const {
2323 Ray transformed_ray = ray.transform (inverseTransform);
2424
25- bool hit_anything = false ;
26- rec.t = INFINITY;
25+ rec.t = t_max;
2726 for (const auto & triangle : mesh) {
28- if (triangle.hit (transformed_ray, 0.001 , rec.t , rec)) {
29- hit_anything = true ;
30- rec.p = transform * transformed_ray.at (rec.t );
31- Vector3 world_normal = (inverseTransposeTransform * rec.normal ).normalize ();
32- rec.set_face_normal (ray, world_normal);
33- rec.material = material;
34- }
27+ triangle.hit (transformed_ray, 0.001 , rec.t , rec);
3528 }
36- return hit_anything;
29+
30+ if (rec.t < t_max) {
31+ rec.p = transform * transformed_ray.at (rec.t );
32+ Vector3 world_normal = (inverseTransposeTransform * rec.normal ).normalize ();
33+ rec.set_face_normal (ray, world_normal);
34+ rec.material = material;
35+ return true ;
36+ }
37+
38+ return false ;
3739};
3840
3941};
You can’t perform that action at this time.
0 commit comments