CSC418 - Notes
Topic 4: Modeling & Transformation

Navigation: back up next notes exercises

Key concepts & Readings

OpenGL

For line, triangle, and polygon drawing also see this.

Polyhedra Meshes

To define a polygon:

    glBegin(GL_POLYGON); /* defining a simple, flat polygon */
       for each vertex i
           glVertex3fv( vertex_list[i] ); /* ith vertex */
           glNormal3fv( normal_list[i] ); /* normal of the ith vertex */
    glEnd();

There are several things to note:

M can be setup as follows:

  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();
  glTranslatef(2.0, 1.0, 0.0);
  glRotatef( -3.14/2.0, 0.0, 0.0, 1.0); 
  glScalef(2.0, 2.0, 2.0);
  ...

which produces the matrix M = trans(2,1,0) rot(z,-90) scale(2,2,2) ....
Another way of loading M is to use:

  glMatrixMode( GL_MODELVIEW );
  glLoadMatrixf( M );

OpenGL functions for setting up modelling transformations

modelling transformation
modelview matrix

glTranslatef(...)
glRotatef(...) 
glScalef(...) 

Notes

Planes

Equation of a Plane using a point (x1,y1,z1) and a normal vector (nx,ny,nz):
Equation of a Plane using three non-collinear points (x1,y1,z1), (x2,y2,z2), and (x3,y3,z3):

Polyhedra Meshes


A teapot modeled using triangles (Courtesy http://www.siggraph.org)

Facet & Vertex Normals

How to calculate facet normals?
How to calculate vertex normals?

Bilinear Interpolation

to be written

3D Transformation

Also see 2D Transformations

Definitions Related to Geometric Transformations

affine transformation

A transformation which preserves the parallelism of lines, but not necessarily angles or lengths.

right-handed and left-handed coordinate systems

homogeneous coordinates

In homogeneous coordinates, each cartesian point (x,y,z) is represented in a redundant manner by 4 coordinates, (hx,hy,hz,h). Setting w=0 can be thought of as a point at infinity or, more simply, a direction.

Derivation of Transformations

Note: A positive rotation about the z-axis is defined as one that rotates from the positive x-axis to the postive y-axis. We can similarly define rotations about the other two axes. These definitions hold for both RHCS and LHCS.

translation
scaling
shear
rotation

3D Transformation Matrices

The transformations defined above can be rewritten using 4x4 matrices and homogeneous coordinates. The general form of the matrix is:

The expressions derived earlier correspond to the following transformation matrices.

Composition and Inversion of Transformations

A series of transformations can be accumulated into a single transformation matrix. Suppose our object is defined as follows:

Suppose we wish to place the object in our scene like this:

This can be accomplished in several ways, one of which is:

Substituting (1) in (2) gives:

Comments on Matrix Composition

Rotation about an arbitrary point

Find the transformation that rotates by an angle theta about a point P(x,y):

Let's choose to describe all transformations w.r.t. a fixed set of axes:

  • translate P to origin: trans(-2,-3,0)
  • perform rotation: rot(z,90)
  • translate P back: trans(2,3,0)

T = trans(2,3,0) rot(z,90) trans(-2,-3,0)

Rotation about an arbitrary axis

Overall Transform = trans(P0) rot(x,-alpha) rot(y,beta) rot(z,theta) rot(y,-beta) rot(x,alpha) trans(-P0)

Transformations as a change of basis (Change of Basis Matrix)

There is another way of looking at transformations which can let us construct transformations between two coordinate systems directly, without having to express the transformations in terms of one or more rotation and translation operations.

Suppose we have two coordinate systems, CS 1 and CS 2, having coincident origins, but having different orientations:

Let i,j,k and m,n,o be unit vectors as shown. These are called basis vectors. The transformation between the two coordinate systems can be obtained as follows.

The elements of the top-left 3x3 portion of any geometric transformation are really the basis vectors of the local coordinate system expressed in the coordinates of the new coordinate system.

Exercises

Exercise 1

How many floating-point multiplies, additions, and divides does it take to transform one vertex to device coordinates? Assume that the modelview and projection matrices could potentially have 16 non-zero elements.

Exercise 2

How many vertices need to be transformed in order to render a set of 10 triangles using a triangle strip such as obtained when using GL_TRIANGLE_STRIP ?

Exercise 3

Vectors only define a direction, not a position. A simple method of transforming vectors exists when the transformation involves only translations, rotations, and uniform scaling. This can be accomplished by transforming a vector much like we transform a point, except using a different value for the homogenous parameter, h. What value should be assigned to h for vectors?

Hint: Transformations are applied to points by augmenting the three-dimensional coordinate with a fourth homogeneous parameter, h=1. This allows for translations and rotations to be combined in a single 4x4 transformation matrix.

Exercise 4

We will now determine a method for transforming normals which works for all types of transformations. To do this, we will write the plane equation for a polygon and determine the transformed plane equation. Write the implicit equation for a plane. Rewrite this equation as a dot product between a vector containing the plane parameters, N, and a point in homogeneous coordinates, P, namely NTP = 0. If we apply a transformation M to any point on the plane, e.g., P' = M P, we need to apply an unknown transformation matrix Q to the vector N, e.g., N' = Q N. Solve for Q as a function of M.

Exercise 5

Consider the point P and the three coordinate frames O, A, and B below:

Notation: MRS is a 3x3 homogeneous matrix, and PR=(x,y,1) is a homogeneous point in coordinate frame S, such that

PS = MRS PR
  1. [2 marks] Find the coordinates of P in the three frames.
  2. [3 marks] Find MOA, MOB, MAB and MBA.
  3. [2 marks] Succintly express MAB in terms of MOA and MOB.
    Succintly express MAB in terms of MBA.

Exercise 7

Write down the 4x4 matrix for scaling an object by 35% in all directions.