SlideShare una empresa de Scribd logo
1 de 35
Drawing and Coordinate Systems
Coordinate Systems






Screen Coordinate system
World Coordinate system
World window
Viewport
Window to viewport mapping
Screen Coordinate System
Glut

OpenGL
(0,0)
Screen Coordinate System
- 2D Regular Cartesian Grid
- Origin (0,0) at lower left
corner (OpenGL convention)
- Horizontal axis – x
Vertical axis – y
- Pixels are defined at the grid
intersections
- This coordinate system is defined
(0,0)
relative to the display window origin
(OpenGL: the lower left corner
of the window)

y

x

(2,2)
World Coordinate System


Screen coordinate system is not easy to
use

10 feet
20 feet
World Coordinate System


Another example:
plot a sinc function:
sinc(x) = sin(PI*x)/PI*x
x = -4 .. +4
World Coordinate System


It would be nice if we can use
application specific coordinates –
world coordinate system
glBegin(GL_LINE_STRIP);
for (x = -4.0; x <4.0; x+=0.1){
Glfloat y = sin(3.14 * x) / (3.14 * x);
glVertex2f (x,y);
}
glEnd();
Define a world window
World Window


World window – a rectangular region in
the world that limits our view
Define by

W_T

W_L, W_R, W_B, W_T

W_B

Use OpenGL command:
W_L

W_R

gluOrtho2D(left, right, bottom,
top)
Viewport




The rectangular region in the screen that
maps to our world window
Defined in the window’s (or control’s)
coordinate system
glViewport(int left, int bottom,
int (right-left),
int (top-bottom));

V_T

V_B
V_L

V_R
To draw in world coordinate system
Two tasks need to be done








Define a rectangular world window
(call an OpenGL function)
Define a viewport (call an OpenGL
function)
Perform window to viewport mapping
(OpenGL internals will do this for you)
A simple example
DrawQuad()
(300,200)
{
glViewport(0,0,300,200);
glMatrixMode(GL_PROJECTION);
glLoadIndentity();
glOrtho2D(-1,1,-1,1);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex2i(-0.5,-0.5);
(0,0)
glVertex2i(+0.5,-0.5);
viewport
glVertex2i(+0.5,+0.5);
glVertex2i(-0.5,+0.5);
How big is the quad?
glEnd();
}
Window to viewport mapping


The objects in the world window will
then be drawn onto the viewport
(x,y)

World window

viewport
(Sx, Sy)
Window to viewport mapping


How to calculate (sx, sy) from (x,y)?

(x,y)
(Sx, Sy)
Window to viewport mapping


First thing to remember – you don’t
need to do it by yourself. OpenGL will
do it for you




You just need to define the viewport (with
glViewport()), and the world window (with
gluOrtho2D())

But we will look ‘under the hood’
Also, one thing to remember …


A practical OpenGL issue


Before calling gluOrtho2D(), you need to
have the following two lines of code –

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(Left, Right, Bottom, Top);
Window to viewport mapping


Things that are given:






The world window (W_L, W_R, W_B, W_T)
The viewport (V_L, V_R, V_B, V_T)
A point (x,y) in the world coordinate system

Calculate the corresponding point (sx,
sy) in the screen coordinate system
Window to viewport mapping


Basic principle: the mapping should be
proportional
(sx,sy)

(x,y)

(x – W_L) / (W_R – W_L)

=

(sx – V_L) / (V_R – V_L)

(y - W_B) / (W_T – W_B)

=

(sy – V_B) / (V_T – V_B)
Window to viewport mapping
(sx,sy)

(x,y)

(x – W_L) / (W_R – W_L)

=

(sx – V_L) / (V_R – V_L)

(y - W_B) / (W_T – W_B)

=

(sy – V_B) / (V_T – V_B)

sx = (x - W_L) * (V_R-V_L)/(W_R-W_L) + V_L
sy = (y - W_B) * (V_T-V_B)/(W_T-W_B) + V_B
Some practical issues





How to set up an appropriate world
window automatically?
How to zoom into the picture?
How to set up an appropriate viewport,
so that the picture is not going to be
distorted?
World window setup


The basic idea is to see all the objects
in the world




