1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Transformations (p2) (đồ họa máy TÍNH SLIDE)

60 14 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 60
Dung lượng 4,69 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Camera Analogy and Transformations• Viewing transformations – tripod–define position and orientation of the viewing volume in the world... Coordinate Systems and Transformations• Steps

Trang 1

Transformations

Trang 4

Camera Analogy and Transformations

• Viewing transformations

– tripod–define position and

orientation of the viewing

volume in the world

Trang 5

Coordinate Systems and Transformations

• Steps in Forming an Image

– Specify geometry (world coordinates)

– Specify camera (camera coordinates)

– Project (window coordinates)

– Map to viewport (screen coordinates)

• Each step uses transformations

• Every transformation is equivalent to a change in

coordinate systems (frames)

5

Trang 6

Affine Transformations

• Want transformations which preserve geometry

– lines, polygons, quadrics

• Affine = line preserving

– Rotation, translation, scaling

– Projection

– Concatenation (composition)

Trang 7

Homogeneous Coordinates

• Each vertex is a column vector

• If a is nonzero, then (x, y, z, w) T and (ax, ay, az, aw) T

represent the same homogeneous vertex

• A 3D Euclidean space point (x, y, z) T becomes the

homogeneous vertex (x, y, z, 1.0) T

• As w is nonzero, the homogeneous vertex (x, y, z,

w) T corresponds to the 3D point (x/w, y/w, z/w) T

• Directions (directed line segments) can be

represented with w = 0.0

•  

7

Trang 8

Vertex transformations

• Vertex transformations (rotations, translations,

scaling, and shearing) and projections (such as

perspective and orthographic) can all be

represented by applying an appropriate 4 x 4 matrix

to the vertex coordinates.

• all affine operations are matrix multiplications

• all matrices are stored column-major in OpenGL

• matrices are always post-multiplied

• product of matrix and vector is

=

•  

Trang 9

• Specify operation (glRotate, glOrtho)

– Programmer does not have to remember the exact

matrices

9

Trang 10

Programming Transformations

• Prior to rendering, view, locate, and orient:

– Eye / camera position

– 3D geometry

• Manage the matrices

– Including matrix stack

• Combine (composite) transformations

Trang 11

Transformation Pipeline

• other calculations here

– material  color – shade model (flat) – polygon rendering mode – polygon culling

Modelview

Modelview

Projection

l l l

object eye clip normalized device window

Trang 12

– usually same as window size

– viewport aspect ratio should be same as projection

transformation or resulting image may be distorted

– glViewport(x, y, width, height)

Trang 13

Viewing Transformations

Trang 14

Viewing Transformations

• Position the camera/eye in the scene

– place the tripod down; aim camera

• To "fly through" a scene

– change viewing transformation and

redraw scene

• gluLookAt(eyex, eyey, eyez,

aimx, aimy, aimz,

upx, upy, upz)

– up vector determines unique orientation

– careful of degenerate positions

tripod

Trang 15

Using gluLookAt()

• In the default position, the camera is at the origin, is

looking down the negative z-axis, and has the positive y-axis as straight up This is the same as calling

• gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0,

-100.0, 0.0, 1.0, 0.0);

Trang 16

Default View

• In the default position,

– the camera is at the

Trang 17

Using gluLookAt()

• gluLookAt(4.0, 2.0, 1.0, 2.0, 4.0,

-3.0, 2.0, 2.0, -1.0);

Trang 18

Projection Tutorial

Trang 19

Modeling Transformations

Trang 21

Translation Transformation

• The call glTranslate*(x, y, z) generates T, where

T =

•  

Trang 22

• glScale*(x, y, z) generates S =

•  

Scale Transformation

Trang 23

Rotation Transformation

• The glRotate*() command generates a matrix for

rotation about an arbitrary axis

• Rotating about the Oz

axis glRotate*(a, 0, 0, 1)

•  

Trang 25

General rotations

• The call glRotate*(a, x, y, z) generates R as follows:

– Let v = (x, y, z)T, and u = v/||v|| = (x’, y’, z’) T.

– Also let S =

– and M = uu T + (cos a) (I − uu T ) + (sin a) S

– Then R =

•  

Trang 26

Bài tập

• Xác định ma trận của phép quay glRotatef(30.0f,

1.0f, 1.0f, 0.0f)

Trang 27

Order of transformations

• In general not commutative: order matters!

Rotate then translate

Trang 28

Transformation Tutorial

Trang 29

Compositing Modeling Transformations

• Problem 1: hierarchical objects

– one position depends upon a previous position

– robot arm or hand; sub-assemblies

• Solution 1: moving local coordinate system

– modeling transformations move coordinate system

– post-multiply column-major matrices

– OpenGL post-multiplies matrices

29

Trang 30

Compositing Modeling Transformations

• Problem 2: objects move relative to absolute world

origin

– my object rotates around the wrong origin

• make it spin around its center or something else

• Solution 2: fixed coordinate system

– modeling transformations move objects around fixed

coordinate system

– pre-multiply column-major matrices

– OpenGL post-multiplies matrices

