Transformations and Projections (Some slides adapted from Amitabh Varshney)

38
Transformations and Projections (Some slides adapted from Amitabh Varshney)
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    215
  • download

    0

Transcript of Transformations and Projections (Some slides adapted from Amitabh Varshney)

Page 1: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Transformations and Projections

(Some slides adapted from Amitabh Varshney)

Page 2: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Transformation of lines/normals

• 2D. Line is set of points (x,y) for which (a,b,c).(x,y,1)T=0. Suppose we rotate points by R. Notice that:

(a,b,c)RT R(x,y,1)T

So, (a,b,c)RT is the rotation of the line (a,b,c).

Surface normals are similar, except they are defined by (a,b,c).(x,y,z)T = 0

Page 3: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Rotation about a known axis

• Suppose we want to rotate about u. • Find R so that u will be the new z axis.

– u is third row of R.– Second row is anything orthogonal to u.– Third row is cross-product of first two.– Make sure matrix has determinant 1.

• Then rotate about (new) z axis.• Then apply inverse of first rotation.

Page 4: Transformations and Projections (Some slides adapted from Amitabh Varshney)

OpenGL Transformation Support• Three matrices

– GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE– glMatrixMode( mode ) specifies the active matrix

• glLoadIdentity( ) – Set the active matrix to identity

• glLoadMatrix{fd}(TYPE *m) – Set the 16 values of the current matrix to those specified by m

• glMultMatrix{fd}(TYPE *m) – Multiplies the current active matrix by m

m1 m5 m9 m13

m2 m6 m10 m14

m3 m7 m11 m15

m4 m8 m12 m16

m =

Page 5: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Transformation Example

glMatrixMode(GL_MODELVIEW);

glLoadIdentity( ); // matrix = I

glMultMatrix(N); // matrix = N

glMultmatrix(M); // matrix = NM

glMultMatrix(L); // matrix = NML

glBegin(GL_POINTS);

glVertex3f(v); // v will be transformed: NMLv

glEnd( );

Page 6: Transformations and Projections (Some slides adapted from Amitabh Varshney)

OpenGL Transformations

• glTranslate{fd}(TYPE x, TYPE y, TYPE z)

– Multiply the current matrix by the translation matrix

• glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z)– Multiply the current matrix by the rotation matrix that

rotates an object about the axis from (0,0,0) to (x, y, z)

• glScale{fd}(TYPE x, TYPE y, TYPE z)– Multiply the current matrix by the scale matrix

Page 7: Transformations and Projections (Some slides adapted from Amitabh Varshney)

ExamplesglMatrixMode(GL_MODELVIEW);

glRecti(50,100,200,150);

glTranslatef(-200.0, -50.0, 0.0);

glRecti(50,100,200,150);

glLoadIdentity();

glRotatef(90.0, 0.0, 0.0, 1.0);

glRecti(50,100,200,150);

glLoadIdentity();

glscalef(-.5, 1.0, 1.0)

glRecti(50,100,200,150);

Page 8: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Hierarchical Transformations in OpenGL

• Stacks for Modelview and Projection matrices• glPushMatrix( )

– push-down all the matrices in the active stack one level– the top-most matrix is copied (the top and the second-from-

top matrices are initially the same).

• glPopMatrix( )– pop-off and discard the top matrix in the active stack

• Stacks used during recursive traversal of the hierarchy. • Typical depths of matrix stacks:

– Modelview stack = 32 (aggregating several transformations)– Projection Stack = 2 (eg: 3D graphics and 2D help-menu)

Page 9: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Viewing in 3D

• World (3D) Screen (2D)

• Orienting Eye coordinate system in World coordinate system– View Orientation Matrix

• Specifying viewing volume and projection parameters for n d (d < n) – View Mapping Matrix

Page 10: Transformations and Projections (Some slides adapted from Amitabh Varshney)

World to Eye Coordinates

(Images Removed)

Page 11: Transformations and Projections (Some slides adapted from Amitabh Varshney)

World to Eye Coordinates

• We need to transform from the world coordinates to the eye coordinates

• The eye coordinate system is specified by:– View reference point (VRP)

• (VRPx, VRPy, VRPz)

– Direction of the axes: eye coordinate system• U = (ux, uy, uz)

• V = (vx, vy, vz)

• N = (nx, ny, nz)

Page 12: Transformations and Projections (Some slides adapted from Amitabh Varshney)

World to Eye Coordinates

• There are two steps in the transformation (in order)– Translation – Rotation

Page 13: Transformations and Projections (Some slides adapted from Amitabh Varshney)

World to Eye Coordinates

• Translate World Origin to VRP

1 0 0 -VRPx

0 1 0 -VRPy

0 0 1 -VRPz

0 0 0 1

x

y

z

1

a

b

c

1

=

Page 14: Transformations and Projections (Some slides adapted from Amitabh Varshney)

World to Eye Coordinates

• Rotate World X, Y, Z to the Eye coordinate system u, v, n, also known as the View Reference Coordinate system

a

b

c

1

x’

y’

z’

1

=

ux uy uz 0

vx vy vz 0

nx ny nz 0

0 0 0 1

Page 15: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Camera Analogy

(Images Removed)

Page 16: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Specifying 3D View(Camera Analogy)

• Center of camera (x, y, z) : 3 parameters• Direction of pointing (,) : 2 parameters• Camera tilt () : 1 parameter• Area of film (w, h) : 2 parameters• Focus (f) : 1 parameter

Page 17: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Specifying 3D View

