521493S Computer Graphics General Info & Exercise 1
General Exercise Info • Teaching Assistant Jukka Holappa – Room TS 322, jukka.holappa@ee.oulu.fi – You can try to reach me between 10-16 (Mon-Fri) – Responsible for exercises only! – 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!
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 . Show that you require only the endpoints to determine whether the line segment is not clipped, is partially visible, or is clipped out completely.
Solution 1.1 (1/4)
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
Solution 1.1 (3/4)
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 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
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 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.
Solution 1.2 (1/4)
Solution 1.2 (2/4) • Again, we can use the parametric form of a line segment where and . where and . • We can clip the line against individual sides of the right parallelepiped by finding the points where line intersects each side.
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
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.
Why clipping is important? • OpenGL will do the right thing because it does its own clipping for all the primitives. • You can significantly improve the performance by doing the clipping by yourself at higher by doing the clipping 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 clipping complex objects
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 the two rectangles are defined by OpenGL function calls. function calls. glViewport(u, v, w, h); gluOrtho2D(x_min, x_max, y_min, y_max); Find the mathematical equations that map into .
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.
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.
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 • We must maintain proportions, so that is in the same relative position in the viewport as is in the window, hence
Solution 1.3 (4/4) • Solving previous equation • Similarly for Similarly for
Question 1.4 Devise a test for convexity of two-dimensional polygon.
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.
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 the point into the equation for each of the lines , we should always get the same sign.
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 correct direction (left) when proceeding counter-clockwise. One still has to watch out for complex polygons!
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. problems exist for inverting the mapping? i.e. Trying to map screen coordinates to world coordinates.
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 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.
Question 1.6 Program is using GLUT window to draw OpenGL graphics. Window size is 400 x 300 pixels. An orthogonal 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 mouse. Each circle is defined as a triplet where and where and are 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.
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 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.
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 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.
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 of circle
Solution 1.6 (4/4)
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 the best time to flip the buffers to minimize any visual problems caused by the screen update? Why?
Solution 1.7 (1/2) Simulated screen tearing (By Vanessaezekowitz Creative Commons Attribution-Share Alike 3.0 Unported)
Recommend
More recommend