reminder
DESCRIPTION
Reminder. Any sequence of matrix operations can be composed into a single matrix We’ll always use an extra dimension for all vertices (x,y,w). Extending to 3D. Homogeneous coordinates in 3D [x,y,z,1] T (x,y,z,w) Matrices of this form: 4x4 Matrices instead of 3x3 for 3D. Translation. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/1.jpg)
1
Reminder
Any sequence of matrix operations can be composed into a single matrix
We’ll always use an extra dimension for all vertices (x,y,w)
![Page 2: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/2.jpg)
2
Extending to 3D
Homogeneous coordinates in 3D [x,y,z,1]T (x,y,z,w) Matrices of this form:
4x4 Matrices instead of 3x3 for 3D
111000
lkzjyix
hgzfyex
dczbyax
z
y
x
lkji
hgfe
dcba
![Page 3: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/3.jpg)
3
Translation
1000
100
010
001
),,(l
h
d
lhdT
111000
100
010
001
lz
hy
dx
z
y
x
l
h
d
![Page 4: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/4.jpg)
4
OpenGL
glTranslated(x, y, z)
1000
100
010
001
z
y
x
MM
Post-multiplies translation matrix onto currently selected matrix…
![Page 5: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/5.jpg)
5
Example…
glTranslated(tox, toy, toz);
DrawBox();
![Page 6: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/6.jpg)
6
Scaling
1000
000
000
000
),,(k
f
a
kfaS
111000
000
000
000
kz
fy
ax
z
y
x
k
f
a
How do I do auniform scale?
glScaled(x, y, z)
![Page 7: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/7.jpg)
7
What about Rotation?
How can we convert this to 3D?
1
cossin
sincos
1100
0cossin
0sincos
yx
yx
y
x
![Page 8: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/8.jpg)
8
Rotation about Z axis
1
cossin
sincos
11000
0100
00cossin
00sincos
z
yx
yx
z
y
x
Just keep z constant.
![Page 9: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/9.jpg)
9
The 3 Rotation Matrices
1000
0100
00cossin
00sincos
)(
zR
1000
0cossin0
0sincos0
0001
)(
xR
1000
0cos0sin
0010
0sin0cos
)(
yR
![Page 10: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/10.jpg)
10
OpenGL general glRotated
glRotated(angle, x, y, z) Rotates by angle (in degrees) around
the vector (x, y, z)
![Page 11: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/11.jpg)
11
Skew or Shear
1000
0100
0010
001
)(
b
bH x
![Page 12: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/12.jpg)
12
Example: Rotating around a point
Suppose we have an object centered on (12, 17, 32)
We want to “spin” the object around that center point
What will be the operations?
![Page 13: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/13.jpg)
13
Homogenous Coordinates and Vectors
It is convention that Points in space are indicated with w=1 Vectors are indicated with w=0 [12, 13, 5, 1]T is a point [45, 13, 2, 0]T is a vector (point –
point?)
We often want unit-length vectors
![Page 14: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/14.jpg)
OpenGL Transformation Composition
A global modeling transformation matrix (GL_MODELVIEW, called it M here) glMatrixMode(GL_MODELVIEW) The user is responsible to reset it if
necessary glLoadIdentity() -> M = 1 0 0 0 1 0 0 0 1
![Page 15: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/15.jpg)
OpenGL Transformation Composition
Matrices for performing user-specified transformations are multiplied to the current matrix
For example, 1 0 1
glTranslated(1,1 0); M = M x 0 1 1
0 0 1 All the vertices defined within glBegin() /
glEnd() will first go through the transformation (modeling transformation)
P’ = M x P
![Page 16: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/16.jpg)
Transformation Pipeline
Object Local Coordinates
Object World Coordinates
Modeling transformation
…
![Page 17: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/17.jpg)
17
Frames
Frame – A center and three coordinate axes A coordinate system
World Frame andCamera Frame
![Page 18: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/18.jpg)
18
World to Camera
What does gluLookAt do mathematically?
void gluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz );
![Page 19: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/19.jpg)
19
Defining a Frame(relative to another frame)
Need: Origin Vectors for X, Y, and Z axis of frame
![Page 20: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/20.jpg)
20
Adding Orthogonal Constraint
We can get by with: Origin One axis direction and which way is
up
Z direction is negative oflook direction.
X is at right angles to Z and Up
![Page 21: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/21.jpg)
21
Z = (eye – center) / | eye – center |
X = (up Z) / | up Z |
Y = Z X
Computing the Axis
z
x
y
Right-hand rule?
![Page 22: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/22.jpg)
22
Making a frame the reference coordinate system
Move the center to the origin Rotate the frame axis onto (1,0,0),
(0,1,0), (0,0,1)
![Page 23: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/23.jpg)
23
Moving the center to the origin
glTranslated(-eyex, -eyey, -eyez);
![Page 24: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/24.jpg)
24
Rotating arbitrary axes v1,v2,v3 onto (1,0,0), (0,1,0), (0,0,1)
Notice: v1,v2,v3 must be orthogonal to each other
![Page 25: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/25.jpg)
25
Suppose we have three ortho-normal vectors…
v1,v2,v3
Let’s build a matrix like this:
This will rotate: v1 onto the x axis, v2 onto the y axis, v3 onto the z axis
1000
0
0
0
),,(,3,3,3
,2,2,2
,1,1,1
321zyx
zyx
zyx
vvv
vvv
vvv
vvvR
![Page 26: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/26.jpg)
26
Introduction to 3D viewing
3D is just like taking a photograph!
![Page 27: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/27.jpg)
27
Viewing Transformation
Position and orient your camera
![Page 28: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/28.jpg)
28
Projection Transformation
Control the “lens” of the camera Project the object from 3D world to 2D screen
![Page 29: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/29.jpg)
29
Viewing Transformation (2)
Important camera parameters to specify Camera (eye) position (Ex,Ey,Ez) in world
coordinate system Center of interest (coi) (cx, cy, cz) Orientation (which way is up?) View-up vector
(Up_x, Up_y, Up_z)
world(cx, cy, cz)
(ex, ey, ez)view up vector(Up_x, Up_y, Up_z)
![Page 30: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/30.jpg)
30
Viewing Transformation (3)
Transformation? Form a camera (eye) coordinate frame
Transform objects from world to eye space
world
uvn
x
y
z
Eye coordinate frame coi
![Page 31: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/31.jpg)
31
world
uvn
x
y
z
(0,0,0) coi
Viewing Transformation (4)
Eye space?
Transform to eye space can simplify many downstream operations (such as projection) in the pipeline
(1,0,0)(0,1,0)(0,0,1)
![Page 32: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/32.jpg)
32
Viewing Transformation (5)
In OpenGL: - gluLookAt (Ex, Ey, Ez, cx, cy, cz,
Up_x, Up_y, Up_z) - The view up vector is usually (0,1,0) - Remember to set the OpenGL matrix
mode to GL_MODELVIEW first
![Page 33: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/33.jpg)
33
Viewing Transformation (6)
void display() { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,1,0,0,0,0,1,0); display_all(); // your display routine}
![Page 34: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/34.jpg)
34
Suppose we have three orthogonal vectors…
v1,v2,v3
Let’s build a matrix like this:
This will rotate: v1 onto the x axis, v2 onto the y axis, v3 onto the z axis
1000
0
0
0
),,(,3,3,3
,2,2,2
,1,1,1
321zyx
zyx
zyx
vvv
vvv
vvv
vvvR
![Page 35: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/35.jpg)
35
My Version of gluLookAt()
void mygluLookAt(Point3 eye, Point3 center, Point3 up){ Point3 cameraZ = Normalize( eye – center ); // v3 Point3 cameraX = Normalize( Cross(up, cameraZ) ); // v1 Point3 cameraY = Cross( cameraZ, cameraX ); // v2 GLdouble m[16]; // Fill the matrix in row by row m[0] = cameraX.X; m[4] = cameraX.Y; m[8] = cameraX.Z; m[12] = 0.0; m[1] = cameraY.X; m[5] = cameraY.Y; m[9] = cameraY.Z; m[13] = 0.0; m[2] = cameraZ.X; m[6] = cameraZ.Y; m[10] = cameraZ.Z; m[14] = 0.0; m[3] = m[7] = m[11] = 0.0; m[15] = 1.0; glMultMatrixd( m ); glTranslated( -eye.X, -eye.Y, -eye.Z );}
Order of transformations!
![Page 36: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/36.jpg)
36
Messing with the camera
What if I want to PAN the camera? We need to define “PAN”
There are two possibilities
Crab Pan
![Page 37: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/37.jpg)
37
Panning
Suppose we pan around the camera Y axis This is NOT “up” in world space. We need to change the lookAt point.
![Page 38: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/38.jpg)
38
Operations on Points in Space
LookAt is a point in space Need these transformation:
Translate by –eye Rotate frame onto axis (using some M) Rotate around Y by pan angle Inverse rotate M Translate by eye
PP=T(eye) MT RY() M T(-eye)
![Page 39: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/39.jpg)
39
Easier #1
Just replace the matrix using gluLookAt. Problems?
![Page 40: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/40.jpg)
40
Easier #2
The first 2 operations are already what is done to set the camera up: M T(-eye)
We just need to add a rotate after this is done. Implies we want to pre-multiply by a
rotation matrix.
![Page 41: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/41.jpg)
41
Easier #2
Steps:1. Read out the current matrix.2. Set the matrix to the identity matrix.3. Rotate about the y-axis the amount
we want to pan.4. Post-multiply by the matrix read out
in step #1.
![Page 42: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/42.jpg)
42
Camera Controls
Tilt Roll Dolly Boom Zoom (same as dolly?) General camera (or entity)
movement and the user interface / control.
Eliot Lash, 2007 (from Wikipedia.org – Camera dolly)
![Page 43: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/43.jpg)
43
Camera Controls Stationary 2 degrees of
freedom + zoom QuicktimeVR
![Page 44: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/44.jpg)
44
Examiner Mimic holding an
object in your hand.
OpenInventor’s Examiner Viewer
Used in IRIS Explorer
Used in modeling and scientific visualization.
Image courtesy of NAG
![Page 45: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/45.jpg)
45
Flying Camera specified
using Euler angles and position.
Many possible control strategies Acceleration /
Deceleration
![Page 46: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/46.jpg)
46
Camera models in games Many different approaches Flying model, with a camera pan, tilt
according to the mouse position. Orthographic view with simple
translations (occasionally a examiner) Cinematic camera with view-oriented
dolly (look with mouse, move in camera look-at direction with keyboard).
![Page 47: Reminder](https://reader036.vdocuments.us/reader036/viewer/2022062519/568153e0550346895dc1dd2a/html5/thumbnails/47.jpg)
47
Software Engineering Define a well-encapsulated Camera
class or base class. Separate the control of the camera from
the camera object. Separate the mouse / keyboard
handling from the control as much as possible.
I will share my Camera classes next week.