Semester Project: Air Hockey
Areas of Work Scene Graph and Texture Mapping Physics and Collision Detection Opponent AI Interface Design
Scene Graph: Overall Structure
Texture Mapping ● Used QT functions to bind texture from file ● Reference the texture index, using glBindTexture, whenever the appropriate faces are drawn
Physics implementation ● Used standard mouse movement detection when left button is held, move player by same amount mouse moves ● X and Y velocity vectors for all objects ● Velocity vectors for human player equal to movement during last time step ● Velocity vectors for computer player are adjusted based on puck position and movement
Collision Detection ● Check the Euclidean distance between players and puck to detect player collisions ● Check the position of the puck in order to detect wall collisions ● No position interpolation between time steps, so it is possible to move so quickly as to pass completely through and object
New Velocity Vectors After Collision ● Wall Collisions – Simply negate the X or Y velocity vector, depending on whether we hit a horizontal or vertical wall ● Player Collisions – First, find the impact angle by calculating θ = arctan( ) – Then find the new direction by taking the sin and cos of θ – Then find the new magnitude by averaging the speeds of the puck and the impacted player
Opponent AI ● Consists of a set of simple conditional statements. ● These check the current position of the puck, and the puck's current velocity vectors, and adjust the velocity vectors of the opponent player accordingly
Interface Design
QMainWindow
Interface Design Use of Signals and Slots: ● Used the clicked() signal on Push buttons to trigger the respective slots i.e., Start, Pause, and Quit. ● Created Signals pcScoreChanged(int) and playerScoreChanged(int) to update the player and computer scores. These signals were handled by the display(int) slot.
Interface Design ● Qt classes Used: ● QMainWindow ● QWidget ● QGLWidget ● QScrollArea ● QLCDNumber ● QLabel ● QPushButton ● QGridLayout ● Credit: The Qt 4 examples and demos were a good source of information on how we could use the various Qt classes to develop an effective GUI.