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

Post on 19-Jan-2016

223 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

1

Graphics

CSCI 343, Fall 2015Lecture 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.

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.

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

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));

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

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 = ?

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 = ?

9

Translate along -Z axis

3. Translate by -d along Z axis.

Final Matrix: M = TRxRy

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.

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.

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 )

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

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

15

Matrix for Orthographic Projection

xp = xyp = yzp = 0 M = ?

p'= Mp = ?

16

Perspective Projection

y

-z

(Y, -Z)

-d

(yp, -d)

(X, -Z)

-d

(xp, -d)

-z

x

17

Matrix for Perspective Projection

Representation of a point, P, in homogeneous coordinates:

Perspective projection Matrix:

top related