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

521493s computer graphics
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

521493S Computer Graphics

General Info & Exercise 1 + Blender Tutorial

slide-2
SLIDE 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!

slide-3
SLIDE 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.

slide-4
SLIDE 4

Solution 1.1 (1/4)

slide-5
SLIDE 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
slide-6
SLIDE 6

Solution 1.1 (3/4)

slide-7
SLIDE 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

slide-8
SLIDE 8

Question 1.2

Clipping can be done independently for each side

  • f the window and can be easily extended to 3-D
  • bjects 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.

slide-9
SLIDE 9

Solution 1.2 (1/4)

slide-10
SLIDE 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.

slide-11
SLIDE 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

slide-12
SLIDE 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.

slide-13
SLIDE 13

Why clipping is important?

  • OpenGL will do the right thing because it does its
  • wn 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

slide-14
SLIDE 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 .

slide-15
SLIDE 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.

slide-16
SLIDE 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.

slide-17
SLIDE 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

slide-18
SLIDE 18

Solution 1.3 (4/4)

  • Solving previous equation
  • Similarly for
slide-19
SLIDE 19

Question 1.4

Devise a test for convexity of two-dimensional polygon.

slide-20
SLIDE 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.

slide-21
SLIDE 21

Solution 1.4 (2/2)

  • One very simple test is obtained by noting

that any point inside the object is on the left

  • f 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.

slide-22
SLIDE 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!

slide-23
SLIDE 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.

slide-24
SLIDE 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.

slide-25
SLIDE 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.

slide-26
SLIDE 26

Solution 1.6 (1/4)

  • glViewport and gluOrtho2D create an
  • rthographic 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.

slide-27
SLIDE 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.

slide-28
SLIDE 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

  • f circle
slide-29
SLIDE 29

Solution 1.6 (4/4)

slide-30
SLIDE 30

Question 1.7

  • Double buffering is used to reduce flickering of

the screen caused by simultaneously drawing

  • bjects 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?

slide-31
SLIDE 31

Solution 1.7 (1/2)

(By Vanessaezekowitz Creative Commons Attribution-Share Alike 3.0 Unported)

Simulated screen tearing

slide-32
SLIDE 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.

slide-33
SLIDE 33

Pondering about 1.7

  • If screen is updated only once per refresh,

what effects will it have for the software?

slide-34
SLIDE 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)?