This can just be your initial view, and the
user can change it later

How to achieve it?
World window set up


Find the world coordinates extent that will
cover the entire scene (the bounding box )
max Y

min Y
min X

max X
Zoom into the picture
Shrink your world window – call gluOrtho2D() with a new range

Viewport
Non-distorted viewport setup






Distortion happens when …
World window and display window have
different aspect ratios
Aspect ratio?
R=W/H
Fixing the aspect ratio


Method I – Fixed camera view







Limit the viewport to a portion of the
window. (covered next)
Constrain the user’s resizing ability.
Adjust the window (or control) size.

Method II – Adjusting the scale to
compensate for a non-square window.


We will cover this when we look at 3D.
Compare aspect ratios
H

W

World window

Display window

Aspect Ratio = R

Aspect Ratio = W / H

R> W/H
Match aspect ratios
H

R

?
W

World window

Display window

Aspect Ratio = R

Aspect Ratio = W / H

R> W/H
Match aspect ratios
H

R
World window
Aspect Ratio = R

R> W/H

W/R
W

Display window
Aspect Ratio = W / H

glViewport(0, 0, W, W/R)
Compare aspect ratios
H

W

World window

Display window

Aspect Ratio = R

Aspect Ratio = W / H

R< W/H
Match aspect ratios
?
H

W

World window

Display window

Aspect Ratio = R

Aspect Ratio = W / H

R< W/H
Match aspect ratios
H*R
H

World window
Aspect Ratio = R

R< W/H

W
Display window
Aspect Ratio = W / H

glViewport(0, 0, H*R, H)
When to call glViewport() ?





Initialization
When the user resizes the display
window.
New type of camera? 35mm, 70mm, …

Note: Resize event is actually called on
initialization, but your callback may not have
been connected at this time.
Resize event
Void resize(int W, int H)
{
glViewport(0,0,W, H);
}
You can provide your own to make sure the
aspect ratio is fixed.
Put it all together
DrawQuad()
(300,200)
{
glViewport(0,0,300,200);
glMatrixMode(GL_PROJECTION);
glLoadIndentity();
glOrtho2D(-1,1,-1,1);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex2i(-0.5,-0.5);
(0,0)
glVertex2i(+0.5,-0.5);
viewport
glVertex2i(+0.5,+0.5);
glVertex2i(-0.5,+0.5);
How big is the quad?
glEnd();
}
More Viewports


Viewports can also be thought of as clip
windows. This can be useful for:






User interaction
Static camera – small moving object
Limited field-of-view
Occlusion culling
Selection (picking)

Más contenido relacionado

La actualidad más candente

Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer GraphicsSanu Philip
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptxRubaNagarajan
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformationSelvakumar Gna
 
Input of graphical data
Input of graphical dataInput of graphical data
Input of graphical dataRajapriya82
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)Timbal Mayank
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer GraphicsSanu Philip
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithmPooja Dixit
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics systemKamal Acharya
 
COLOR CRT MONITORS IN COMPUTER GRAPHICS
COLOR CRT MONITORS IN COMPUTER GRAPHICSCOLOR CRT MONITORS IN COMPUTER GRAPHICS
COLOR CRT MONITORS IN COMPUTER GRAPHICSnehrurevathy
 
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPTHOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPTAhtesham Ullah khan
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 

La actualidad más candente (20)

Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
 
3D Transformation
3D Transformation 3D Transformation
3D Transformation
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
 
3 d display methods
3 d display methods3 d display methods
3 d display methods
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptx
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
 
Input of graphical data
Input of graphical dataInput of graphical data
Input of graphical data
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithm
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics system
 
Halftoning in Computer Graphics
Halftoning  in Computer GraphicsHalftoning  in Computer Graphics
Halftoning in Computer Graphics
 
COLOR CRT MONITORS IN COMPUTER GRAPHICS
COLOR CRT MONITORS IN COMPUTER GRAPHICSCOLOR CRT MONITORS IN COMPUTER GRAPHICS
COLOR CRT MONITORS IN COMPUTER GRAPHICS
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
 
Three dimensional concepts - Computer Graphics
Three dimensional concepts - Computer GraphicsThree dimensional concepts - Computer Graphics
Three dimensional concepts - Computer Graphics
 
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPTHOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
 
fractals
fractalsfractals
fractals
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 

Similar a computer graphics

3 projection computer graphics
3 projection computer graphics3 projection computer graphics
3 projection computer graphicscairo university
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2Sardar Alam
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Takao Wada
 
Java Graphics
Java GraphicsJava Graphics
Java GraphicsShraddha
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shahSyed Talha
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationMark Kilgard
 
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
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsRup Chowdhury
 
UNIT_3-Two-Dimensional-Geometric-Transformations.pdf
UNIT_3-Two-Dimensional-Geometric-Transformations.pdfUNIT_3-Two-Dimensional-Geometric-Transformations.pdf
UNIT_3-Two-Dimensional-Geometric-Transformations.pdfVivekKumar148171
 
Trytten computergraphics(1)
Trytten computergraphics(1)Trytten computergraphics(1)
Trytten computergraphics(1)nriaz469
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).pptHIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.pptHIMANKMISHRA2
 
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 a computer graphics (20)

Lesson 2 - Drawing Objects
Lesson 2 - Drawing ObjectsLesson 2 - Drawing Objects
Lesson 2 - Drawing Objects
 
3 projection computer graphics
3 projection computer graphics3 projection computer graphics
3 projection computer graphics
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2
 
Lec4
Lec4Lec4
Lec4
 
Bai 1
Bai 1Bai 1
Bai 1
 
Games 3 dl4-example
Games 3 dl4-exampleGames 3 dl4-example
Games 3 dl4-example
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shah
 
Drawing Tools
Drawing ToolsDrawing Tools
Drawing Tools
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
 
Unit 3
Unit 3Unit 3
Unit 3
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer Graphics
 
UNIT_3-Two-Dimensional-Geometric-Transformations.pdf
UNIT_3-Two-Dimensional-Geometric-Transformations.pdfUNIT_3-Two-Dimensional-Geometric-Transformations.pdf
UNIT_3-Two-Dimensional-Geometric-Transformations.pdf
 
Trytten computergraphics(1)
Trytten computergraphics(1)Trytten computergraphics(1)
Trytten computergraphics(1)
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Último (20)

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

computer graphics

  • 2. Coordinate Systems      Screen Coordinate system World Coordinate system World window Viewport Window to viewport mapping
  • 4. Screen Coordinate System - 2D Regular Cartesian Grid - Origin (0,0) at lower left corner (OpenGL convention) - Horizontal axis – x Vertical axis – y - Pixels are defined at the grid intersections - This coordinate system is defined (0,0) relative to the display window origin (OpenGL: the lower left corner of the window) y x (2,2)
  • 5. World Coordinate System  Screen coordinate system is not easy to use 10 feet 20 feet
  • 6. World Coordinate System  Another example: plot a sinc function: sinc(x) = sin(PI*x)/PI*x x = -4 .. +4
  • 7. World Coordinate System  It would be nice if we can use application specific coordinates – world coordinate system glBegin(GL_LINE_STRIP); for (x = -4.0; x <4.0; x+=0.1){ Glfloat y = sin(3.14 * x) / (3.14 * x); glVertex2f (x,y); } glEnd();
  • 8. Define a world window
  • 9. World Window  World window – a rectangular region in the world that limits our view Define by W_T W_L, W_R, W_B, W_T W_B Use OpenGL command: W_L W_R gluOrtho2D(left, right, bottom, top)
  • 10. Viewport   The rectangular region in the screen that maps to our world window Defined in the window’s (or control’s) coordinate system glViewport(int left, int bottom, int (right-left), int (top-bottom)); V_T V_B V_L V_R
  • 11. To draw in world coordinate system Two tasks need to be done     Define a rectangular world window (call an OpenGL function) Define a viewport (call an OpenGL function) Perform window to viewport mapping (OpenGL internals will do this for you)
  • 13. Window to viewport mapping  The objects in the world window will then be drawn onto the viewport (x,y) World window viewport (Sx, Sy)
  • 14. Window to viewport mapping  How to calculate (sx, sy) from (x,y)? (x,y) (Sx, Sy)
  • 15. Window to viewport mapping  First thing to remember – you don’t need to do it by yourself. OpenGL will do it for you   You just need to define the viewport (with glViewport()), and the world window (with gluOrtho2D()) But we will look ‘under the hood’
  • 16. Also, one thing to remember …  A practical OpenGL issue  Before calling gluOrtho2D(), you need to have the following two lines of code – glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(Left, Right, Bottom, Top);
  • 17. Window to viewport mapping  Things that are given:     The world window (W_L, W_R, W_B, W_T) The viewport (V_L, V_R, V_B, V_T) A point (x,y) in the world coordinate system Calculate the corresponding point (sx, sy) in the screen coordinate system
  • 18. Window to viewport mapping  Basic principle: the mapping should be proportional (sx,sy) (x,y) (x – W_L) / (W_R – W_L) = (sx – V_L) / (V_R – V_L) (y - W_B) / (W_T – W_B) = (sy – V_B) / (V_T – V_B)
  • 19. Window to viewport mapping (sx,sy) (x,y) (x – W_L) / (W_R – W_L) = (sx – V_L) / (V_R – V_L) (y - W_B) / (W_T – W_B) = (sy – V_B) / (V_T – V_B) sx = (x - W_L) * (V_R-V_L)/(W_R-W_L) + V_L sy = (y - W_B) * (V_T-V_B)/(W_T-W_B) + V_B
  • 20. Some practical issues    How to set up an appropriate world window automatically? How to zoom into the picture? How to set up an appropriate viewport, so that the picture is not going to be distorted?
  • 21. World window setup  The basic idea is to see all the objects in the world   This can just be your initial view, and the user can change it later How to achieve it?
  • 22. World window set up  Find the world coordinates extent that will cover the entire scene (the bounding box ) max Y min Y min X max X
  • 23. Zoom into the picture Shrink your world window – call gluOrtho2D() with a new range Viewport
  • 24. Non-distorted viewport setup     Distortion happens when … World window and display window have different aspect ratios Aspect ratio? R=W/H
  • 25. Fixing the aspect ratio  Method I – Fixed camera view     Limit the viewport to a portion of the window. (covered next) Constrain the user’s resizing ability. Adjust the window (or control) size. Method II – Adjusting the scale to compensate for a non-square window.  We will cover this when we look at 3D.
  • 26. Compare aspect ratios H W World window Display window Aspect Ratio = R Aspect Ratio = W / H R> W/H
  • 27. Match aspect ratios H R ? W World window Display window Aspect Ratio = R Aspect Ratio = W / H R> W/H
  • 28. Match aspect ratios H R World window Aspect Ratio = R R> W/H W/R W Display window Aspect Ratio = W / H glViewport(0, 0, W, W/R)
  • 29. Compare aspect ratios H W World window Display window Aspect Ratio = R Aspect Ratio = W / H R< W/H
  • 30. Match aspect ratios ? H W World window Display window Aspect Ratio = R Aspect Ratio = W / H R< W/H
  • 31. Match aspect ratios H*R H World window Aspect Ratio = R R< W/H W Display window Aspect Ratio = W / H glViewport(0, 0, H*R, H)
  • 32. When to call glViewport() ?    Initialization When the user resizes the display window. New type of camera? 35mm, 70mm, … Note: Resize event is actually called on initialization, but your callback may not have been connected at this time.
  • 33. Resize event Void resize(int W, int H) { glViewport(0,0,W, H); } You can provide your own to make sure the aspect ratio is fixed.
  • 34. Put it all together DrawQuad() (300,200) { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity(); glOrtho2D(-1,1,-1,1); glBegin(GL_QUADS); glColor3f(1,1,0); glVertex2i(-0.5,-0.5); (0,0) glVertex2i(+0.5,-0.5); viewport glVertex2i(+0.5,+0.5); glVertex2i(-0.5,+0.5); How big is the quad? glEnd(); }
  • 35. More Viewports  Viewports can also be thought of as clip windows. This can be useful for:      User interaction Static camera – small moving object Limited field-of-view Occlusion culling Selection (picking)