120 likes | 138 Views
Learn about coordinate systems, mapping, viewport and window coordinates, OpenGL matrices, and usability design guidelines in computer graphics. Includes practical examples and activities for hands-on learning.
E N D
Coordinate Systems (3.1-3.2) • Device coordinates, or screen coordinates (pixels) • put limitations on programmers and the code is not portable • generally expressed in integers • World coordinates • an effort was made to hide the actual device coordinates from the programmer and allow ANY coordinate to be used • generally expressed in floats • programmer defines world space • Mapping • the mathematical transformation from one coordinate system to another • involves relatively simple algebra • See page 85 for one option
Mapping • Convert from world coordinates to viewport coordinates • Proportional along the x-axis and y-axis • Values needed • Window left, right, bottom, top • Viewport left, right, bottom, top • Sx = VL + ((Wx - WL)/Wr - WL) * Vr - VL) • Sy = Vb + ((Wy - Wt)/Wt - Wb) * (Vt - Vb) • Example • Device coordinates of 640 x 480 • World coordinates of 5000 x 4000 • Map (2500, 2000) to ___________ • Map (1000, 1000) to ___________
Viewing • Viewing rectangle or window • items within the window will be seen and others will be clipped • 3D Viewing Volume • glOrtho(left,right,bottom,top,near,far) • Be aware of right handed coordinate system • positive Z comes out from screen • Viewport • a rectangular region within the window • glViewport(x,y,width,height) • Aspect Ratio • the ratio of the viewing rectangle should be the same as the viewport
Mapping in OpenGL • Primitives are multiplied by matrices before being displayed. • OpenGL has two important matrices • MODELVIEW - for viewing parameters • PROJECTION - for display parameters • Typical initialization • glMatrixMode(GL_PROJECTION); • glLoadIdentity(); • glOrtho(left, right, bottom, top); • glViewport (left, bottom, width, height); • glMatrixMode(GL_MODELVIEW); • Leave in MODELVIEW mode • OpenGL handles the mapping and clipping of points • Demo • viewport.c
Animation 3.2 • repeatedly draw images to create the illusion of motion • this may cause flicker though • solution is double buffering • draw images in the back buffer • display images in the front buffer • swap when ready to display • glutSwapBuffers(); • Let OpenGL know • glutInitDisplay (GLUT_DOUBLE | GLUT_RGB); • Demo • single_double.c • Zooming and Panning • Adjust window coordinates as needed for different effects
Canvas class (3.4) • Author’s class to support to 2D rendering • My version is available at • ~grissom/367/Canvas.c • Must create a global variable • Canvas cvs (640, 480, “title); • Instance Variables • CP - current position (x, y) • CD - current direction (angle) • Methods • setWindow (left, right, bottom, top) • setViewport (left, right, bottom, top) • clearScreen ( ) • setBackgroundColor(r, g, b) • setColor (r, g, b) • moveTo (x, y) • lineTo (x, y)
Relative Drawing (3.5) • Methods • moveRel (x, y) • lineRel (x, y) • Group Activity • draw stairs
Turtle Graphics (3.5) • Methods • turnTo (angle) • turn (angle) • forward (dist, isVisible) • Angles • positive rotation is CCW • starts a degree zero on X-axis • human uses degrees • computer uses radians (2 π) • Group Activity • draw a star
Polygons • Calculate the points based on angle • Convert degrees to radians • formula? • x = radius * cos(angle) + center.x • y = radius * sin(angle) + center.y • Group Activity • draw a hexagon
Input Devices • Physical devices • Pointing devices - Mouse, ligth pen, microphone, trackball, joystick • Keyboard device - keyboard • 3D input - laser scanners, VR helmets, data gloves • Logical devices • not related to a specific physical device • device independent just like cout statements • String - sequence of ASCII characters • Locator - returns XY position • Pick - returns ID of a selected object • Choice - one of a limited number of options (menu) • Dial - valuator, returns analog values (slidebars) • Stroke - a series of points or vectors
Usability Design Guidelines • Usability Engineering • Objectives • Reduce errors • Improve performance • Ease of use • Attractive • Examples • Nothing is every as easy to use as the designer thinks it is • EDIT (select everything, delte, insert T) • Delete everything or cancel this request? • YES or NO • Remove the diskette from the protective cover • Press any key to continue • Usability Testing is a must • Watch typical users • It can be frustrating
Usability Measures • Number of errors • Performance time • User satisfaction • Ability to customize