Top Banner
1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I
17

1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

Jan 19, 2016

Download

Documents

Walter Lane
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

1

Graphics

CSCI 343, Fall 2015Lecture 16

Viewing I

Page 2: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

2

Viewing

Viewing refers to positioning the camera in a coordinate frame and projection of the 3D object onto the 2D image plane of the camera. Positioning the camera is very similar to positioning an object. Moving the camera relative to an object is the same as moving the object relative to the camera, in the opposite direction. In openGL the modeling and viewing transformations are combined into one transformation matrix.

First the object is positioned by multiplying the vertices by the object transformation matrices. Then the camera is positioned by multiplying by camera transformation matrices.

Page 3: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

3

Default Position of Camera

The default camera position is centered at the origin, pointing along the negative Z axis.

If we create an object (e.g. a cube) centered on the origin, part of it will be behind the camera.

To gain a view of the entire object, we need to move the camera by a distance, d, along the positive Z axis.

This is equivalent to moving the object by a distance, -d, along the negative Z axis.

Page 4: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

4

Moving the camera backward

x

y

z

x

y

z

x'

y'

z' d

translate(0.0, 0.0, -d)

Camera Frame

Object Frame

Page 5: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

5

Looking at the side of an Object

To move the camera to look at the side of an object that is centered on the origin:

1. Rotate the camera 90 deg.(Equivalent to rotating the object by -90 deg)

2. Translate the camera backward along +Z axis.(Equivalent to translating the object along -Z axis)

mvMatrix = translate(0.0, 0.0, -d);mvMatrix = mult(mvMatrix, rotate(-90.0, 0.0, 1.0, 0.0));

Page 6: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

6

Isometric view of a cube

The isometric view of a cube, is one in which the projection plane is placed symmetrically with respect to 3 faces of the cube.

We can gain an isometric view by rotating the camera (or cube centered on the origin), first about the Y axis and then about the X axis.

We then translate the camera backward to view it.

M = TRxRy

Page 7: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

7

Rotation matrix for Rotation about the Y axis

1. Rotate the cube 45 deg about the Y axis.

z

x

Top-down view after 45 deg rotation

2

Ry = ?

Page 8: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

8

Rotation Matrix for Rotation about Y axis

z

y2. Rotate about the X Axis:

Slice through Y-Z plane.(Through diagonal of cube)

1

Rx = ?

Page 9: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

9

Translate along -Z axis

3. Translate by -d along Z axis.

Final Matrix: M = TRxRy

Page 10: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

10

The UVN System

Other graphics systems may define the camera viewing plane differently. The U-V-N system is one example:

The camera plane is defined by 3 parameters: View Reference Point (VRP): A point (in the world frame) indicating the center of the camera's image plane. This specifies the position of the camera in space. View Plane Normal (VPN): A unit vector perpendicular to the camera's image plane. This specifies the orientation of the camera. View Up (VUP): A vector indicating the up direction (in world coordinates) for the camera.

Page 11: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

11

The UVN vector coordinates

nVUP

v

u

VUP does not have to lie in the image plane.

The projection of VUP onto the image plane is v. v is perpendicular to n. These define 2 of our three basis vectors for the camera coordinate system.

We define a third basis vector, u, such that u = v x n.

Together, u, v and n make up the camera coordinate system.

Page 12: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

12

The look-at function

The look-at function allows the camera to remain aimed at a given point even as its position in the world changes.

The camera is centered at the eye (VRP = e)

The camera is pointed at the "at" point (VPN = a - e)

The up vector (VUP) must be defined to specify the camera orientation.

e

a

VPN

In MV.js:function lookAt( eye, at, up )

Page 13: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

13

Yaw, Pitch and Roll

Camera in nose of plane.

y

x

y

Roll

z

y

Pitch

x

z

Yaw

In flight simulators, the angles of rotation are about the center of mass of the airplane.

The camera is in the nose of the plane.

x

z

Page 14: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

14

Parallel projections

In parallel projections, the lines projecting from an object onto the image plane are parallel.

Two parallel projection systems:Orthographic projection: Projection lines are perpendicular to the image plane.

Oblique projection: The view plane is tilted so the projection lines are not perpendicular to the plane.

x

z

x

zOrthographic Oblique

Page 15: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

15

Matrix for Orthographic Projection

xp = xyp = yzp = 0 M = ?

p'= Mp = ?

Page 16: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

16

Perspective Projection

y

-z

(Y, -Z)

-d

(yp, -d)

(X, -Z)

-d

(xp, -d)

-z

x

Page 17: 1 Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I.

17

Matrix for Perspective Projection

Representation of a point, P, in homogeneous coordinates:

Perspective projection Matrix: