Spiegazioni
dell'esercitazione del 2 Novembre 2004
Scopo dell’esercitazione: scopo dell’esercitazione è di
prendere confidenza con i principali meccanismi di interazione
ed animazione di OpenGL e di GLUT attraverso la
modifica e completamento di un semplice programma che visualizza un cubo ed una
sfera. Nota bene: Tutte le operazioni di disegno e di modifica delle
matrici devono (preferibilmente) essere effettuate nella
Display Function, chiamata disegna nel nostro caso. Nelle altre
funzioni, dovete soltanto cambiare i valori dei parametri che vengono usati dalla Display Function.
Cose da
fare:
1)
Su risorse del Computer selezionare Tools à Map Network
Drive. Selezionate il Drive S ed inserite il Folder \\SAMBADMN\PUBLIC
2)
Spostatevi nel Folder Corsi\InfoGrafica\2004-11-02
3)
Create nella vostra Home Directory (selezionabile dal desktop) una
directory per l’esercitazione
4)
Copiate in questa directory sul vostro computer il file cuboInterattivo.c e Spiegazioni.doc (questo file)
5)
Avviate Visual C++ ed aprite la vostra copia del file cuboInterattivo.c
6)
Compilate il file. Vi verrà chiesto di creare un
default workspace. Rispondete di si.
7)
Se non ci sono errori, mandate in esecuzione il programma.
8)
Aprite il codice e cercate di capirne il funzionamento.
9)
Introducete le seguenti modifiche in ordine:
a. Provate ad inserire istruzioni
nella DisplayFunc (disegna) e nella MouseFunc (topo) in modo da far ruotare la scena intorno
all’asse z ogni volta che viene premuto il tasto
destro del mouse.
b. Provate ad inserire istruzioni
nella DisplayFunc (disegna) e nella MouseFunc (topo) in modo da far ruotare la scena intorno
all’asse x ogni volta che il mouse viene trascinato,
con il bottone sinistro premuto, in alto (ruota in senso antiorario) od in
basso (ruota in senso orario).
c. Aggiungere un’animazione che
ruota tutta la scena intorno all’asse y usando
7.5 glutMouseFunc
glutMouseFunc sets the mouse callback
for the current window.
Usage
void glutMouseFunc(void
(*func)(int button, int state, int x, int y));
func The new mouse callback
function.
Description
glutMouseFunc sets the mouse callback for
the current window. When a user presses and releases mouse buttons in
the window, each press and each release generates a mouse callback.
The button parameter is one of
GLUT LEFT BUTTON, GLUT MIDDLE BUTTON, or GLUT RIGHT BUTTON. For systems with only two mouse
buttons, it may not be possible to generate GLUT MIDDLE BUTTON callback. For systems with
a single mouse button, it may be possible to generate only a GLUT LEFT BUTTON callback. The state parameter is either GLUT UP or GLUT DOWN indicatingwhether the callback was due to a release or press respectively. The x and y callback parameters indicate the
window relative coordinates when the mouse button state changed. If a GLUT DOWN callback for a specific
button is triggered, the program can assume a GLUT UP callback for the same buttonwill be generated (assuming the window still has a
mouse callback registered) when the mouse button is
released even if the mouse has moved outside the window. If a menu is attached
to a button for a window, mouse callbacks will not be
generated for that button. During a mouse callback, glutGetModifiers may be called to determine the state of
modifier keys when the mouse event generating the callback
occurred. Passing NULL to glutMouseFunc disables the generation of mouse callbacks.