SlideShare a Scribd company logo
1 of 47
Computer Graphics
Chapter Three
Faculty of Artificial Intelligence
Autonomous Systems Department
1. Coordinate Reference Frames
2. Specifying a Two-Dimensional World-
Coordinate Reference Frame in
OpenGL
3. OpenGL Point Functions
4. OpenGL Line Functions
5. OpenGL Curve Functions
6. Fill-Area Primitives
7. Polygon Fill Areas
8. OpenGL Polygon Fill-Area Functions.
Content
2
• Describing various picture components of a virtual
scene is one of the first things needed when
generated a computer picture .
To provide the shape or structure of the individual
objects
To provide their coordinate locations in the scene
• We need:
• 1) graphics output primitive that are functions in
CG API describe such picture components
• 2) Geometric primitives to define the geometry of
objects such as Lines, Triangles, Quadrics, Conic
sections, Curved surfaces, ……
Definitions
3
• The coordinate positions are stored in the scene
description alongside the information about the
objects, such as their color and their coordinate
extents.
• Coordinate extents are the lowest and highest x,
and z values for each object.
• A set of coordinate extents is also described as a
bounding box for an object.
• For a two-dimensional figure, the coordinate
extents are sometimes called an object’s
bounding rectangle.
Coordinate Reference Frames
4
• Locations on a video monitor are referenced in integer
screen coordinates, which correspond to the pixel
positions in the frame buffer.
Screen Coordinates
5
• Given the low-level procedure of the form
setPixel (x, y);
• This procedure stores the current color
setting into the frame buffer at integer
position (x, y), relative to the selected
position of the screen-coordinate origin.
Screen Coordinates
6
•To retrieve the current frame-buffer setting for a
pixel location, use the following low-level
function for obtaining a frame-buffer color value:
getPixel (x, y, color);
•In this function, parameter color receives an
integer value corresponding to the combined red,
green, and blue (RGB) bit codes stored for the
specified pixel at position (x, y).
Screen Coordinates
7
• To set up any two-dimensional Cartesian
reference frame, use the function gluOrtho2D.
• This function specifies an orthogonal projection,
we need to ensure that the coordinate values are
placed in the OpenGL projection matrix.
• We could also assign the identity matrix as the
projection matrix before defining the world-
coordinate range.
Specifying A Two-Dimensional World-Coordinate
Reference Frame in OpenGL
8
• In the two-dimensional examples, define the
coordinate frame for the screen display window
with the following:
glMatrixMode (GL_PROJECTION);
glLoadIdentity ( );
gluOrtho2D (xmin, xmax, ymin, ymax);
• The display window is referenced by (xmin, ymin)
coordinates at the lower-left corner, and by
(xmax, ymax) coordinates at the upper-right
corner, as shown in Figure 2.
Specifying A Two-Dimensional World-Coordinate
Reference Frame in OpenGL
9
A Two-Dimensional World-Coordinate Frame in
OpenGL
10
• To state the coordinate values for a single
position, use the OpenGL function :
glVertex* ( );
• The asterisk (*) suffix codes are used in this
function to identify the spatial dimension, the
numerical data type to be used for the coordinate
values, and a possible vector form for the
coordinate specification.
OpenGl Point Functions
11
• Calls to glVertex functions must be placed between a
glBegin function and a glEnd function.
• The argument of the glBegin function is used to identify
the kind of geometric output primitive that is to be
displayed, and glEnd takes no arguments.
• For point plotting, the argument of the glBegin function is
the symbolic constant GL_POINTS.
• Thus, the form for an OpenGL specification of a point
position is:
glBegin (GL_POINTS);
glVertex* ( );
glEnd ( );
OpenGl Point Functions
12
• Coordinate positions in OpenGL can be given in two,
three, or four dimensions.
• We use a suffix value of 2, 3, or 4 on the glVertex
function to indicate the dimensionality of a coordinate
position.
• A four-dimensional specification indicates a
homogeneous-coordinate representation, where the
fourth coordinate parameter h is a scaling factor for the
Cartesian-coordinate values.
• Homogeneous-coordinate representations are useful
for expressing transformation operations in Matrix form.
OpenGl Point Functions
13
• Because OpenGL treats two-dimensions as a special
case of three dimensions, any (x, y) coordinate
specification is equivalent to a three-dimensional
specification of (x, y, 0).
• We need to specify which data type to be used for the
numerical value specifications of the coordinates.
• This is accomplished with a second suffix code on the
glVertex function.
• Suffix codes for specifying a numerical data type are i
(integer), s (short), f (float), and d (double).
OpenGl Point Functions
14
• Finally, the coordinate values can be listed
explicitly in the glVertex function, or a single
argument can be used that references a
coordinate position as an array.
• If we use an array specification for a coordinate
position, we need to append v (for “vector”) as a
third suffix code.
OpenGl Point Functions
15
• In this example, three equally spaced points are
plotted along a two dimensional, straight-line
path, where coordinates are given as integer pairs:
glBegin (GL_POINTS);
glVertex2i (50, 100);
glVertex2i (75, 150);
glVertex2i (100, 200);
glEnd ( );
OpenGl Point Functions
16
OpenGl Point Functions
17
• Alternatively, we could use the coordinate
values for the preceding points in arrays as:
int point1 [ ] = {50, 100};
int point2 [ ] = {75, 150};
int point3 [ ] = {100, 200};
• and call the OpenGL functions for plotting
the three points as
glBegin (GL_POINTS);
glVertex2iv (point1);
glVertex2iv (point2);
glVertex2iv (point3);
glEnd ( );
OpenGl Point Functions
18
• Graphic packages normally provide a function for
specifying one or more straight-line segments, where
each line segment is defined by two endpoint
coordinate positions.
• For example, if we have five coordinate positions,
labelled p1 through p5, and each position is
represented by a two-dimensional array, then the
following code could create the display shown in
Figure 4(a):
glBegin (GL_LINES);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
OpenGl Line Functions
19
OpenGl Line Functions
20
• Using the OpenGL primitive constant
GL_LINE_STRIP, we obtain a polyline.
• Using the same five coordinate positions as in
the previous example, we obtain the display in
Figure 4(b) with the code
glBegin (GL_LINE_STRIP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
OpenGl Line Functions
21
• The third OpenGL line primitive is GL_LINE_LOOP, which
produces a closed polyline.
• Figure 4(c) shows the display of our endpoint list when we
select this line option, using the code
glBegin (GL_LINE_LOOP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
OpenGl Line Functions
22
• Routines for generating basic curves, such as circles
and ellipses, are not included as primitive functions
in the OpenGL core library.
• But this library does contain functions for
displaying B´ezier splines, which are polynomials
that are defined with a discrete point set.
• And the OpenGL Utility (GLU) library has routines
for three-dimensional quadrics, such as spheres and
cylinders, as well as routines for producing rational
B-splines, which are a general class of splines that
include the simpler B´ezier curves.
OpenGl Curve Functions
23
• Using rational B-splines, we can display circles,
ellipses, and other two-dimensional quadrics.
• In addition, there are routines in the OpenGL
Utility Toolkit (GLUT) that we can use to display
some three-dimensional quadrics, such as spheres
and cones, and some other shapes.
• However, all these routines are more involved
than the basic primitives we introduce in this
chapter.
OpenGl Curve Functions
24
OpenGl Curve Functions
25
• Another useful construct, besides points,
straight-line segments, and curves, for
describing components of a picture is an
area that is filled with some solid color or
pattern.
• A picture component of this type is
typically referred to as a fill area or a
filled area.
Fill-Area Primitives
26
Fill-Area Primitives
27
Fill-Area Primitives
28
• Objects described with a set of polygon
surface patches are usually referred to as
standard graphics objects, or just
graphics objects.
Fill-Area Primitives
29
• Mathematically defined, a polygon is a plane
figure specified by a set of three or more
coordinate positions, called vertices, that are
connected in sequence by straight-line segments,
called the edges or sides of the polygon.
• Examples of polygons include triangles,
rectangles, octagons, and decagons.
Polygon Fill Areas
30
• Sometimes, any plane figure with a closed-
polyline boundary is alluded to as a polygon, and
one with no crossing edges is referred to as a
standard polygon or a simple polygon.
• In an effort to avoid ambiguous object references,
we will use the term polygon to refer only to
those planar shapes that have a closed-polyline
boundary and no edge crossings.
Polygon Fill Areas
31
• With one exception, the OpenGL procedures for
specifying fill polygons are similar to those for
describing a point or a polyline.
• A glVertex function is used to input the
coordinates for a single polygon vertex, and a
complete polygon is described with a list of
vertices placed between a glBegin/glEnd pair.
• However, there is one additional function that
we can use for displaying a rectangle that has
an entirely different format.
OpenGL Polygon Fill-Area Functions
32
• By default, a polygon interior is displayed in a solid color,
determined by the current color settings.
• As options, we can fill a polygon with a pattern and we can
display polygon edges as line borders around the interior
fill.
• There are six different symbolic constants that we can use
as the argument in the glBegin function to describe
polygon fill areas.
• These six primitive constants allow us to display a single
fill polygon, a set of unconnected fill polygons, or a set of
connected fill polygons.
OpenGL Polygon Fill-Area Functions
33
• In OpenGL, a fill area must be specified as a
convex polygon.
• Thus, a vertex list for a fill polygon must
contain at least three vertices, there can be no
crossing edges, and all interior angles for the
polygon must be less than 180◦.
OpenGL Polygon Fill-Area Functions
34
• Because graphics displays often include rectangular fill areas,
OpenGL provides a special rectangle function that directly
accepts vertex specifications in the xy plane.
• In some implementations of OpenGL, the following routine can
be more efficient than generating a fill rectangle using
glVertex specifications:
glRect* (x1, y1, x2, y2);
• One corner of this rectangle is at coordinate position (x1, y1),
and the opposite corner of the rectangle is at position (x2, y2).
• Suffix codes for glRect specify the coordinate data type and
whether coordinates are to be expressed as array elements.
• These codes are i (for integer), s (for short), f (for float), d (for
double), and v (for vector). The rectangle is displayed with
edges parallel to the xy coordinate axes.
OpenGL Polygon Fill-Area Functions
35
• As an example, the following statement defines
the square shown in Figure 21:
glRecti (200, 100, 50, 250);
• If we put the coordinate values for this rectangle
into arrays, we can generate the same square with
the following code:
int vertex1 [ ] = {200, 100};
int vertex2 [ ] = {50, 250};
glRectiv (vertex1, vertex2);
OpenGL Polygon Fill-Area Functions
36
OpenGL Polygon Fill-Area Functions
37
• Each of the other six OpenGL polygon fill
primitives is specified with a symbolic
constant in the glBegin function, along with
a a list of glVertex commands.
• With the OpenGL primitive constant
GL_POLYGON, we can display a single
polygon fill area such as that shown in Figure
22(a).
OpenGL Polygon Fill-Area Functions
38
OpenGL Polygon Fill-Area Functions
39
• For this example, we assume that we have a list of
six points, labeled p1 through p6, specifying two-
dimensional polygon vertex positions in a
counterclockwise ordering.
• Each of the points is represented as an array of (x,
y) coordinate values:
glBegin (GL_POLYGON);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glVertex2iv (p6);
glEnd ( );
OpenGL Polygon Fill-Area Functions
40
• If we reorder the vertex list and change the
primitive constant in the previous code
example to GL_TRIANGLES, we obtain the
two separated triangle fill areas in Figure
22(b):
glBegin (GL_TRIANGLES);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p6);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
OpenGL Polygon Fill-Area Functions
41
• By reordering the vertex list once more and
changing the primitive constant to
GL_TRIANGLE_STRIP, we can display the set
of connected triangles shown in Figure 22(c):
glBegin (GL_TRIANGLE_STRIP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p6);
glVertex2iv (p3);
glVertex2iv (p5);
glVertex2iv (p4);
glEnd ( );
OpenGL Polygon Fill-Area Functions
42
• Another way to generate a set of connected triangles
is to use the “fan” approach illustrated in Figure 22(d),
where all triangles share a common vertex.
• We obtain this arrangement of triangles using the
primitive constant GL_TRIANGLE_FAN and the
original ordering of our six vertices:
glBegin (GL_TRIANGLE_FAN);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glVertex2iv (p6);
glEnd ( );
OpenGL Polygon Fill-Area Functions
43
• Besides the primitive functions for triangles and
a general polygon, OpenGL provides for the
specifications of two types of quadrilaterals
(four-sided polygons).
OpenGL Polygon Fill-Area Functions
44
OpenGL Polygon Fill-Area Functions
45
• With the GL_QUADS primitive constant and the
following list of eight vertices, specified as two-
dimensional coordinate arrays, we can generate the
display shown in Figure 23(a):
glBegin (GL_QUADS);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glVertex2iv (p6);
glVertex2iv (p7);
glVertex2iv (p8);
glEnd ( );
OpenGL Polygon Fill-Area Functions
46
• Rearranging the vertex list in the previous
quadrilateral code example and changing the
primitive constant to GL_QUAD_STRIP, we can obtain
the set of connected quadrilaterals shown in Figure
23(b):
glBegin (GL_QUAD_STRIP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p4);
glVertex2iv (p3);
glVertex2iv (p5);
glVertex2iv (p6);
glVertex2iv (p8);
glVertex2iv (p7);
glEnd ( );
OpenGL Polygon Fill-Area Functions
47

More Related Content

Similar to CG Graphics Chapter on Coordinate Frames

3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptxssuser255bf1
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)RohitK71
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3SIMONTHOMAS S
 
Comparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for ImprovementComparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for ImprovementIJMER
 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
 
3d-object-representation.pdf
3d-object-representation.pdf3d-object-representation.pdf
3d-object-representation.pdfKeerthanaP37
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingMark Kilgard
 
Unit 3
Unit 3Unit 3
Unit 3ypnrao
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene GraphsSyed Zaid Irshad
 
CS 354 Pixel Updating
CS 354 Pixel UpdatingCS 354 Pixel Updating
CS 354 Pixel UpdatingMark Kilgard
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardwarestefan_b
 

Similar to CG Graphics Chapter on Coordinate Frames (20)

Boundary fill algm
Boundary fill algmBoundary fill algm
Boundary fill algm
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)
 
Curves and surfaces
Curves and surfacesCurves and surfaces
Curves and surfaces
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
 
Comparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for ImprovementComparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for Improvement
 
JDK and AWT
JDK and AWTJDK and AWT
JDK and AWT
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
3d-object-representation.pdf
3d-object-representation.pdf3d-object-representation.pdf
3d-object-representation.pdf
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
Shading in OpenGL
Shading in OpenGLShading in OpenGL
Shading in OpenGL
 
Unit 4 notes
Unit 4 notesUnit 4 notes
Unit 4 notes
 
cg mod2.pdf
cg mod2.pdfcg mod2.pdf
cg mod2.pdf
 
Unit 3
Unit 3Unit 3
Unit 3
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene Graphs
 
Geometric model & curve
Geometric model & curveGeometric model & curve
Geometric model & curve
 
CS 354 Pixel Updating
CS 354 Pixel UpdatingCS 354 Pixel Updating
CS 354 Pixel Updating
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
 
Building Models
Building ModelsBuilding Models
Building Models
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

CG Graphics Chapter on Coordinate Frames

  • 1. Computer Graphics Chapter Three Faculty of Artificial Intelligence Autonomous Systems Department
  • 2. 1. Coordinate Reference Frames 2. Specifying a Two-Dimensional World- Coordinate Reference Frame in OpenGL 3. OpenGL Point Functions 4. OpenGL Line Functions 5. OpenGL Curve Functions 6. Fill-Area Primitives 7. Polygon Fill Areas 8. OpenGL Polygon Fill-Area Functions. Content 2
  • 3. • Describing various picture components of a virtual scene is one of the first things needed when generated a computer picture . To provide the shape or structure of the individual objects To provide their coordinate locations in the scene • We need: • 1) graphics output primitive that are functions in CG API describe such picture components • 2) Geometric primitives to define the geometry of objects such as Lines, Triangles, Quadrics, Conic sections, Curved surfaces, …… Definitions 3
  • 4. • The coordinate positions are stored in the scene description alongside the information about the objects, such as their color and their coordinate extents. • Coordinate extents are the lowest and highest x, and z values for each object. • A set of coordinate extents is also described as a bounding box for an object. • For a two-dimensional figure, the coordinate extents are sometimes called an object’s bounding rectangle. Coordinate Reference Frames 4
  • 5. • Locations on a video monitor are referenced in integer screen coordinates, which correspond to the pixel positions in the frame buffer. Screen Coordinates 5
  • 6. • Given the low-level procedure of the form setPixel (x, y); • This procedure stores the current color setting into the frame buffer at integer position (x, y), relative to the selected position of the screen-coordinate origin. Screen Coordinates 6
  • 7. •To retrieve the current frame-buffer setting for a pixel location, use the following low-level function for obtaining a frame-buffer color value: getPixel (x, y, color); •In this function, parameter color receives an integer value corresponding to the combined red, green, and blue (RGB) bit codes stored for the specified pixel at position (x, y). Screen Coordinates 7
  • 8. • To set up any two-dimensional Cartesian reference frame, use the function gluOrtho2D. • This function specifies an orthogonal projection, we need to ensure that the coordinate values are placed in the OpenGL projection matrix. • We could also assign the identity matrix as the projection matrix before defining the world- coordinate range. Specifying A Two-Dimensional World-Coordinate Reference Frame in OpenGL 8
  • 9. • In the two-dimensional examples, define the coordinate frame for the screen display window with the following: glMatrixMode (GL_PROJECTION); glLoadIdentity ( ); gluOrtho2D (xmin, xmax, ymin, ymax); • The display window is referenced by (xmin, ymin) coordinates at the lower-left corner, and by (xmax, ymax) coordinates at the upper-right corner, as shown in Figure 2. Specifying A Two-Dimensional World-Coordinate Reference Frame in OpenGL 9
  • 11. • To state the coordinate values for a single position, use the OpenGL function : glVertex* ( ); • The asterisk (*) suffix codes are used in this function to identify the spatial dimension, the numerical data type to be used for the coordinate values, and a possible vector form for the coordinate specification. OpenGl Point Functions 11
  • 12. • Calls to glVertex functions must be placed between a glBegin function and a glEnd function. • The argument of the glBegin function is used to identify the kind of geometric output primitive that is to be displayed, and glEnd takes no arguments. • For point plotting, the argument of the glBegin function is the symbolic constant GL_POINTS. • Thus, the form for an OpenGL specification of a point position is: glBegin (GL_POINTS); glVertex* ( ); glEnd ( ); OpenGl Point Functions 12
  • 13. • Coordinate positions in OpenGL can be given in two, three, or four dimensions. • We use a suffix value of 2, 3, or 4 on the glVertex function to indicate the dimensionality of a coordinate position. • A four-dimensional specification indicates a homogeneous-coordinate representation, where the fourth coordinate parameter h is a scaling factor for the Cartesian-coordinate values. • Homogeneous-coordinate representations are useful for expressing transformation operations in Matrix form. OpenGl Point Functions 13
  • 14. • Because OpenGL treats two-dimensions as a special case of three dimensions, any (x, y) coordinate specification is equivalent to a three-dimensional specification of (x, y, 0). • We need to specify which data type to be used for the numerical value specifications of the coordinates. • This is accomplished with a second suffix code on the glVertex function. • Suffix codes for specifying a numerical data type are i (integer), s (short), f (float), and d (double). OpenGl Point Functions 14
  • 15. • Finally, the coordinate values can be listed explicitly in the glVertex function, or a single argument can be used that references a coordinate position as an array. • If we use an array specification for a coordinate position, we need to append v (for “vector”) as a third suffix code. OpenGl Point Functions 15
  • 16. • In this example, three equally spaced points are plotted along a two dimensional, straight-line path, where coordinates are given as integer pairs: glBegin (GL_POINTS); glVertex2i (50, 100); glVertex2i (75, 150); glVertex2i (100, 200); glEnd ( ); OpenGl Point Functions 16
  • 18. • Alternatively, we could use the coordinate values for the preceding points in arrays as: int point1 [ ] = {50, 100}; int point2 [ ] = {75, 150}; int point3 [ ] = {100, 200}; • and call the OpenGL functions for plotting the three points as glBegin (GL_POINTS); glVertex2iv (point1); glVertex2iv (point2); glVertex2iv (point3); glEnd ( ); OpenGl Point Functions 18
  • 19. • Graphic packages normally provide a function for specifying one or more straight-line segments, where each line segment is defined by two endpoint coordinate positions. • For example, if we have five coordinate positions, labelled p1 through p5, and each position is represented by a two-dimensional array, then the following code could create the display shown in Figure 4(a): glBegin (GL_LINES); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glEnd ( ); OpenGl Line Functions 19
  • 21. • Using the OpenGL primitive constant GL_LINE_STRIP, we obtain a polyline. • Using the same five coordinate positions as in the previous example, we obtain the display in Figure 4(b) with the code glBegin (GL_LINE_STRIP); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glEnd ( ); OpenGl Line Functions 21
  • 22. • The third OpenGL line primitive is GL_LINE_LOOP, which produces a closed polyline. • Figure 4(c) shows the display of our endpoint list when we select this line option, using the code glBegin (GL_LINE_LOOP); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glEnd ( ); OpenGl Line Functions 22
  • 23. • Routines for generating basic curves, such as circles and ellipses, are not included as primitive functions in the OpenGL core library. • But this library does contain functions for displaying B´ezier splines, which are polynomials that are defined with a discrete point set. • And the OpenGL Utility (GLU) library has routines for three-dimensional quadrics, such as spheres and cylinders, as well as routines for producing rational B-splines, which are a general class of splines that include the simpler B´ezier curves. OpenGl Curve Functions 23
  • 24. • Using rational B-splines, we can display circles, ellipses, and other two-dimensional quadrics. • In addition, there are routines in the OpenGL Utility Toolkit (GLUT) that we can use to display some three-dimensional quadrics, such as spheres and cones, and some other shapes. • However, all these routines are more involved than the basic primitives we introduce in this chapter. OpenGl Curve Functions 24
  • 26. • Another useful construct, besides points, straight-line segments, and curves, for describing components of a picture is an area that is filled with some solid color or pattern. • A picture component of this type is typically referred to as a fill area or a filled area. Fill-Area Primitives 26
  • 29. • Objects described with a set of polygon surface patches are usually referred to as standard graphics objects, or just graphics objects. Fill-Area Primitives 29
  • 30. • Mathematically defined, a polygon is a plane figure specified by a set of three or more coordinate positions, called vertices, that are connected in sequence by straight-line segments, called the edges or sides of the polygon. • Examples of polygons include triangles, rectangles, octagons, and decagons. Polygon Fill Areas 30
  • 31. • Sometimes, any plane figure with a closed- polyline boundary is alluded to as a polygon, and one with no crossing edges is referred to as a standard polygon or a simple polygon. • In an effort to avoid ambiguous object references, we will use the term polygon to refer only to those planar shapes that have a closed-polyline boundary and no edge crossings. Polygon Fill Areas 31
  • 32. • With one exception, the OpenGL procedures for specifying fill polygons are similar to those for describing a point or a polyline. • A glVertex function is used to input the coordinates for a single polygon vertex, and a complete polygon is described with a list of vertices placed between a glBegin/glEnd pair. • However, there is one additional function that we can use for displaying a rectangle that has an entirely different format. OpenGL Polygon Fill-Area Functions 32
  • 33. • By default, a polygon interior is displayed in a solid color, determined by the current color settings. • As options, we can fill a polygon with a pattern and we can display polygon edges as line borders around the interior fill. • There are six different symbolic constants that we can use as the argument in the glBegin function to describe polygon fill areas. • These six primitive constants allow us to display a single fill polygon, a set of unconnected fill polygons, or a set of connected fill polygons. OpenGL Polygon Fill-Area Functions 33
  • 34. • In OpenGL, a fill area must be specified as a convex polygon. • Thus, a vertex list for a fill polygon must contain at least three vertices, there can be no crossing edges, and all interior angles for the polygon must be less than 180◦. OpenGL Polygon Fill-Area Functions 34
  • 35. • Because graphics displays often include rectangular fill areas, OpenGL provides a special rectangle function that directly accepts vertex specifications in the xy plane. • In some implementations of OpenGL, the following routine can be more efficient than generating a fill rectangle using glVertex specifications: glRect* (x1, y1, x2, y2); • One corner of this rectangle is at coordinate position (x1, y1), and the opposite corner of the rectangle is at position (x2, y2). • Suffix codes for glRect specify the coordinate data type and whether coordinates are to be expressed as array elements. • These codes are i (for integer), s (for short), f (for float), d (for double), and v (for vector). The rectangle is displayed with edges parallel to the xy coordinate axes. OpenGL Polygon Fill-Area Functions 35
  • 36. • As an example, the following statement defines the square shown in Figure 21: glRecti (200, 100, 50, 250); • If we put the coordinate values for this rectangle into arrays, we can generate the same square with the following code: int vertex1 [ ] = {200, 100}; int vertex2 [ ] = {50, 250}; glRectiv (vertex1, vertex2); OpenGL Polygon Fill-Area Functions 36
  • 37. OpenGL Polygon Fill-Area Functions 37
  • 38. • Each of the other six OpenGL polygon fill primitives is specified with a symbolic constant in the glBegin function, along with a a list of glVertex commands. • With the OpenGL primitive constant GL_POLYGON, we can display a single polygon fill area such as that shown in Figure 22(a). OpenGL Polygon Fill-Area Functions 38
  • 39. OpenGL Polygon Fill-Area Functions 39
  • 40. • For this example, we assume that we have a list of six points, labeled p1 through p6, specifying two- dimensional polygon vertex positions in a counterclockwise ordering. • Each of the points is represented as an array of (x, y) coordinate values: glBegin (GL_POLYGON); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glVertex2iv (p6); glEnd ( ); OpenGL Polygon Fill-Area Functions 40
  • 41. • If we reorder the vertex list and change the primitive constant in the previous code example to GL_TRIANGLES, we obtain the two separated triangle fill areas in Figure 22(b): glBegin (GL_TRIANGLES); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p6); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glEnd ( ); OpenGL Polygon Fill-Area Functions 41
  • 42. • By reordering the vertex list once more and changing the primitive constant to GL_TRIANGLE_STRIP, we can display the set of connected triangles shown in Figure 22(c): glBegin (GL_TRIANGLE_STRIP); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p6); glVertex2iv (p3); glVertex2iv (p5); glVertex2iv (p4); glEnd ( ); OpenGL Polygon Fill-Area Functions 42
  • 43. • Another way to generate a set of connected triangles is to use the “fan” approach illustrated in Figure 22(d), where all triangles share a common vertex. • We obtain this arrangement of triangles using the primitive constant GL_TRIANGLE_FAN and the original ordering of our six vertices: glBegin (GL_TRIANGLE_FAN); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glVertex2iv (p6); glEnd ( ); OpenGL Polygon Fill-Area Functions 43
  • 44. • Besides the primitive functions for triangles and a general polygon, OpenGL provides for the specifications of two types of quadrilaterals (four-sided polygons). OpenGL Polygon Fill-Area Functions 44
  • 45. OpenGL Polygon Fill-Area Functions 45
  • 46. • With the GL_QUADS primitive constant and the following list of eight vertices, specified as two- dimensional coordinate arrays, we can generate the display shown in Figure 23(a): glBegin (GL_QUADS); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glVertex2iv (p6); glVertex2iv (p7); glVertex2iv (p8); glEnd ( ); OpenGL Polygon Fill-Area Functions 46
  • 47. • Rearranging the vertex list in the previous quadrilateral code example and changing the primitive constant to GL_QUAD_STRIP, we can obtain the set of connected quadrilaterals shown in Figure 23(b): glBegin (GL_QUAD_STRIP); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p4); glVertex2iv (p3); glVertex2iv (p5); glVertex2iv (p6); glVertex2iv (p8); glVertex2iv (p7); glEnd ( ); OpenGL Polygon Fill-Area Functions 47

Editor's Notes

  1. Conic = المخروط
  2. Polyline = شكل متعدد الخطوط
  3. Cones = مخاريط
  4. Figure 7 shows the side and top surfaces of a metal cylinder approximated in an outline form as a polygon mesh. Displays of such figures can be generated quickly as wire-frame views, showing only the polygon edges to give a general indication of the surface structure.
  5. Octagons = مثمن الزوايا والأضلاع Decagons = شكل ذو عشرة زوايا
  6. Alluded = Indicate
  7. When a rectangle is generated with function glRect, the polygon edges are formed between the vertices in the order (x1, y1), (x2, y1), (x2, y2), (x1, y2), and then back to (x1, y1). Thus, in our example, we produced a vertex list with a clockwise ordering.
  8. Nothing is displayed if we do not list at least three vertices; and if the number of vertices specified is not a multiple of 3, the final one or two vertex positions are not used.