diff --git a/hittables/rt_instance.c b/hittables/rt_instance.c index e814de7..debc017 100644 --- a/hittables/rt_instance.c +++ b/hittables/rt_instance.c @@ -86,7 +86,7 @@ static bool rt_instance_hit(const rt_hittable_t *hittable, const ray_t *ray, dou vec3_add(&record->p, instance->offset); vec3_t new_normal = rt_mat3_mul_vec3(&instance->transform_matrix_bb, &record->normal); - rt_hit_record_set_front_face(record, &transformed_ray, &new_normal); + rt_hit_record_set_front_face(record, ray, &new_normal); return true; } @@ -105,8 +105,6 @@ static bool rt_instance_bb(const rt_hittable_t *hittable, double time0, double t return false; } - hittable_bb = rt_aabb(vec3_sum(hittable_bb.min, instance->offset), vec3_sum(hittable_bb.max, instance->offset)); - vec3_t min = hittable_bb.min, max = hittable_bb.max; for (int i = 0; i < 2; i++) { @@ -119,7 +117,6 @@ static bool rt_instance_bb(const rt_hittable_t *hittable, double time0, double t k * hittable_bb.max.z + (1 - k) * hittable_bb.min.z); vec3_t tester = rt_mat3_mul_vec3(&instance->transform_matrix_bb, &point); - for (int c = 0; c < 3; c++) { min.components[c] = fmin(min.components[c], tester.components[c]); @@ -128,8 +125,7 @@ static bool rt_instance_bb(const rt_hittable_t *hittable, double time0, double t } } } - - *out_bb = rt_aabb(min, max); + *out_bb = rt_aabb(vec3_sum(min, instance->offset), vec3_sum(max, instance->offset)); return true; } diff --git a/scenes/rt_scenes.c b/scenes/rt_scenes.c index 64f85e0..3217ba2 100644 --- a/scenes/rt_scenes.c +++ b/scenes/rt_scenes.c @@ -179,8 +179,8 @@ rt_hittable_list_t *rt_scene_instance_test(void) rt_hittable_t *box = rt_box_new(point3(-1, -1, -1), point3(1, 1, 1), green); rt_hittable_t *instance = rt_instance_new(box); - rt_instance_rotate_y(instance, 0); - rt_instance_translate(instance, point3(1, 0, 0)); + rt_instance_rotate_y(instance, 45); + rt_instance_translate(instance, point3(1, 0, 0.1)); rt_hittable_list_add(objects, instance); rt_hittable_list_add(objects, rt_box_new(point3(-0.25, -0.25, -0.25), point3(0.25, 0.25, 0.25), red)); @@ -332,8 +332,9 @@ rt_hittable_list_t *rt_scene_metal_test(void) rt_hittable_list_add(objects, rt_sphere_new(point3(2, 2, 0), 1, rt_mt_metal_new(colour(0.8, 0.8, 0.9), 1.0))); rt_hittable_t *box_instance = - rt_instance_new(rt_box_new(point3(-1, 0, 10), point3(1, 2, 12), rt_mt_metal_new(colour(0.8, 0.8, 0.9), 0.0))); - rt_instance_rotate_y(box_instance, 10); + rt_instance_new(rt_box_new(point3(-1, -1, -1), point3(1, 1, 1), rt_mt_metal_new(colour(0.8, 0.8, 0.9), 0.0))); + rt_instance_rotate_y(box_instance, 45); + rt_instance_translate(box_instance, vec3(2, 1, 11)); rt_hittable_list_add(objects, box_instance); return objects;