Docsity

Advanced Computer Graphics: Transforming Objects - Intersecting & Instancing, Slides of Computer Graphics

Partial preview of the text

Download Advanced Computer Graphics: Transforming Objects - Intersecting & Instancing and more Slides Computer Graphics in PDF only on Docsity!

Advanced Topics in

Computer Graphics

Transform ing Objects – Chapter 21

Outline

 Review of Affine Transformations

 Intersecting Transformed objects

 Instancing

 Beveled Objects

Review of Affine

Transformations

 Translation:

Review of Affine

Transformations

 Scaling:

Review of Affine

Transformations

 Inverse transformations:

(Suffern, 412)

Intersecting

Transformed Objects

 Problem Setup:

 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)

Intersecting

Transformed Objects

 Simple illustration of procedure: Sphere

p’=Tp

p=T -1^ p’

n=T -T^ n’

n’=T T^ n

Intersecting Transformed

Objects – finding p’

 Computing ray’:

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)

 Computing o’ and d’ :

(Suffern, 420)

Intersecting Transformed

Objects – finding p’

 Computing p’ :

“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)

Therefore:

p’ = o + td

Intersecting Transformed

Objects – finding p’

Instancing

 Instead of creating a new object every time

we want to show a different transformation

of the same object, we create a pointer to

that object:

 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

Instancing

 Instances can be nested:

 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.

Instancing

256 instances of sphere

Instancing

 Code for previous image:

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); } }