1. Trang chủ
  2. » Công Nghệ Thông Tin

Giáo trình thực tại ảo BKHN lesion 5:Các phép biến đổi Đồ hoạ Transformations

94 304 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 94
Dung lượng 1,81 MB

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

Nội dung

Phép biến đổi - Transformations  Trong kỹ thuật đồ hoạ 3 bước: Mô hình, Tô trát và Hiên thị modeling, rendering, displaying  Với Modeling Mô hình hóa :  Transformation: là phép án

Trang 1

1

Transformations

Le Tan Hung Email: hunglt@it-hut.edu.vn

Trang 2

Phép biến đổi - Transformations

 Trong kỹ thuật đồ hoạ 3 bước: Mô hình, Tô trát

và Hiên thị (modeling, rendering, displaying)

 Với Modeling ( Mô hình hóa) :

 Transformation: là phép ánh xạ tọa độ điểm hay vector thành tọa độ hay vector khác

modeling

coordinate Modeling

transformation

Viewing transformation

world coordinate

viewing coordinate ( eye

coordinate)

Trang 3

3

Phép biến đổi Transformations

 Biến đổi mô hình hoá - Modeling transformations

– build complex models by positioning simple components

 Biến đổi tạo góc nhìn - Viewing transformations

– placing virtual camera in the world

– transformation from world coordinates to camera

coordinates

 Biến Phép chiếu – Projection Transform

Trang 4

Transformations - Modeling

world

Trang 5

5

Phép biến đổi Affine

Affine Transformations?

 Ph ép biến đổi Affine l à phép biến đổi tọa độ

điểm đặc trưng của đối tượng thành tập tương

ứng các điểm mới để tạo ra các hiệu ứng cho

toàn đối tượng

– Ví dụ: phép biến đổi tọa độ với chỉ 2 điểm đầu cuối của đoạn thẳng tạo thành 2 điểm mới mà khi nối chúng với nhau tạo thành đoạn thẳng mới

 Các điểm nằm trên đoạn thẳng sẽ có kết quả là điểm nằm trên đoạn thẳng mới với cùng phép biến đổi thông qua phép nội suy

Trang 6

Modeling Transformations

Transform objects/points

Transform coordinate system

Trang 7

7

Biểu diễn Ma trận

 Việc biến đối các đối tượng làm thay đổi các

điểm P thành các điểm Q theo thuật toán

Việc biến đổi P sử dụng tọa độ của P (Px,Py) ánh

Trang 8

x y

x

t

t P

P d

c

b a

Q Q

x x

x

x aP bP t

y y

y

y cP dP t

Trang 9

9

Các phép biến đổi hình học hai

chiều

 Phương pháp biểu diễn đối tượng P = [ x y ]

 Phép biến đổi vị trí điểm

 Thực thi phép biến đổi đúng trên 1 điểm ảnh sẽ đúng

trên toàn bộ đối tượng

b

a T

             ' '

y dy

bx

* y

d c

b

a x

p M

p W

Trang 10

Phép biến đổi

 Phép bất biến

 Phép biến đổi tỉ lệ - Scaling

 A scaling changes the size of an object with two scale

Trang 11

11

Phép quay- Rotation

x = cos  , y =  sin  ;

x’ = cos ( + ), y’ =  sin ( + ) ;

x’ = ( cos cos - sin sin )

sin

cos]

