Computer Graphics

advertisement
Computer Graphics
Chapter 6
Andreas Savva
Interactive Graphics
Graphics provides one of the most natural
means of communicating with a computer.
Interactive computer graphics permits usercomputer interaction.
2
Graphics Software
Programming packages (OpenGL)
Designed for programmers
General-Purpose Applications packages
(Paint)
Designed for non-programmers
3
Graphics Functions
A general-purpose graphics package provides users with
a variety of functions for creating and manipulating
pictures. These routines can be categorized according to
whether they deal with:
Output
Input
Attributes
Transformations
Viewing
General control
4
Output Primitives
basic tools for constructing pictures
Character strings
Geometric entities
Points
Straight lines
Curved lines
Filed areas (Polygons, Circles, etc)
Shapes defined with arrays or color points
5
Attributes
properties of the output primitives
Intensity
Color specifications
Line styles
Text styles
Area-filling patterns
6
Geometric Transformations
size, position and orientation of an object within the scene
Translate
Scale
Rotate
7
Control Operations
Clearing a display screen
Initialize a parameter
8
Software Standards
Primary goal – portability
Software can be moved easily from one
hardware system to another
Software can be used in different
implementations and applications
Without standards, software need to be
rewritten for different systems
9
A simple Paint Program
It should have the ability to work with geometric
objects such as line segments and polygons.
Given that geometric objects are defined through
vertices, the program should allow us to enter
vertices interactively.
It should have the ability to manipulated pixels,
and thus to draw directly into the frame buffer.
It should provide control of attributes such as
color, line type, and fill patterns.
It should include menus for controlling the
application.
It should behave correctly when the window is
moved or resized.
10
Coordinate Representations
Modeling coordinates: (xm , ym)
World coordinates: (xw , yw)
Normalized coordinates (Range: 0 - 1): (xn , yn)
Device coordinates: (xd , yd)
11
World to Device
(xw ,yw)
(xd ,yd)
Display area
MaxXw  MinXw
xScale
DeviceW idt
h
xw  MinXw
xd 
xScale
MaxYw  MinYw
yScale
DeviceHeight
y w  MinYw
yd 
yScale
12
World to Normalized
x w  MinXw
xn 
MaxXw  MinXw
y w  MinYw
yn 
MaxYw  MinYw
Normalized to Device
xd  xn  DeviceW idth
yd  yn  DeviceHeight
13
Device Coordinates
(xd ,yd)
(xw ,yw)
(0,0)
(0,0)
(xd ,DeviceHeight-yd)
Display area
14
Exercises
(0,0)
Assume that the screen monitor has
1200800 pixels. Find and display:
(1200,800)
1. the device coordinates for the point (-18,12) if the
display area is -25 ≤ x ≤ 8 and -8 ≤ y ≤ 16, as shown
below:
16
(-18,12)
-25
8
-8
Display area
2. the device coordinates for the point (-18,12) if the
display area is -216 ≤ x ≤ -2 and -30 ≤ y ≤ 30.
15
3.
the device coordinates for the triangle shown in the
figure below, by using the normalized coordinates
which you should calculate first.
40
(35,30)
(18,10)
-5
10
(43,15)
50
Display area
4.
5.
the device coordinates for the triangle shown above
if the display area is 25 ≤ x ≤ 100 and -5 ≤ y ≤ 40.
You should also find the device coordinates for the
two points where the triangle sides intersect the line
x = 25.
the world coordinate of the pixel (400,167) for the
display area in question 1.
16
Pipeline Vs Parallelism
Multiprocessing has two basic forms:
A pipeline processor contains a number of
processing elements (PEs) arranged such that
the output of one becomes the input of the
next, in pipeline fashion.
The PEs of a parallel processor are arranged
side-by-side and operate simultaneously on
different portions of the data.
17
Drawing Pipeline
Standard drawing process uses a pipeline
of computations
Starts with: Collection of polygons
Ends with: Image stored in frame buffer
(Desired result)
18
Pipeline
Input device
Model traversal
new view of the model
Model transform
Viewing transform
Clipping
Project & Map to Viewport
Lighting
Shading
Rasterization
Display
19
Model Traversal
Data structure of Polygons
Each polygon in own coordinate system
List:
0
1
2
3
20
Modeling Transformations
Move each polygon to its desired location
y
0
1
2
3
x
Operations: Translate, Scale, Rotate
21
Clipping
Viewport is the area of the Frame Buffer
where the new image is to appear
Clipping eliminates geometry outside the
viewport
Resulting
Polygon
Clipping
Viewport
22
Project & Map to Viewport
Projection takes 3D data and flattens it to 2D
Eye
Projection Plane
(Screen)
23
Lighting
Simulate effects of light on surface of objects
Each polygon gets some light independent of
other objects
24
Shading
Lighting could be calculated for each pixel,
but that’s expensive
Shading is an approximation:
Gouraud shading: Light each vertex
Interpolate color across pixels
25
Rasterization
Find which pixels are covered by polygon:
Plane Sweep: For each polygon
go line-by-line from min to max
go from left boundary to right boundary pixel by pixel
Fill each pixel (color & density)
2D Process
26
Download