Upload
jasmine-jenkins
View
307
Download
12
Embed Size (px)
Citation preview
Introduction to Computer GraphicsChapter 6 – 2D Viewing Pt 1
1
2
Two-Dimensional Viewing
Co-ordinate Systems.Co-ordinate Systems.
Cartesian – offsets along the x and y axis from (0.0)Cartesian – offsets along the x and y axis from (0.0)
Polar – rotation around the angle Polar – rotation around the angle ..
Graphic libraries mostly using Cartesian co-ordinatesGraphic libraries mostly using Cartesian co-ordinates
Any polar co-ordinates must be converted to Cartesian co-Any polar co-ordinates must be converted to Cartesian co-ordinatesordinates
Four Cartesian co-ordinates systems in computer Graphics.Four Cartesian co-ordinates systems in computer Graphics.
1. Modeling co-ordinates1. Modeling co-ordinates
2. World co-ordinates2. World co-ordinates
3.3. Normalized device co-ordinatesNormalized device co-ordinates
4. Device co-ordinates4. Device co-ordinates
3
Modeling Coordinates
Also known as local coordinate.Also known as local coordinate.
Ex: where individual object in a scene within separate Ex: where individual object in a scene within separate coordinate reference frames.coordinate reference frames.
Each object has an origin (0,0)Each object has an origin (0,0)
So the part of the objects are placed with reference to the So the part of the objects are placed with reference to the object’s origin.object’s origin.
In term of scale it is user defined, so, coordinate values can be In term of scale it is user defined, so, coordinate values can be any size.any size.
4
World Co-ordinates.
The world coordinate system describes the relative positions The world coordinate system describes the relative positions and orientations of every generated objects.and orientations of every generated objects.
The scene has an origin (0,0).The scene has an origin (0,0).
The object in the scene are placed with reference to the The object in the scene are placed with reference to the scenes origin.scenes origin.
World co-ordinate scale may be the same as the modeling co-World co-ordinate scale may be the same as the modeling co-ordinate scale or it may be different.ordinate scale or it may be different.
However, the coordinates values can be any size (similar to However, the coordinates values can be any size (similar to MC) MC)
5
Normalized Device Co-ordinates
Output devices have their own co-ordinates.Output devices have their own co-ordinates.
Co-ordinates values:Co-ordinates values:
The x and y axis range from 0 to 1The x and y axis range from 0 to 1
All the x and y co-ordinates are floating point numbers in the All the x and y co-ordinates are floating point numbers in the range of 0 to 1range of 0 to 1
This makes the system independent of the various devices This makes the system independent of the various devices coordinates.coordinates.
This is handled internally by graphic system without user This is handled internally by graphic system without user awareness.awareness.
6
Device Co-ordinates
Specific co-ordinates used by a device.Specific co-ordinates used by a device.
Pixels on a monitorPixels on a monitor
Points on a laser printer.Points on a laser printer.
mm on a plotter.mm on a plotter.
The transformation based on the individual device is handled The transformation based on the individual device is handled by computer system without user concern. by computer system without user concern.
7
Two-Dimensional Viewing
Example:Example:
Graphic program which draw an entire building by an Graphic program which draw an entire building by an architect but we only interested on the ground floorarchitect but we only interested on the ground floor
Map of sales for entire region but we only like to Map of sales for entire region but we only like to know from certain region of the country.know from certain region of the country.
8
Two-Dimensional Viewing
When we interested to display certain portion of the drawing, When we interested to display certain portion of the drawing, enlarge the portion, enlarge the portion, windowing windowing technique is usedtechnique is used
Technique for not showing the part of the drawing which one is Technique for not showing the part of the drawing which one is not interested is called not interested is called clippingclipping
An area on the device (ex. Screen) onto which the window will An area on the device (ex. Screen) onto which the window will be mapped is called be mapped is called viewport.viewport.
Window defines what to be displayed.Window defines what to be displayed.
A viewport defines where it is to be displayed.A viewport defines where it is to be displayed.
Most of the time, windows and viewports are usually rectangles Most of the time, windows and viewports are usually rectangles in standard position(i.e aligned with the x and y axes). In some in standard position(i.e aligned with the x and y axes). In some application, others such as general polygon shape and circles application, others such as general polygon shape and circles are also availableare also available
However, other than rectangle will take longer time to process.However, other than rectangle will take longer time to process.
9
Viewing Transformation
Viewing transformationViewing transformation is the mapping of a part of a world- is the mapping of a part of a world-coordinate scene to device coordinates.coordinate scene to device coordinates.
In 2D (two dimensional) viewing transformation is simply In 2D (two dimensional) viewing transformation is simply referred as the referred as the window-to-viewport transformation window-to-viewport transformation or the or the windowing transformationwindowing transformation..
Mapping a window onto a viewport involves converting from Mapping a window onto a viewport involves converting from one coordinate system to another.one coordinate system to another.
If the window and viewport are in standard position, this just If the window and viewport are in standard position, this just
involves translation and scaling.involves translation and scaling.
if the window and/or viewport are not in standard, then if the window and/or viewport are not in standard, then extra transformation which is rotation is required. extra transformation which is rotation is required.
10
Viewing Transformation
0
1
1x-world
y-world
window window
Normalised deviceworld
y-view
x-view
11
Window-To-Viewport Coordinate Transformation
Window-to-Viewport transformation
12
Window-To-Viewport Coordinate Transformation
.
XWmax
YWmax
XWmin
YWmin
XVmaxXVmin
YVmax
YVminxw,yw
xv,yv
13
Window-To-Viewport Coordinate Transformation
xv - xvxv - xvminmin = = xw - xwxw - xw
minmin
xvxvmax - max - xvxv
minmin xw xwmaxmax - xw - xw
minmin
yv – yvyv – yvmin min = = yw - yw yw - yw
minmin
yvyvmax – max – yvyv
min min yw ywmax - max - ywyw
minmin
From these two equations we derived From these two equations we derived
xv = xvxv = xvmin min + (xw – xw+ (xw – xw
minmin)sx)sx
yv = yvyv = yvmin min + (yw – yw+ (yw – yw
minmin)sy)sy
where the scaling factors arewhere the scaling factors are
sx = xvsx = xvmax – max – xvxv
minmin sy = yvsy = yvmax - max - yvyv
minmin
xwxwmax – max – xwxw
minmin ywywmax - max - ywyw
minmin
14
Window-To-Viewport Coordinate Transformation
The sequence of transformations are:The sequence of transformations are:
1. Perform a scaling transformation using a 1. Perform a scaling transformation using a fixed-point position of (xwfixed-point position of (xw
min,min,ywywminmin) that ) that
scales the window area to the size of the scales the window area to the size of the viewport.viewport.
2. Translate the scaled window area to the 2. Translate the scaled window area to the position of the viewportposition of the viewport..
15
Window-To-Viewport Coordinate Transformation
Relative proportions of objects are maintained if the scaling Relative proportions of objects are maintained if the scaling factors are the same (sx = sy). Otherwise, world objects will be factors are the same (sx = sy). Otherwise, world objects will be stretched or contracted in either x or y direction when stretched or contracted in either x or y direction when
displayed on output device.displayed on output device.
How about character strings when map to viewport?about character strings when map to viewport?
maintains a constant character size (apply when maintains a constant character size (apply when standard character fonts cannot be changed).standard character fonts cannot be changed).
If character size can be changed, then windowed will be If character size can be changed, then windowed will be applied like other primitives.applied like other primitives.
For characters formed with line segments, the mapping For characters formed with line segments, the mapping to viewport is carried through sequence of line to viewport is carried through sequence of line
transformationstransformations ..
16
Viewport-to-Normalized Device Coordinate Transformation
From normalized coordinates, object descriptions can be mapped to the various display devices
When mapping window-to-viewport transformation is done to different devices from one normalized space, it iscalled workstation transformation.
17
The Viewing Pipeline
18
OpenGL 2D Viewing Functions
• To transform from world coordinate to screen coordinates, the appropriate matrix mode must be chosen
• glMatrixMode (GL_PROJECTION);• glLoadIdentity( );
• To define a 2D clipping window, we use OpenGL Utility function:
• gluOrtho2D( xwmin, xwmax, ywmin, ywmax);
• This function also perform normalization (NDC)
19
OpenGL 2D Viewing Functions
• To specify the viewport parameters in OpenGL, we use function
• glViewport(xvmin, yvmin, vpWidth, vpHeight);