Presentation is loading. Please wait.

Presentation is loading. Please wait.

Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.104.1.

Similar presentations


Presentation on theme: "Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.104.1."— Presentation transcript:

1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.104.1

2 Mengenalkan basic input devices Physical Devices Logical Devices Input Modes Event-driven input : Input berbasis event Introduce double buffering for smooth animations Programming event input with GLUT Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.204.2

3 Karaketristik komputer grafik interaktif -Ivan Sutherland (MIT 1963) : User melihat object pada display User menunjuk (picks) object dengan input device (light pen, mouse, trackball) Perubahan object (moves, rotates, morphs) Repeat 04.304.3 Change Image React to Change Graphics SystemUser Input Device Display

4 Alat input dapat dibedakan bdsk Physical properties Mouse Keyboard Trackball Logical Properties What is returned to program via API A position An object identifier Modes How and when input is obtained request event Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.404.4

5 04.504.5 mousetrackball light pen data tablet joy stick space ball

6 Alat input menyerupai pena yang memancarkan sinar untuk dituliskan langsung pada layar monitor atau pada bidang datar yang khusus Light pen memiliki sensor yang dapat mengirimkan sinyal cahaya yang kemudian direkam dan dihubungkan dengan kabel ke komputer untuk diintrepretasikan Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.604.6

7 Berfungsi seperti mouse tapi penggunaannya dengan memutar bola Punya tombol left & right click Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.704.7

8 Jika Trackball biasa digunakan pada aplikasi 2 dimensi, maka Spaceball digunakan pada aplikasi 3 dimensi, virtual reality dan pemodelan Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.804.8

9 Suriyong L., Computer Multimedia9 IBM spaceball

10 Cursor Positioning Alat input seperti tablet akan memberikan data input berupa current position ke komputer Sedangkat alat input berupa mouse, trackball, and joy stick akan memberikan incremental inputs (or velocities) ke komputer Pada incremental device (ex:mouse), inputannya berupa : Position: almost relative value, absolute value is rarely used Velocity: small deviation, small change, large deviation, large change Relative positioning, used by measure moving of the mouse 0 4. 1010

11 Input dari sudut pandang logika program Perhatikan C dan C++ code berikut C++: cin >> x; C: scanf (%d, &x); Apa alat inputnya? Cant tell from the code Could be keyboard, file, output from another program The code provides logical input Suatu data input dikembalikan ke program tanpa mempedulikan alat input fisiknya berupa apa Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 1111

12 Figures from Angle's textbook12 Physical Device Application Program Software Driver Logical Device Mouse, Keyboard Trackball, etc.

13 Pada API sebelum Open GL, yaitu GKS dan PHIGS, didefinisikan enam tipe logical input Locator: return a position in coordinat system Pick: return ID of an object Keyboard: return strings of characters Stroke: return array of positions Valuator: analog input (ex: slidebar), return floating point number Choice: return one of n items (ex: radio button) Programmer's Hierarchical Interactive Graphics System (PHIGS) : the 1990s API standards for 3D graphics Graphical Kernel System (GKS) – API standards for 2D graphics Input untuk grafis lebih bervariasi daripada input pada program biasa (umumnya berupa numbers, characters, or bits) Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 1313

14 Input devices menggunakan trigger untuk mengirim sinyal ke OS Button on mouse Pressing or releasing a key When triggered, input devices return information (their measure) to the system Mouse returns position information Keyboard returns ASCII code Ex: keyboard: Measure : string Trigger : when press enter or return Mouse: Measure : screen position Trigger : when press button Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 1414

15 Suriyong L., Computer Multimedia15 Request mode Event-mode model Sample mode Input Mode Logical input devices can be operated in three modes: Request, Sample, and Event

16 Suriyong L., Computer Multimedia16 Sample mode: Measured data return immediately, no trigger required For example the current cursor position, without waiting for a trigger Sample mode

17 Input provided to program only when user triggers the device ex. scanf : Collect measure, waiting for trigger Typical of keyboard input Can erase (backspace), edit, correct until key (the trigger) is depressed Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 1717

18 Pada event mode, aplikasi dapat mengaktifkan beberapa input device secara simultan Ex. Flight simulator -> joystick, dial, buttons and switches, we do not know which one the pilot will use Setiap trigger menghasilkan event dimana measure akan ditempatkan padaevent queue untuk kemudian diperiksa oleh program Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 1818

19 Window: resize, expose, iconify Mouse: click one or more buttons Motion: move mouse Keyboard: press or release a key Idle: nonevent Define what should be done if no other event is in queue Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 1919

20 Setiap program GLUT pada main.c selalu diakhiri dengan glutMainLoop(); untuk menempatkan program pada infinite event loop Untuk setiap looping, GLUT : Memeriksa event queue Untuk setiap event pada queue, GLUT mengeksekusi fungsi callback jika fungsi tsb sudah didefinisikan sebelumnya Jika definisi fungsi callback belum didefinisikan maka event tsb diabaikan Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 2020

21 Suriyong L., Computer Multimedia21 glutMainLoop(); /* an event loop function */ GLUT Callback Function glutDisplayFunc glutMouseFunc glutReshapeFunc glutKeyboardFunc glutIdleFunc

22 22 Event in Queue Pop Event From Queue Call Function n Switch on Event Type Call Function n Call Function n Call Idle Function No Yes Call Function n Call Function n Calls Function n

23 Suriyong L., Computer Multimedia23 void mouse(int button, int state, int x, int y) { if(button==GLUT_LEFT_BUTTON && state == GLUT_DOWN) exit(); } int main(int argc, char **argv) { glutInit(&argc, argv) glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow(square); myinit(); glutReshapeFunc(myReshape); glutMouseFunc(mouse); glutDisplayFunc(display); glutMainLoop(); } Mouse Callback

24 24 GLUT_LEFT_BUTTON GLUT_MIDDLE_BUTTON GLUT_RIGHT_BUTTON GLUT_UP GLUT_DOWN

25 Suriyong L., Computer Multimedia25 Glut provide pop-up menu, can use with mouse use: glutCreateMenu(); // create menu glutAddEntryMenu(); // add the menu entry Menu which has sub menu

26 Suriyong L., Computer Multimedia26

27 Suriyong L., Computer Multimedia27 Window events when Redraw, resize Aspect ratio Attribute of new primitive Use glutReshapeFunc(reshape_function);

28 Suriyong L., Computer Multimedia28 When key pressed Use glutKeyboardFunc(keyboad_function); void keyboard_function(unsigned char key, int x, int y) { if(key == q || key ==Q) exit(); }

29 Callback Display Func dieksekusi ketika GLUT memerintahkan window untuk di-refresh When the window is first opened When the window is reshaped When the user program decides it wants to change the display In main.c glutDisplayFunc(mydisplay) identifies the function to be executed Every GLUT program must have a display callback Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 2929

30 Pada animasi, fungsi display perlu dipangil berkali-kali -> tidak efisien We can avoid this problem by instead using glutPostRedisplay(); With this function, for each iteration of the mainloop, your registered display() function is called Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 3030

31 Single buffering objects are always rendered into the same framebuffer, which is always being displayed delay of clearing of and re-drawing into frame-buffer will cause flicker if re-draw takes longer than refresh or refresh and animation not synced Double buffering keep two buffers (front and back) always display front, always render into back* swap front and back when rendering complete

32 Suriyong L., Computer Multimedia32 Former graphic the use single buffer Redraw directly on graphic Flicker may happen especially the animation User need to refresh the display at the display rate (50- 70Hz) The double buffer can resolve One for display (front buffer) One for redraw (back buffer) Both is swappable for smooth graphic Using glutSwapBuffers() at display function Initial display mode set use GLUT_DOUBLE mode set at glutInitDisplayMode(); (see at rotate square double buffers.exe)

33 The idle callback is executed whenever there are no events in the event queue glutIdleFunc(myidle) Useful for animations Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 3333 void myidle() { /* change something */ t += dt glutPostRedisplay(); } Void mydisplay() { glClear(); /* draw something that depends on t */ glutSwapBuffers(); }

34 The form of all GLUT callbacks is fixed void mydisplay() void mymouse(GLint button, GLint state, GLint x, GLint y) Must use globals to pass information to callbacks Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 0 4. 3434 float t; /*global */ void mydisplay() { /* draw something that depends on t }

35 35 glutPassiveMotionFunc glutVisibilityFunc glutEntryFunc glutSpecialFunc glutSpaceballMotionFunc glutSpaceballRotateFunc glutSpaceballButtonFunc glutButtonBoxFunc glutDialsFunc glutTabletMotionFunc glutTabletButtonFunc glutMenuStatusFunc


Download ppt "Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 04.104.1."

Similar presentations


Ads by Google