– must reverse order of operations to achieve desired effect

Trang 32

Connection: Viewing and Modeling

Trang 33

Connection: Viewing and Modeling

• Moving camera is equivalent to moving every object in

the world towards a stationary camera

• Viewing transformations are equivalent to several

Trang 34

OpenGL Viewing Code

• In OpenGL, we can use the built-in transformation calls to specify the viewing transformation

• The camera is positioned in the scene with

translation by [vTx, vTy, vTz] and rotation about the

X, Y, and Z axis:

void setupView(void) { // Inverse viewing transformation glRotatef( -vAngleZ, 0.0, 0.0, 1.0 );

glRotatef( -vAngleY, 0.0, 1.0, 0.0 );

glRotatef( -vAngleX, 1.0, 0.0, 0.0 );

glTranslatef( -vTx, -vTy, -vTz );

void setupView(void) { // Inverse viewing transformation glRotatef( -vAngleZ, 0.0, 0.0, 1.0 );

glRotatef( -vAngleY, 0.0, 1.0, 0.0 );

glRotatef( -vAngleX, 1.0, 0.0, 0.0 );

glTranslatef( -vTx, -vTy, -vTz );

Trang 35

Constructing a Frame

• The cross product between the up and the look-at

vector will get a vector that points to the right.

r = up x a

• Finally, using the vector a and the vector r we can synthesize a new vector u in the up direction:

Trang 36

• Rotation takes the unit world to our desired camera:

Trang 37

• Translation to the eye point:

Trang 38

Composing the Result

• The final camera transformation is:

Trang 39

The Viewing Transformation

• Transforming all points P in the world with E -1 :

• Where these are normalized vectors

a = P eye – P aim

r = up x a

u = a x r

Trang 40

Projection Transformation

Trang 41

Projection Transformation

• To lower dimensional space (here 3D -> 2D)

– Preserve straight lines

• Shape of viewing frustum

• Perspective projection

• Orthographic parallel projection

41

Trang 42

Demo

Trang 43

Orthographic projection

• The viewing volume is a rectangular parallelepiped.

• Vertexes of an object are "projected" towards infinity

• Distance from the camera doesn’t affect how large an

Trang 44

Orthographic projection

• Specify the orthographic viewing frustum by

– specifying minimum and maximum x, y coordinates

– Indicating range of distances along the z-axis by specifying near and far planes

Trang 45

Orthographic Projections matrix

• Here is the orthographic world-to-clip

transformation:

Trang 46

Orthographic Projection in OpenGL

• This matrix is constructed with the following OpenGL call:

glOrtho(left, right, bottom, top, zNear,zFar)

• And the 2D version (another GL utility function):

gluOrtho2D(left, right, bottom, top)

– Just a call to glOrtho() with near = -1 and far = +1

• Usually, the following code is part of the initialization

Trang 47

Perspective Projections

• Artists (Donatello, Brunelleschi, and Da Vinci) during

the renaissance discovered the importance of

perspective for making images appear realistic

• Parallel lines intersect at a point

Trang 48

Perspective projection

• Characteristic of perspective projection is

foreshortening:

– The farther an object is from the camera, the smaller it

appears in the final image

Trang 49

Perspective projection

• glFrustum(left, right, bottom, top,

zNear, zFar)

49

Trang 50

Perspective projection

– fov = vertical field of view in degrees

– aspect = image width / height at near depth

– Can only specify symmetric viewing frustums where the viewing window is centered around the –z axis.

Trang 51

OpenGL Perspective Matrix

• Mapping the perspective viewing frustum in OpenGL

to clip space involves some affine transformations

• OpenGL uses a clever composition of these

transformations with the perspective projection

matrix:

Trang 52

Viewport Transformation

Trang 53

Viewport Transformation

• The viewport is the rectangular region of the

window where the image is drawn

• Defining the Viewport

– glViewport(GLint x, GLint y, GLsizei

width, GLsizei height)

Trang 54

Mapping the Viewing Volume to the Viewport

• The aspect ratio of a viewport should equal the aspect

ratio of the viewing volume

– If the two ratios are different, the projected image will be distorted when mapped to the viewport

Trang 55

Common Transformation Usage

• 3 examples of resize() routine

– restate projection & viewing transformations

• Usually called when window resized

55

Trang 56

resize(): Perspective & LookAt

void resize( int w, int h )

Trang 57

resize(): Perspective & Translate

• Same effect as previous LookAt

Trang 58

GLdouble bottom = -2.5, top = 2.5;

glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION);

Trang 59

Additional Clipping Planes

• At least 6 more clipping planes available

• Good for cross-sections

• Modelview matrix moves clipping plane

Trang 60

Reversing Coordinate Projection

• Screen space back to world space

glGetIntegerv(GL_VIEWPORT, GLint viewport[4]) glGetDoublev(GL_MODELVIEW_MATRIX,

GLdouble *objx, *objy, *objz)

• gluProject goes from world to screen space

Ngày đăng: 29/03/2021, 08:19

TỪ KHÓA LIÊN QUAN

w