521493s computer graphics
play

521493S Computer Graphics General Info & Exercise 1 + Blender - PowerPoint PPT Presentation

521493S Computer Graphics General Info & Exercise 1 + Blender Tutorial General Exercise Info Teaching Assistant Jukka Holappa Room TS 322, jukka.holappa@ee.oulu.fi You can try to reach me between 12-16 (Mon-Fri) Responsible


  1. 521493S Computer Graphics General Info & Exercise 1 + Blender Tutorial

  2. General Exercise Info • Teaching Assistant Jukka Holappa – Room TS 322, jukka.holappa@ee.oulu.fi – You can try to reach me between 12-16 (Mon-Fri) – Responsible for exercises only! • There are 5 exercises – Usually about one week to figure out the answers – No extra points for completing them on your own – Similar questions may appear in the exam!

  3. Question 1.1 Consider the clipping of a line segment defined by the latter’s two endpoints and with a rectangular window . Show that you require only the endpoints to determine whether the line segment is not clipped, is partially visible, or is clipped out completely.

  4. Solution 1.1 (1/4)

  5. Solution 1.1 (2/4) • Suppose that the line segment is between the points and . • We can create a line using parametric form: • For x-axis, we get • Vertical and horizontal lines need special cases

  6. Solution 1.1 (3/4)

  7. Solution 1.1 (4/4) • We get minimum and maximum unclipped values for parameter t from each dimension. – means unclipped line – means completely clipped out line – Some other range means partially clipped out line • Solutions paper has an alternative approach – Uses ( x , y ) coordinates instead of t – More difficult to use in my opinion

  8. Question 1.2 Clipping can be done independently for each side of the window and can be easily extended to 3-D objects like right parallelepipeds. Explain how you can clip a line segment from to where each side of a right parallelepiped is described as a plane where a , b , c and d are known constants. Hint : Right parallelepiped is like a non-uniformly scaled cube that may have been rotated. Each side of it is a rectangle.

  9. Solution 1.2 (1/4)

  10. Solution 1.2 (2/4) • Again, we can use the parametric form of a line segment where and . • We can clip the line against individual sides of the right parallelepiped by finding the points where line intersects each side.

  11. Solution 1.2 (3/4) • By expanding the line equation we get the equations for each individual component: • Components can be then assigned to plane equation

  12. Solution 1.2 (4/4) • By solving t from we get • Now we can figure out valid range for t as we did in 1.1. – Just clip with all 6 planes that can be derived from side vertices.

  13. Why clipping is important? • OpenGL will do the right thing because it does its own clipping for all the primitives. – Clipped primitive contains only visible part • You can significantly improve the performance by doing culling by yourself at higher level! – By proving that you don’t need to draw 90% of the scene, you might get 10x performance! – For example you can use bounding boxes for culling complex objects – We’ll get back to this with hidden surface removal techniques later on

  14. Question 1.3 A fundamental operation in graphics system is to map a point , which lies within a clipping rectangle, to a point , which lies in the viewport of a window on the screen. Assume that the two rectangles are defined by OpenGL function calls. glViewport(u, v, w, h); gluOrtho2D(x_min, x_max, y_min, y_max); Find the mathematical equations that map into .

  15. Solution 1.3 (1/4) Name glViewport — set the viewport C Specification void glViewport( GLint x, GLint y, GLsizei width, GLsizei height); Parameters x, y Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0). width, height Specify the width and height of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.

  16. Solution 1.3 (2/4) Name gluOrtho2D — define a 2D orthographic projection matrix C Specification void gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top); Parameters left, right Specify the coordinates for the left and right vertical clipping planes. bottom, top Specify the coordinates for the bottom and top horizontal clipping planes.

  17. Solution 1.3 (3/4) • We can solve this problem separately in the and directions. The transformation is linear, that is and . • We must maintain proportions, so that is in the same relative position in the viewport as is in the window, hence

  18. Solution 1.3 (4/4) • Solving previous equation • Similarly for

  19. Question 1.4 Devise a test for convexity of two-dimensional polygon.

  20. Solution 1.4 (1/2) • Consider the lines defined by the sides of the polygon. We can assign a direction for each of these lines by traversing the vertices in a counter-clockwise order.

  21. Solution 1.4 (2/2) • One very simple test is obtained by noting that any point inside the object is on the left of each of these lines. Thus, if we substitute the point into the equation for each of the lines , we should always get the same sign.

  22. Note to 1.4 • If we are checking the next point of the polygon with the line formed by previous two, we can easily verify that we turn into the correct direction (left) when proceeding counter-clockwise. One still has to watch out for complex polygons!

  23. Question 1.5 The mapping from a point in three- dimensional world coordinates to one in screen coordinates is well defined. What problems exist for inverting the mapping? i.e. Trying to map screen coordinates to world coordinates.

  24. Solution 1.5 (1/1) • There is one main problem – Going from three dimensions to two dimensions we lose one dimension. Therefore each point in the screen map to some kind of line (or more complex set of points) in the world coordinates instead of a single point. • Additional problems – Multiple three-dimensional lines may map to the same screen coordinate even when the coordinates are not integers. – There may also be point in the screen that do not map to any valid position in the world coordinates. For example if the whole world is mapped to a rectangle at the center of the screen, inverse mapping will not exist for pixels outside the rectangle at all.

  25. Question 1.6 Program is using GLUT window to draw OpenGL graphics. Window size is 400 x 300 pixels. An orthographic projection of the scene is setup as follows: glViewport(0, 0, 400, 300); gluOrtho2D(0, 400, 0, 300); There are four circles in the scene that user can select with a mouse. Each circle is defined as a triplet where and are the coordinates and is the circle radius. Circles are , , and When user selects his favorite circle, GLUT callback function for mouse pointer position reports that the mouse is at coordinates . What circle (if any) did the user select? Explain your answer.

  26. Solution 1.6 (1/4) • glViewport and gluOrtho2D create an orthographic view of the scene with visible size of 400 x 300. Also the actual window is of the same size so no scaling or stretching happens. • Therefore a circle centered at (100, 100) with radius of 50 is drawn centered as the same OpenGL screen coordinates.

  27. Solution 1.6 (2/4) • However, there is a difference between GLUT coordinates and OpenGL coordinates in the screen. – GLUT passes down coordinates that come from the underlying windowing system as relative coordinates to the window position where the origin is at top left, x-axis grows to the right and y-axis down. – In OpenGL, using presented setup and no additional transformations, the origin is at bottom left with y- axis pointing up.

  28. Solution 1.6 (3/4) • When reported mouse pointer is at (110, 110), the position in the scene is (110, (300-1)-110) that equals (110, 189). This point is in the area of circle

  29. Solution 1.6 (4/4)

  30. Question 1.7 • Double buffering is used to reduce flickering of the screen caused by simultaneously drawing objects while the screen is displayed. What is the best time to flip the buffers to minimize any visual problems caused by the screen update? Why?

  31. Solution 1.7 (1/2) Simulated screen tearing (By Vanessaezekowitz Creative Commons Attribution-Share Alike 3.0 Unported)

  32. Solution 1.7 (2/2) • One should update during vertical retraces. • Suppose that we have a fast computer that can render 300 frames per second. Screen of this computer is physically updated at 60 Hz. – This means that we can render a completely different scene and show it 5 times during one screen update. • This can cause a visual tearing effect as a set of lines come from a different image than ones above it. • Quickly horizontally moving objects have parts of them shown at different positions during the same screen update. • By limiting updates to one per screen refresh and refreshing the screen during vertical retrace period, no visible artifacts can be seen.

  33. Pondering about 1.7 • If screen is updated only once per refresh, what effects will it have for the software?

  34. Pondering about 1.7 • If screen is updated only once per refresh, what effects will it have for the software? • What if we use triple buffering (one front and two back buffers)?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend