Drawing and Coordinate Systems Coordinate Systems n n
- Slides: 35
Drawing and Coordinate Systems
Coordinate Systems n n n World Coordinate system World window Screen Coordinate system Viewport Window to viewport mapping
Screen Coordinate System Glut Open. GL (0, 0)
Screen Coordinate System - 2 D Regular Cartesian Grid - Origin (0, 0) at lower left corner (Open. GL convention) - Horizontal axis – x Vertical axis – y - Pixels are defined at the grid (0, 0) intersections - This coordinate system is defined relative to the display window origin (Open. GL: the lower left corner of the window) y x (2, 2)
World Coordinate System n Application specific – difficult to work directly in screen coordinates 10 feet 20 feet
World Coordinate System n Another example: plot a sinc function: sinc(x) = sin(PI*x)/PI*x x = -4. . +4
World Coordinate System n It would be nice if we can use application specific coordinates – world coordinate system gl. Begin(GL_LINE_STRIP); for (x = -4. 0; x <4. 0; x+=0. 1){ GLfloat y = sin(3. 14 * x) / (3. 14 * x); gl. Vertex 2 f (x, y); } gl. End();
Define a world window
World Window n World window – a rectangular region in the world that is to be displayed W_T Define by W_L, W_R, W_B, W_T W_B Use Open. GL command: W_L W_R glu. Ortho 2 D(left, right, bottom, top)
Viewport n n The rectangular region in the screen for displaying the graphical objects defined in the world window Defined in the screen coordinate system gl. Viewport(int left, int bottom, int (right-left), int (top-bottom)); V_T V_B V_L V_R call this function before drawing (calling gl. Begin() and gl. End() )
To draw in world coordinate system Two tasks need to be done n n Define a rectangular world window (call an Open. GL function) Define a viewport (call an Open. GL function) Perform window to viewport mapping (Open. GL internals will do this for you)
A simple example Draw. Quad() { (300, 200) gl. Viewport(0, 0, 300, 200); gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); glu. Ortho 2 D(-1, 1, -1, 1); gl. Begin(GL_QUADS); gl. Color 3 f(1, 1, 0); gl. Vertex 2 f(-0. 5, -0. 5); (0, 0) gl. Vertex 2 f(+0. 5, -0. 5); viewport gl. Vertex 2 f(+0. 5, +0. 5); gl. Vertex 2 f(-0. 5, +0. 5); How big is the quad? gl. End(); }
Window to viewport mapping n The objects in the world window will then be drawn onto the viewport (x, y) World window viewport (Sx, Sy)
Window to viewport mapping n How to calculate (sx, sy) from (x, y)? (x, y) (Sx, Sy)
Window to viewport mapping n First thing to remember – you don’t need to do it by yourself. Open. GL will do it for you n n You just need to define the viewport (with gl. Viewport()), and the world window (with glu. Ortho 2 D()) But we will look ‘under the hood’
Also, one thing to remember … n A practical Open. GL issue n Before calling glu. Ortho 2 D(), you need to have the following two lines of code – gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); glu. Ortho 2 D(Left, Right, Bottom, Top);
Window to viewport mapping n Things that are given: n n 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 n Basic principle: the mapping should be proportional (sx, sy) (x, y) (x – W_L) / (W_R – W_L) (y - W_B) / (W_T – W_B) = = (sx – V_L) / (V_R – V_L) (sy – V_B) / (V_T – V_B)
Window to viewport mapping (sx, sy) (x, y) (x – W_L) / (W_R – W_L) (y - W_B) / (W_T – W_B) = = (sx – V_L) / (V_R – V_L) (sy – V_B) / (V_T – V_B) sx = x * (V_R-V_L)/(W_R-W_L) - W_L * (V_R – V_L)/(W_R-W_L) + V_L sy = y * (V_T-V_B)/(W_T-W_B) – W_B * (V_T-V_B)/(W_T-W_B) + V_B
Some practical issues n n n How to set up an appropriate world window automatically? How to zoom in the picture? How to set up an appropriate viewport, so that the picture is not going to be distorted?
World window setup n The basic idea is to see all the objects in the world n n This can just be your initial view, and the user can change it later How to achieve it?
World window set up n Find the world coordinates extent that will cover the entire scene max Y min X max X
Zoom into the picture Shrink your world window – call glu. Ortho 2 D() with a new range Viewport
Non-distorted viewport setup n n Distortion happens when … World window and display window have different aspect ratios Aspect ratio? R=W/H
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 gl. Viewport(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 gl. Viewport(0, 0, H*R, H)
When to call gl. Viewport() ? Two places: n Initialization n n Default: same as the window size When the user resizes the display window
Resize (Reshape) window Void main(int argc, char** argv) { … glut. Display. Func(display); glut. Reshape. Func(resize); glut. Keyboard. Func(key); … } void resize () – a function provided by you. It will be called when the window changes size.
Resize (reshape) window Void resize(int W, int H) { gl. Viewport(0, 0, W, H); } This is done by default in GLUT You can use the call to make sure the aspect ratio is fixed that we just discussed.
Put it all together Draw. Quad() { (300, 200) gl. Viewport(0, 0, 300, 200); gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); glu. Ortho 2 D(-1, 1, -1, 1); gl. Begin(GL_QUADS); gl. Color 3 f(1, 1, 0); gl. Vertex 2 f(-0. 5, -0. 5); (0, 0) gl. Vertex 2 f(+0. 5, -0. 5); viewport gl. Vertex 2 f(+0. 5, +0. 5); gl. Vertex 2 f(-0. 5, +0. 5); How big is the quad? gl. End(); }
Well, this works too … main() Open. GL Default: { … gl. Viewport: as large as gl. Begin(GL_QUADS); you display window gl. Color 3 f(1, 1, 0); gl. Vertex 2 f(-0. 5, -0. 5); glu. Ortho 2 D: gl. Vertex 2 f(+0. 5, 0); glu. Ortho 2 D(-1, 1, -1, 1); gl. Vertex 2 f(+0. 5, +0. 5); gl. Vertex 2 f(-0. 5, +0. 5); gl. End(); } Every time you learn a new Open. GL function, always try to know its default Why? arguments
- Pre coordinate indexing and post coordinate indexing
- Coordinate bond in carbon monoxide
- Isometric drawing n2
- Drafting technical drawing
- Area in spherical coordinates
- Rotating coordinate systems
- Isometric 30 60
- Iso standard drawing scales
- Shaft undercut standards
- Technical drawing terms
- Types of isometric view
- Decision support systems and intelligent systems
- Define cyclic co-ordinate
- Ngs coordinate conversion and transformation tool (ncat)
- Module 10 coordinate proof using slope
- Midpoint and distance in the coordinate plane
- 4-8 triangles and coordinate proof answer key
- Unit 3 quadrilaterals and coordinate proof
- How to find missing coordinates of an isosceles triangle
- Dilations and similarity in the coordinate plane
- Subordinate clause kinds
- Dilations and similarity in the coordinate plane
- Coordinate proof using slope and distance
- Difference between covalent and coordinate covalent bond
- Geometry midpoint and distance formula
- 4-8 skills practice triangles and coordinate proof
- Distance and midpoint formula
- 4-8 triangles and coordinate proof
- Perimeter on coordinate plane
- Coordinate adjectives comma
- Midsegment theorem and coordinate proof
- Test for symmetry
- 1-6 midpoint and distance in the coordinate plane
- 4-8 triangles and coordinate proof
- 1-6 midpoint and distance in the coordinate plane
- Midpoint and distance in the coordinate plane worksheet