Coordinate Systems (3.1-3.2)
-
Upload
kelsie-sharp -
Category
Documents
-
view
24 -
download
0
description
Transcript of Coordinate Systems (3.1-3.2)
Chap 3 More Tools page 1CS 367
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 coordinatesan 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
• Mappingthe mathematical transformation from one coordinate system to
another
involves relatively simple algebra
See page 85 for one option
Chap 3 More Tools page 2CS 367
Mapping
• Convert from world coordinates to viewport coordinates
• Proportional along the x-axis and y-axis
• Values neededWindow 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)
• ExampleDevice coordinates of 640 x 480
World coordinates of 5000 x 4000
Map (2500, 2000) to ___________
Map (1000, 1000) to ___________
Chap 3 More Tools page 3CS 367
Viewing
• Viewing rectangle or windowitems within the window will be seen and others will be clipped
• 3D Viewing VolumeglOrtho(left,right,bottom,top,near,far)
• Be aware of right handed coordinate systempositive Z comes out from screen
• Viewporta rectangular region within the window
glViewport(x,y,width,height)
• Aspect Ratiothe ratio of the viewing rectangle should be the same as the viewport
Chap 3 More Tools page 4CS 367
Mapping in OpenGL
• Primitives are multiplied by matrices before being displayed.
• OpenGL has two important matricesMODELVIEW - for viewing parameters
PROJECTION - for display parameters
• Typical initializationglMatrixMode(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
• Demoviewport.c
Chap 3 More Tools page 5CS 367
Animation 3.2
• repeatedly draw images to create the illusion of motion
• this may cause flicker though
• solution is double bufferingdraw images in the back buffer
display images in the front buffer
• swap when ready to displayglutSwapBuffers();
• Let OpenGL knowglutInitDisplay (GLUT_DOUBLE | GLUT_RGB);
• Demosingle_double.c
• Zooming and PanningAdjust window coordinates as needed for different effects
Chap 3 More Tools page 6CS 367
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 variableCanvas cvs (640, 480, “title);
• Instance VariablesCP - current position (x, y)
CD - current direction (angle)
• MethodssetWindow (left, right, bottom, top)
setViewport (left, right, bottom, top)
clearScreen ( )
setBackgroundColor(r, g, b)
setColor (r, g, b)
moveTo (x, y)
lineTo (x, y)
Chap 3 More Tools page 7CS 367
Relative Drawing (3.5)
• MethodsmoveRel (x, y)
lineRel (x, y)
• Group Activitydraw stairs
Chap 3 More Tools page 8CS 367
Turtle Graphics (3.5)
• MethodsturnTo (angle)
turn (angle)
forward (dist, isVisible)
• Anglespositive rotation is CCW
starts a degree zero on X-axis
human uses degrees
computer uses radians (2 π)
• Group Activitydraw a star
Chap 3 More Tools page 9CS 367
Polygons
• Calculate the points based on angle
• Convert degrees to radiansformula?
• x = radius * cos(angle) + center.x
• y = radius * sin(angle) + center.y
• Group Activitydraw a hexagon
Chap 3 More Tools page 10CS 367
Input Devices
• Physical devicesPointing devices - Mouse, ligth pen, microphone, trackball, joystick
Keyboard device - keyboard
3D input - laser scanners, VR helmets, data gloves
• Logical devicesnot 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
Chap 3 More Tools page 11CS 367
Usability Design Guidelines
• Usability Engineering
• ObjectivesReduce errors
Improve performance
Ease of use
Attractive
• ExamplesNothing 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 mustWatch typical users
It can be frustrating
Chap 3 More Tools page 12CS 367
Usability Measures
• Number of errors
• Performance time
• User satisfaction
• Ability to customize