PushMatrix / PopMatrix

A transformation is represented mathematically as a matrix.

OpenGL maintains a stack of saved transformation matrices.

glPushMatrix() & glPopMatrix() save and restore transformation state.



Make sure you always have the same number of pushes & pops.

The number of transformations you can save is finite; it is at least 32.






Hierarchical Transformations

Hierarchical transformations can be thought of as transformations that are "attached to" other transformations.

They are used to transform objects relative to other objects.

A common use is in articulated bodies.






Hierarchical Transformations

We can draw this "car" by transforming the two wheels relative to the body of the car.

We'd like each wheel to be affected by the car body's transformation, but not by any other wheel's transformation.






Hierarchical Transformations

This can be accomplished by saving & restoring transformation state.

apply body transformation
draw body
save state
apply front wheel transformation
draw wheel
restore saved state
apply rear wheel transformation
draw wheel





Transformation Hierarchy

Hierarchical transformations are often represented as a tree of transformations.

This is the basis of scene graph systems.






Interaction






Types of Devices






Common Devices






Reading Devices

Polling

Event driven






Feedback

Change in response to users' actions

Lets users know that they're interacting

Immediate, simple response often useful

Can be visual, auditory, haptic






Latency

Delay between an action and its result

Humans very aware of latency > ~ 100 milliseconds

Many delays inherent in different stages of hardware/software
"End-to-end" latency = total delay

Long latency slows up user
Irregular latency even worse


Latency is distinct from update speed






Resolution

Measure of how many distinct values a device can report


On/off switch = 1 bit resolution


"Non-analog" joystick = 3 values (+1, 0, -1) for X and for Y

8 bit resolution joystick = 256 possible values for X and for Y

16 bit resolution joystick = 65536 possible values for X and for Y






Noise

Signal = the information we want to communicate to the computer (e.g. button state, pointer position)

Noise = variations in the signal, outside of our control

Examples:

Applications may need to allow for noise in input data






Fitts' Law

From human movement research - Paul Fitts, 1954

Predicts time needed to move from a starting position to a target - e.g. to point at something

D = distance to target
W = width of target







GLUT Input






GLUT Keyboard Functions

glutKeyboardFunc(func) Called when a 'character' key is hit
glutSpecialFunc(func) Called when a 'special' key is hit
glutKeyboardUpFunc(func) Called when a 'character' key is released
glutSpecialUpFunc(func) Called when a 'special' key is released
glutGetModifiers() Returns state of shift, control, alt keys when event happened
glutIgnoreKeyRepeat(val) Tells GLUT whether to ignore automatic keyboard repeat





GLUT Keyboard Callback

All keyboard callback functions take the form:

    def func(key, x, y):
         ...

key is the key pressed or released - either a single-character string (e.g. 'a'), or a special-key constant (e.g. GLUT_KEY_UP)

x, y is the mouse pointer location when the key event occurred


Note: in Python, the same function can be used for both normal & special keys






glutGetModifiers

glutGetModifiers() returns a bit-mask value
i.e. a combination of flags

Possible flags are GLUT_ACTIVE_SHIFT, GLUT_ACTIVE_CTRL, and GLUT_ACTIVE_ALT

Test a flag with the & operator. e.g.:

    if glutGetModifiers() & GLUT_ACTIVE_CTRL:
        doSomethingForCtrlKey()





GLUT Mouse Functions

glutMouseFunc(func) Called when a mouse button is pressed
glutMotionFunc(func) Called when mouse moves, while button pressed
glutPassiveMotionFunc(func) Called when mouse moves, with no button pressed
glutGetModifiers() Returns state of shift, control, alt keys when event happened





GLUT Mouse Callback

Mouse-button callback functions take the form:

    def func(button, state, x, y):
         ...

button is the button pressed or released - one of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON

state is GLUT_DOWN if the button was pressed, or GLUT_UP if it was released

x, y is the mouse pointer location when the button was pressed or released






GLUT Motion Callback

Mouse-motion callback functions take the form:

    def func(x, y):
         ...

x, y is the new mouse pointer location



Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons License.