

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















Transform ing Objects – Chapter 21
(Suffern, 412)
We have a transformed object or primitive, and want to calculate the hit point(s) with the ray, and the normal to the object at that hit point.
Problem: How exactly can we do this without complicated arithmetic?
Solution: Transform the ray instead of the object! (so that we can take advantage of a simple closed form solution)
ray => p’ = o + td p’ = Tp p=T-1p’ p =T-1p’ = T-1o + tT-1d T-1o = o’ T-1d = d’ p = o’+td’ => ray’
(blue = unknown)
(Suffern, 420)
“if the closest hit point p of the inverse
transformed ray with the untransformed object occurs at t=t 0 , the closest hit point p’ of the original ray with the transformed object occurs at the same value of t: t=t 0 “ (Suffern, 421)
p’ = o + td
The instance class implements instancing by: Having a pointer to the object Storing a the forward and inverse transformation matrices, and materials of that instance. Each instance transforms its own local copy of the ray. Every time the instance is transformed by a new transform T, its forward matrix (which defaults to the unit matrix) is multiplied by T, and its inverse matrix is multiplied by T -1 Docsity.com
An instance can point to another instance: The hit function is called recursively until the object is untransformed.
This makes it easier to implement compound objects. Q: Why? A: Parts of the object can be transformed relative to a single part of the object. The entire object is then transformed relative to world coordinates. A: Nested instances can partly share material properties.
256 instances of sphere
int n = 16;
for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { Instance* ellipsoid_ptr = new Instance(new Sphere); ellipsoid_ptr->set_material(phong_ptr); ellipsoid_ptr->scale(1, 4, 1); ellipsoid_ptr->translate(0, 10, 0); ellipsoid_ptr->rotate_z((360.0f/(float)n)(float)i); ellipsoid_ptr->rotate_x((360.0f/(float)n)(float)j); add_object(ellipsoid_ptr); } }