[T

Trang 12

Thuộc tính cơ bản của phép biến

đổi Affine Transformations

– We need only compute the image of the two endpoints

of the original line and then draw a straight line between them

Trang 13

 Preservation of proportional distances

– Preservation of proportional distances means that points of lines remain mid-points

mid- Affine transformations change volume by | Det(M) |;

Trang 14

Kết hợp các phép biến đổi

Composition of Affine Transforms

 Any affine transformation can be

decomposed into elementary

Trang 15

 Usually an application requires that we build a

complex transformation out of several elementary ones

– e.g translate an object, rotate it, and scale it, all in one move

 These individual transformations combine into one

overall transformation

 This is called the composition of transformations

 The composition of two or more affine transformations

is also an affine transformation

Trang 16

Thuộc tính

 Tác động lên tập các điểm đặc trưng của đối

tượng tạo thành phép biến đổi cho đối tượng

 We have defined each transformation by their effects on single points

 In practice these will be applied to multiple points to

T

Trang 17

(c 1 ,c 2 )

(0,0)

Trang 18

Pivotal points

 Often we wish to rotate or scale with respect to some

pivotal point, not the origin

 Most significantly, we often wish to rotate or scale an

object about its centre, or midpoint

 In this way, the object’s location does not change

 To do this, we relate the rotation or scaling about the

pivotal point V, to an elementary rotation or scaling about the origin

– We first translate all points so that V coincides with the origin

– We then rotate or about the origin

Trang 19

 Unfortunately, the translation portion is not a

matrix multiplication but must instead be added as

an extra term, or vector

 What we need is a “trick”, so that translations can

be represented in matrix multiplication form

 This then means that they can be easily

composed with other transformations, by simply multiplying the matrices together

Trang 20

Tọa độ đồng nhất

Homogeneous Transform

tọa độ đồng nhất của các vector vị trí

ở đó tọa độ điểm được mô tả dưới ma trận [

Trang 21

Order matters: AB is generally not the same as BA

 Cho phép kết hợp với cả các phép biến đổi đặc biệt không tuyến tính khác(non-affine) như:

– Phép chiếu phối cảnh - Perspective projections!

– Uốn - Bends, Vuốt tapers v.v.v

Trang 22

Phép biến đổi với tọa độ đồng nhất

0 ]

[

n m

d c

b a

T

] 1 [

1

0 1 0

0 0 1

] 1 [

] 1 ' '

n m

y x

Trang 23

23

Phép tỉ lệ

] 1 2 1

[ 1

0 0

0 2 0

0 0

1 ] 1 [

] 1 ' '

S y

x y

Trang 24

0

0 cos

sin

0 sin

cos ]

1 [

] 1 '

y

x

]1cos

.sin

.sin

.cos

Trang 25

25

Phép biến đổi tổng hợp

Trang 26

Ma trận biến đổi 3 chiều

3D Matrix Transformations

 Các phép biến đổi chuyển vị - translation, tỉ

lệ-scaling và quay-rotation sử dụng trong không

gian 2D đều co thể mở rộng trong không gian 3D

 Again, using homogeneous coordinates it is

possible to represent each type of transformation

in a matrix form

 In 3D, each transformation is represented by a 4x4 matrix

Trang 27

27

Các phép biến đổi hình học 3 chiều

m l

r j

i g

q f

e d

p c

b a

]

[T

Trang 28

0 0

0 0

1 0

0 0

0 1

)]

, ,

(

[

dz dy

dx

dz dy

dx

T

Trang 29

0 0

0 3

0 0

0 0

2 0

0 0

0 1

1

1

s s

s z

y x

z y

[

] 1 3

2

1

.

Trang 31

0 0

0 0

0 0

0 0

0 1

sin

cos ]

0

0 1 0

0

0 0 cos

sin

0 0 sin

cos ]

Tz

Trang 32

0 0

0 cos

0 sin

0 0

1 0

0 sin

0 cos

] [

Trang 33

0 0

0 1

0 1

0 1

1

1

i g

f d

c b

z y

x z

y

[

] 1 [ xydgz bxyiz cxfyz

Trang 34

Phép lấy đối xứng

( reflections-secondary translation)

Trang 35

0 1

0 0

0 0

1 0

0 0

0 1

]

[

z y

00

00

00

00

01

sin

cos)]

01

00

00

10

00

01

1

z y

)cos1(sin

)cos1(0

0cos

sin0

0sin

cos0

00

01

z y

Tth

Trang 36

Quay quanh một trục bất kỳ

Trang 37

 Quay quanh trục x sao cho P1P2 trùng với trục z

 Quay quanh trục z sao cho P1P3 nằm trên mặt phẳng (y, z)

 Euler’s Theorem: Every rotation around the origin

can be decomposed into a rotation around the x-axis followed by a rotation around the y-axis followed by a rotation around the z-axis

Trang 38

Biến đổi góc nhìn Viewing Transformation

Lê Tấn Hùng

Trang 39

39

Nội dung

 Phép biến đổi nhìn cơ bản

 Biến đổi hệ thống tọa độ

 Biến đổi 3D viewing

 Ví dụ

Trang 40

Hệ tọa độ thực

(WCS-World Coordinate System)

 Là hệ tọa độ của đối tượng

được các chương trình

ứng dụng sử dụng để mô

tả tọa độ của các đối

tượng trong thế giới thực

 Đơn vị trong hệ thống tọa

độ phụ thuộc vào không

gian và kích thước của đối

tượng được mô tả, có thể

từ A0, nm, mm đến m,

km

Trang 41

41

Hệ tọa độ thiết bị

(DCS-Device Coordinate System)

 Là hệ thống tọa độ của thiết bị nơi hiển thị

hỡnh ảnh và khụng gian của đối tượng mà

ứng dụng mụ tả

Thiết bị hiển thị

subselect.me

Vùng tọa độ thiết bị VGA=640x480

Trang 42

Hệ tọa độ chuẩn

(NCS - Normalized Coordinate System)

 Chuyển đổi hệ tọa độ

 Giải quyết vấn đề khi ứng dụng chạy trờn cỏc thiết bị khỏc nhau

 Cú kớch thước 1x1

Wcs

chuyển đổi 1

NCS chuyển đổi 2 Dcs

Trang 43

43

Phép biến đổi nhìn cơ bản

Basic Viewing Transform

 Phép biến đổi góc nhìn cơ bản là chuyển đổi từ

hệ tọa độ mô hình sang hệ tọa độ mà hình

(Modelling co-ordinates to Screen Coordinates)

 Vấn đề:

 Thay đổi tỷ lệ hình ảnh

 Hiệu ứng về tỉ lệ khi Zoom hình ảnh

 Phần nào của hình vẽ sẽ hiển thị ?

 Hiển thị tại đâu trên màn hình ?

 Chuyển đổi sẽ được thực hiện ra sao?

Trang 44

max ,vy max)

Trang 45

45

Phép chuyển đổi

Trang 46

Phép biến đổi theo ma trận

 Ma trận chuyển vị theo Window

0

0 0

1 1

Yw Xw

0

0 min max

min max

0

0

0 Xwmin

Xwmax

-Xvmin -

Xvmax

] 1

[

Yw Yw

Yv Yv

S

Trang 47

max min

min Xwmin

Xwmax

-Xvmin -

Xvmax min

min

0 min

max

min

max 0

0

0 Xwmin

Xwmax

-Xvmin -

Xvmax

]

[

] 2 [ ] 1 [ ] 1 [ ]

[

Yw Yw

Yv

Yv Yw

Yv Xw

Xv

Yw Yw

Yv

Yv T

T x S x T T

Trang 48

Ví dụ OpenGL - Windows and Viewports

 Plotting a function revisted

//set the viewing coordinates

setWindow(xmin, xmax, ymin,

Trang 51

1 0

0 1

0

0

ty

tx ty

tx

1 0

1

ty

tx ty

tx

1 0 0

1 0

0 1

1

0

ty

tx ty

tx

1 0 0

1 0

0 1

Trang 52

O

Trang 53

0

0 Q

sx v

Trang 54

cos 1

(

sin )

cos 1

(

1 1

1 1

y x

cos 1

( sin

sin )

cos 1

( cos

1 1

1 1

y x

cos 1

( cos

sin )

cos 1

( sin

1 1

1 1

y x

O =

v =

u =

Trang 56

Quan sát 3D - 3D Viewing

 Hiển thị hình ảnh 3D trên các thiết bị

2D

 Mỗi 1 quan sát 3D trên cùng 1 đối

tượng chỉ ra trạng thái chiếu của

điểm quan sát đó

– HÌnh ảnh chiếu 2D của đối tượng 3D

phụ thuộc vào người quan sát

 Các quan sát khác nhau được phân

biệt bởi thông số: vị trí position, hướng

orientation, và vùng nhìn field of view

Trang 57

transformation

world coordinate

viewing coordinate (eye coordinate)

Viewing transformation

Trang 58

The Viewing Process

 Để tạo 1 cảnh nhìn gồm các bước

– Mô tả biểu diễn hình học

– Định nghĩa điểm nhìn – Camera

 Chuyển đổi từ đối tượng 3D sang 2D

 Xác định vùng hiển thị của đố tượng

 Xác định camera để có thể tạo thành phép chiếu từ 3D thành 2D

Trang 60

Viewing Coordinates

 Có thể sử dụng mô hình hệ

thống tọa độ quan sát trên các

thông số gồm:

– Điểm nhìn (VRP View Reference

Point ): điểm gốc quan sát Vị trí của Camera)

– Vector mặt phẳng quan sát (VPN

View Plane Normal vector ): viewing direction)

– Vector hướng quan sát (VUP View

UP vector ): establishes orientation of

“camera”

) , , (n1 n2 n3

N

N n

N V

Three mutually orthogonal basis vectors:

Trang 61

M WC,VC = T (-a, -b, -c )

zW

xW

yW

Trang 62

and

,

3 2 1

3 2 1

3 2 1

v v v

u u

u

n v

u

Ma trận biến đổi tọa độ thế giới sang tọa độ quan sát :

M = R T

(xw, yw, zw) and (u, v, n) 2 hệ tọa độ với cùng 1 gốc

Vector đơn vị (u, v, n) được định nghĩa theo WCS

Trang 63

63

3D Viewing Transformation

 Với điểm quan sát VRPoint (x0, y0, z0) the Viewing

Transformation can be defined by composition of the following two transformations:

0 0

1 0 0

0 1 0

0 0 1

0 0 0

z y

0

0 0 0

3 2

1

3 2

1

3 2

1

n n

n

v v

v

u u

u

R

T R

Trang 64

1 0 0

0 1 0

0 0 1

0 0 0

z y x

Trang 65

65 65

1 0

0 0

0 0

0

3 2

1

3 2

1

3 2

n

v v

v

u u

u u

u

R u

Trang 66

• Recall we’ve re-expressed our world geometry in eye’s frame

reference

• To do projection, we use a synthetic camera by introducing a

viewing frustum after the viewing transformation

Trang 67

67

Camera trong OpenGL

 Các hàm cơ bản

– glOrtho() and gluLookAt()

– these created parallel projections

 We now want to modify a scene to give us perspective projections

– lines converge as they get further away

Trang 68

Demo : Viewing

from Nate Robins

(Utah)

Trang 71

71

The Camera

– The camera is positioned using a combination

of translations and rotations

– Think if the camera being in the same location

as the viewers eye

Trang 72

The Camera

eye(x,y,z)

up(x,y,z)

Trang 73

73

The Camera

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(eye.x, eye.y, eye.z,

Trang 75

75

Camera Movement

 A camera has six degrees of freedom:

1. slid in 3 directions; and

2. rotated in 3 directions

 Camera Movement

– The camera can move along its axes

This is called sliding the camera

Trang 77

– the camera can be tilted in different directions to look

at different parts of the scene

Trang 78

The Camera - Camera Movement

We use a plane analogy to describe the cameras

movement

 a rotation from the horizontal along the length is called PITCH

 a rotation from the horizontal along the width is called ROLL

 a rotation around the vertical is called YAW

Trang 79

79

The Camera

 Pitch

v’ = cos(θ)v – sin(θ)n n’ = sin(θ)n + cos(θ)v

n

v

Trang 81

81

The Camera

 Yaw

n’ = cos(θ)n - sin(θ)u u’ = sin(θ)n + cos(θ)u

u

n

Trang 82

A 3D Scene

 Notice the presence of

the camera, the

projection plane, and

the world

coordinate axes

 Viewing transformations define how to acquire the image

on the projection plane

Trang 83

83

Viewing Transformations

 Create a camera-centered view

 Camera is at origin

 Camera is looking along negative z-axis

 Camera’s ‘up’ is aligned with y-axis

Trang 84

2 Basic Steps

 Align the two coordinate frames by rotation

Trang 85

85

2 Basic Steps

 Translate to align origins

Trang 86

Creating Camera Coordinate

 Specify a vector in world

space that we wish to

point up in camera

image, the up vector

 Intuitive camera

movement

Trang 87

87

Constructing Viewing

Transformation, V

 Create a vector from eye-point to lookat-point

 Normalize the vector

 Desired rotation matrix should map this

vector to [0, 0, -1]T Why?

Trang 88

Constructing Viewing

Transformation, V

 Construct another important vector from the

cross product of the lookat-vector and the vector

vup- This vector, when normalized, should align with [1, 0, 0]T Why?

Trang 89

89

Constructing Viewing

Transformation, V

 One more vector to define…

 This vector, when normalized, should align with [0, 1, 0]T

 Now let’s compose the results

Trang 90

Compositing Vectors to Form V

 We know the three world axis vectors (x, y, z)

 We know the three camera axis vectors (r, u, l)

 Viewing transformation, V, must convert from world to camera coordinate systems

Trang 91

91

Compositing Vectors to Form V

– Each camera axis vector is unit length

– Each camera axis vector is perpendicular to others

 Camera matrix is orthogonal and normalized

– Orthonormal

 Therefore, M-1 = MT

Trang 92

Compositing Vectors to Form V

 Therefore, rotation component of viewing

transformation is just transpose of computed vectors

Trang 93

93

Compositing Vectors to Form V

 Translation component too

 Multiply it through

Trang 94

Final Viewing Transformation, V

 To transform vertices, use this matrix:

 And you get this:

Ngày đăng: 24/10/2014, 01:37

HÌNH ẢNH LIÊN QUAN

Hình ảnh và không gian của đối tượng mà - Giáo trình thực tại ảo BKHN lesion 5:Các phép biến đổi Đồ hoạ Transformations
nh ảnh và không gian của đối tượng mà (Trang 41)

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm