Skip to content

Using HitRecord::t before declaring it  #428

@Krenodeno

Description

@Krenodeno

In Chapter 6, at listing 13, hit_record definition is

struct hit_record {
    vec3 p;
    vec3 normal;
};

and then in listing 14, there is reference to a t member that do not exist... yet.

bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
[...]
            rec.t = temp;
            rec.p = r.at(rec.t);
            rec.normal = (rec.p - center) / radius;

hit_record's member t is defined later as the time:
I know that we’ll also want motion blur at some point, so I’ll also add a time input variable.
Therefore I cannot see any relation to time in the calculations of temp listing 18:

auto a = r.direction().length_squared();
auto half_b = dot(oc, r.direction());
auto root = sqrt(discriminant);
auto temp = (-half_b - root)/a;

If I'm correct, at this point t is more like a depth buffer, as to see listing 19.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions