Docsity

3-D Transformations: Scaling, Translation, and Rotation in 3-D and Euler Angles, Study notes of Computer Graphics

Toggle sidebar
bg1
3-D Transformations
Last time, we developed 2-D transformations
But we’re mainly interested in 3-D graphics
So today, we’ll extend these tools to 3-D
Scaling & Translation in 3-D
Looks pretty much the same as in 2-D
•just add on the z dimension to
everything
Unfortunately, rotation is not so simple …
Scaling
Translation
r
s
t
0 0 0
0 0 0
=
0 0 0
0 0 0 1
S
x
y
z
1 0 0 ∆
0 1 0 ∆
=
0 0 1 ∆
0 0 0 1
T
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download 3-D Transformations: Scaling, Translation, and Rotation in 3-D and Euler Angles and more Study notes Computer Graphics in PDF only on Docsity!

3-D Transformations

Last time, we developed 2-D transformations

But we’re mainly interested in 3-D graphics

So today, we’ll extend these tools to 3-D

Scaling & Translation in 3-D

Looks pretty much the same as in 2-D

  • (^) just add on the z dimension to

everything

Unfortunately, rotation is not so simple …

Scaling

Translation

r

s

t

S

x

y

z

^1 0 0 ∆ 

T

Euler Angles:

Rotation About Coordinate Axes

cos sin

sin cos

x

θ θ

θ θ

R

cos sin

sin cos

z

θ θ

θ θ

 −^0 0 

R

cos sin

sin cos

y

θ θ

θ θ

R

Drawbacks of Euler Angles

Drawback 1: Result is order dependent

  • (^) suppose we rotate about x then _y
  • y_ rotation is about transformed axis

after x rotation is performed

  • this gets confusing

Drawback 2: Difficult to interpolate

  • for animation want to interpolate angles
  • resulting motion can be weird

Can produce gimbal lock

cos sin

sin cos

x

θ θ

θ θ

R

cos sin

sin cos

z

θ θ

θ θ

 −^0 0 

R

cos sin

sin cos

y

θ θ

θ θ

R

Projection: Mapping 3-D to 2-D

Our scene models are in 3-D space and images are 2-D

  • so we need some way of projecting 3-D to 2-D

The fundamental approach: planar projection

  • first, we define a plane in 3-D space
    • this is the image plane (or film plane)
  • then project scene onto this plane
  • and map to the window viewport

Need to address two basic issues

  • how to define plane
  • how to define mapping onto plane

Orthographic Projection

Arguably the simplest projection

  • image plane is perpendicular to one of the coordinate axes
  • project onto plane by dropping that coordinate
  • ( x ,^ y ,^ z )^ $^ ( x ,^ y )^ or^ $^ ( x , z)^ or^ $^ ( y , z)

OpenGL — glOrtho(left, right, bottom, top, near, far)

  • assumes image plane perpendicular to z axis
    • (^) in other words, it’s the xy -plane
  • projects points ( x , y , z ) $ ( x , y )
  • also defines viewport mapping
    • (^) defines rectangle on xy -plane
    • this gets mapped to window

left

right

top

bottom

Perspective Projection

But we naturally see things in perspective

  • objects appear smaller the farther away they are
  • lenses bend (and hence focus) incoming light
  • in orthographic projection, all rays are parallel

We’ve been using pinhole camera models

  • draw rays thru focal point and points on object
  • some of these lines will intersect the image plane
  • this defines our projection into 2-D
  • all points along a ray project to same point
  • can project lines by projecting endpoints

d

The Canonical Camera Configuration

Want to derive perspective transformation

  • in particular, a matrix representation

First, we fix a canonical camera

  • focal point at origin
  • looking along z axis
  • image plane parallel to xy plane
  • located distance d from origin
    • called the focal length

x

y

z

d

focal

point

image

plane

Perspective Projection as a Transformation

This homogeneous matrix performs perspective projection

It’s operation on any given point is

d

P

x x

y y

z z

z

d d

Perspective Projection as a Transformation

This homogeneous matrix performs perspective projection

And when we do the homogeneous division

  • we get exactly the point we want
  • only keep x and y coordinates

d

P

^   

  ^ 

d

x

x z

y d

y

z z

z d

d

Completing the Projection

The image plane itself is infinite

  • must map a rectangular region of it to the viewport
  • defined by ( left, right, top, bottom ) coordinates

We also customarily define near & far clipping planes

  • these are expressed as distances from the viewpoint
  • they should always be positive
  • nothing nearer than near will be drawn
    • (^) don’t want to draw things behind the image plane
  • nothing further than far will be drawn
  • distance far-near should be small
    • (^) use fixed precision numbers to represent depth between them

OpenGL — glFrustum(left, right, bottom, top, near, far)

More Convenient Perspective Specification

Could always use glFrustum(left, right, bottom, top, near, far)

  • this is certainly sufficient
  • but it’s inconvenient

Generally want to use: gluPerspective(fovy, aspect, near, far)

  • viewport is always centered about z axis
  • specifies the field of view along the y axis
    • the angle! made by the sides of the frustum
  • and the aspect ratio of the viewport
    • this is just ( width / height)

y

z

!

We Need More General Cameras

So far, we’ve assumed a “canonical” camera configuration

  • focal point at the origin
  • image plane parallel to xy -plane

This is pretty limited, we want greater flexibility

  • deriving general projection matrices is painful
  • but we can transform world so camera is canonical
  • typically called the viewing transformation

Naturally, there are several ways of setting this up

  • we’ll focus on the OpenGL supported mechanism
  • the one in the book is gratuitously complex

Specifying General Camera Configurations

First, we want to allow focal point to be anywhere in space

  • call this position lookFrom , or just from

Next, we need to specify the orientation of the camera

  • define what it’s pointing at: lookAt - lookAt % lookFrom will define the axis of projection
  • define vertical axis of image: vUp
    • essentially a twist parameter about the lookAt axis

Converting Camera to Canonical Form

Our camera is parameterized by three vectors

- lookFrom , lookAt , and vUp

We want to transform into canonical camera position

  1. translate lookFrom to the origin — translate by – lookFrom
  2. rotate lookAt % lookFrom to the z axis
  3. rotate about z so that vUp lies inside the y-z plane

Axis:

Angle: where

θ sin ( / L ) L

− 1

= − ×

u z

u z

lookAt lookFrom

lookAt lookFrom

OpenGL Transformation Matrices

OpenGL maintains two different matrices

  • one to hold the camera projection matrix
  • and one to hold everything else
  • select “current matrix” with glMatrixMode( which ) - (^) which is GL_MODELVIEW or GL_PROJECTION

glFrustum() and friends multiply the current matrix

  • just like glTranslate(), glScale(), glRotate()

Vertices are transformed in the following manner

Model-view Projection Perspective division