# Ray tracing the next week: understanding Instances

My question is not about the code, but it's about the approach used by the author Peter Shirley (and apparently common practice in ray tracers) of handling Instances. To understand the question it's necessary to be familiar with the book, because posting the code for every class involved is not feasible. Something I don't understand is how rays behave.

Let's consider the traslation. The idea is to offset the origin, and check if the new ray - which is now shot from the new origin with the same direction of the original ray - hits the object. If so, we shift the hitting point by an equal and opposite offset. Two questions:

1) Why is it not sufficient to shoot rays from the "standard" origin, and offset the hitting point without actually shifting the origin first? Example: the ray is shot, if it hits the object in point (x,y) I move the hitting point by 2 (x+2, y+2) and store it.

2) The hit function of the class translate is only called when the original ray hits the object? Because in that case, the translation would not result in the whole object, since it would only store those points that are first hit by the original ray, and for which the new ray hits the object again.

There are two ways to 'translate' your object. The first is by moving each point of your object by the desired translation. The second is by translating the origin of your coordinate system. In this case it's the latter. Basically it turns out to be the same, whether you translate your object by a vector $$\vec{t}$$ or whether you translate your origin by $$-\vec{t}$$.
For 2) note that you only care about the intersected points (since that is what you use to compute the pixel color), so you compute the offset only when you need it. So yes, you do translate the origin of the ray at each intersect, it's the same as translating the object though (at each ray intersect), since $$\vec{p}+\vec{t} - \vec{o} = \vec{p} - (\vec{o}-\vec{t})$$.
• @MauroComi I don't get what you mean by 'hit the class translation'. You don't offset only a part of the object, you offset the ray origin, which is the same as offsetting the object. Note that if you translate an object, rays that previously intersected it, will not anymore - it's the same thing. What you should take away from this is that coordinate system translation by $-\vec{t}$ and object translation by $\vec{t}$ are the same thing. If you formulate it in terms of matrices, you can consider even more general transformations. Feb 22, 2019 at 16:42
• Thanks for our explanation. With "hit the class translation" I mean that I offset the origin inside the function translate::hit(), which means that this function is called when the original ray hits a Hitable object inside the class translate? Feb 22, 2019 at 17:36