Tải bản đầy đủ (.pdf) (35 trang)

Lecture computer graphics and virtual reality slides lesson 6 viewing transformation

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.09 MB, 35 trang )

Lesson 6

Viewing
Transformation

Trinh Thanh Trung School of ICT, HUST

Content

1. Overview
2. 2D viewing transformation
3. 3D viewing transformation

1.
Overview

Viewing transformation

■ More logical to use dimensions which are
appropriate to the object. e.g.

□ metres for buildings,
□ millimetres for assembly parts,
□ nanometres or microns for molecules, cells, and

atoms

■ Objects are described with respect to their actual
physical size in the real world,
■ These measurements are then mapped onto
screen co-ordinates before displaying



Viewing transformation

■ Apply transform to convert from Modelling co-
ordinates to Screen Coordinates
■ We can scale dimensions to change the resulting
view
■ We can even achieve a zooming in and out
effect without changing the model by scaling
dimensions proportionally

Problems

■ How much of the model should be drawn?
■ Where should it appear on the display?
■ How do we convert Real-world co-ordinates into
screen co-ordinates?

Viewing transformation

■ Transform into camera coordinates.
■ Perform projection into screen coordinate or
view volume.
■ Clip geometry outside the view volume

■ Homogeneous transformation

v=Mproj Mc←w Mw←l vl

Homogeneous Coordinates


■ In homogenous coordinates, (x,y,z,w) represent
the same point when all elements are multiplied by
the same factor

□ (2,0,1,1) and (4,0,2,2) are the same points
□ To bring back to Cartesian space, need to

divide the other elements by the fourth element w
▫ (x, y, z, w) → (x/w, y/w, z/w, 1)

2.
2D viewing transformation

Window and viewport

■ Window: the portion of the world which will be
displayed

■ Viewport: The screen where the image will be
displayed

(wxmax,wymax) (vxmax,vymax)

(wx,wy) (vx,vy)
(wxmin,wymin) (vxmin,vymin)

Transformation

Transformation matrices


■ Translation to window  1 0 0
transformation matrix [T1] =  0 1 0

− Xw − Yw 1

 Xvmax - Xvmin 0 0
 Xwmax - Xwmin
 Yv max − Yv min 
■ Scale
[S1] =  0 0
Yw max − Yw min 
 0 0 1



 

■ Translation to viewport  1 0 0
transformation matrix [T 2] =  0 1 0

 Xv Yy 1

Combined transformation matrix

[T ] = [T1]x[S1]x[T 2]

 Xvmax- Xvmin 

 Xwmax- Xwmin 0 0

 0
[T ] =  Yv max - Yv min 

0

 Yw max -Ywmin 

 Xvmax- Xvmin Yv max -Yv min Xv min− Xwmin Yv min− Ywmin 1
 Yw max -Yw min 
Xwmax- Xwmin

Example in OpenGL

//set the viewing coordinates //--------------- setWindow -----------
setWindow(xmin, xmax, ymin, ymax); ----------
setViewport(0,640,0,480); void setWindow(GLdouble left, Gldouble
glBegin(GL_POINTS); right, GLdouble bottom, GLdouble top)
{
for(GLdouble x = xmin; x < xmax;
x+=0.005 ) glMatrixMode(GL_PROJECTION);
glLoadIdentity();
{ gluOrtho2D(left, right, bottom, top);
glVertex2d(x, pow(2.7183,-x) }
*cos(2*3.14*x)); //---------------- setViewport --------
----------
} void setViewport(GLdouble left,
glEnd(); Gldouble right, GLdouble bottom,
GLdouble top)
{
glViewport(left, bottom,


right – left, top - bottom);
}

3.
3D viewing transformation

3D viewing

■ Part of the difficulty lies in trying to display three
dimensional objects on a 2D display
■ Different views on the same object eventually
lead to different 2D representations at the
projection stage

□ The projected 2D image of a 3D object is viewer
dependent

■ Different views can be specified based on several
parameters e.g. position, orientation, field of view

3D viewing

■ To create a view of a scene we need:

□ a description of the scene geometry
□ a view definition (camera)

■ We need to transform the 3D objects onto a 2D
plane

■ A real-world window is defined on this plane
■ This window is then mapped to the viewport as
in 2D viewing
■ The camera definition allows projection of the 3D
scene geometry onto a 2D surface for display.

Viewing coordinates

y

z

x

yW

pV

yM

zM p pW
zW
M

xM xW

Viewing coordinates

■ NOTE: Camera always looks at the negative of
the z-axis


Point of view on
zW -axis

yW yW

(a, b, c)

xW xW

n zW

(0, 0, z) MWC,VC = T (-a, -b, -c )

zW MWC,VC = T (0, 0, z,)

Camera analogy

■ The synthetic camera model involves 2
components, specified independently:

□ objects (a.k.a. geometry)
□ viewer (a.k.a. camera)

■ The image is rendered onto an image plane or
projection plane (usually in front of the camera).
■ Projectors emanate from the center of
projection (COP) at the center of the lens (or
pinhole).


□ The image of an object point P is at the intersection
of the projector through P and the image plane.


×