• Center of camera (x, y, z) : View Reference Point (VRP)

• Direction of pointing (,) : View Plane Normal (VPN)• Camera tilt () : View Up (VUP)• Area of film (w, h) : Aspect Ratio (w/h),

Field of view (fov)• Focus (f) : Will consider later

Page 18: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Eye Coordinate System

• View Reference Point (VRP)• View Plane Normal (VPN)• View Up (VUP)

VRP

(origin)

VUP

(Y-axis)

VPN

(Z-axis)

Viewing Plane

VUP VPN

(X-axis)

Page 19: Transformations and Projections (Some slides adapted from Amitabh Varshney)

World to Eye Coordinates

• Translate World Origin to VRP • Rotate World X, Y, Z to the Eye coordinate system, also

known as the View Reference Coordinate system, VRC = (VUP VPN, VUP, VPN), respectively:

( VUP VPN ) 0

( VUP ) 0

( VPN ) 0

0 0 0 1

Page 20: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Eye Coordinate System(OpenGL/GLU library)

• gluLookAt (eyex , eyey , eyez , lookatx , lookaty , lookatz , upx , upy , upz );

• In our terminology:

eye = VRP

lookat = VRP + VPN

up = VUP

• gluLookAt also works even if:

– lookat is any point along the VPN– VUP is not perpendicular to VPN

Page 21: Transformations and Projections (Some slides adapted from Amitabh Varshney)

gluLookAt()

Image from: Interactive Computer Graphics by Ed Angel

(Images Removed)

Page 22: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Eye Coordinate System(OpenGL/GLU library)

• This how the gluLookAt parameters are used to generate the eye coordinate system parameters:

VRP = eye

VPN = (lookat - eye) / lookat - eye)

VUP = VPN (up VPN)

• The eye coordinate system parameters are then used in translation T(VRP) and rotation R(XYZ VRC) to get the view-orientation matrix

Page 23: Transformations and Projections (Some slides adapted from Amitabh Varshney)

http://www.acmi.net.au/AIC/CAMERA_OBSCURA.html (Russell Naughton)

Camera Obscura

"When images of illuminated objects ... penetrate through a small hole into a very dark room ... you will see [on the opposite wall] these objects in their proper form and color, reduced in size ... in a reversed position, owing to the intersection of the rays".

Da Vinci

Page 24: Transformations and Projections (Some slides adapted from Amitabh Varshney)

• Used to observe eclipses (eg., Bacon, 1214-1294)

• By artists (eg., Vermeer).

Page 25: Transformations and Projections (Some slides adapted from Amitabh Varshney)

http://brightbytes.com/cosite/collection2.html (Jack and Beverly Wilgus)

Jetty at Margate England, 1898.

Page 26: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Pinhole cameras

• Abstract camera model - box with a small hole in it

• Pinhole cameras work in practice

(Forsyth & Ponce)

Page 27: Transformations and Projections (Some slides adapted from Amitabh Varshney)

The equation of projection

(Forsyth & Ponce)

Page 28: Transformations and Projections (Some slides adapted from Amitabh Varshney)

The equation of projection

• Cartesian coordinates:– We have, by similar

triangles, that (x, y, z) -> (f x/z, f y/z, f)

– Ignore the third coordinate, and get

(x,y, z) ( fxz

, fyz)

Page 29: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Perspective Projection

• Homogenize (divide by w’’= z / f) to get:– x’ = x / (z / f) = x’’/ w’’– y’ = y / (z / f) = y’’/ w’’– z’ = z / (z / f) = z’’/ w’’ = f

1 0 0 0

0 1 0 0

0 0 1 0

0 0 1/f 0

x

y

z

1

x’’

y’’

z’’

w’’

=

Page 30: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Distant objects are smaller

(Forsyth & Ponce)

Page 31: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Parallel lines meet

Common to draw image plane in front of the focal point. Moving the image plane merely scales the image.

(Forsyth & Ponce)

Page 32: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Vanishing points

• Each set of parallel lines meets at a different point– The vanishing point for this direction

• Sets of parallel lines on the same plane lead to collinear vanishing points. – The line is called the horizon for that plane

Page 33: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Properties of Projection

• Points project to points• Lines project to lines• Planes project to the whole image• Angles are not preserved• Degenerate cases

– Line through focal point projects to a point.– Plane through focal point projects to line– Plane perpendicular to image plane

projects to part of the image (with horizon).

Page 34: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Weak perspective (scaled orthographic projection)

• Issue– perspective effects,

but not over the scale of individual objects

– collect points into a group at about the same depth, then divide each point by the depth of its group

(Forsyth & Ponce)

Page 35: Transformations and Projections (Some slides adapted from Amitabh Varshney)

The Equation of Weak Perspective

),(),,( yxszyx • s is constant for all points.

• Parallel lines no longer converge, they remain parallel.

Page 36: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Parallel Projection

Project on the plane, z = 0

1 0 0 0

0 1 0 0

0 0 0 0

0 0 0 1

x

y

z

1

x’

y’

z’

1

=

Page 37: Transformations and Projections (Some slides adapted from Amitabh Varshney)

Cameras with Lenses

(Forsyth & Ponce)

Page 38: Transformations and Projections (Some slides adapted from Amitabh Varshney)

OpenGL for Projection

• Projection specifies clipping windows.

• glMatrixMode(GL_PROJECTION)• glOrtho(xmin,xmax,ymin,ymax,dnear,dfar)• gluPerspective(theta,aspect,dnear,dfar)