Animated Chess Set
By Luke Gnos
Project Description
My final project for CPE 471 was to create an interactive chess set model,
where the pieces animate when a move is made. The user can select a piece and move it to any
other location on the board (So it is up to the user to make legal chess moves, the program does
no checking in this regard). A transparent block signifies the currently highlighted square, which
the users controls in order to make piece selections. The highlight selection commands also swap once
the camera has rotated to the other side, so the controls are applicable to both white and black sides.
Once a piece is selected, the user then highlights another block (selecting the same block twice will do
nothing) and after pressing the enter key, the selected piece moves to its destination.
Taken pieces appear on their respective side of the board and are replaced when the board is reset.
Project Controls
- Change Light Colors
- --> White
- --> Red
- --> Green
- --> Blue
- Camera Controls
- Q - Move camera to behind black's side of the board
- E - Move camera to behind white's side of the board
- W - Move down to board plane (keeps look at point at origin)
- S - Move away from board plane
- A - Rotate camera left
- D - Rotate camera right
- Game Controls
- Arrow Keys - Move currently highlighted board square
- Enter - Select currently highlighted square / Move selected piece to destination
- R - Reset camera and board state
- Esc - Close window / exit
Project Implementation
The implementation of the project focused on three main aspects, managing user input, heirarchical
modeling and animation, and controlling a variety of models differently.
- Managing the user input to move models or the camera proved to be the easiest of the three to
implement. Basically it involved checking the key and action variables set by a key_callback signal, and
then performing the desired command. The camera for the scene was set to have a fixed look at point that
was the center of the board. As such, all camera rotations were centered around this point with a fixed
radius. This was accomplished by constraining the X-Z coordinates of the camera to move along the circle
defined by the radius and some angle. The "zoom" effect was accomplished by moving the camera forwards or
backwards along the the camera frame's 'W'-axis, which when combined with the fixed look-at-point, resulted
in the camera approaching or going away from the board's plane. Lastly the user input on selecting a piece and
its destination was accomplished through a series of if-statements to determine the current status of the
board. The logic for this system is flipped when the camera's angle is calculated via cos to be on one half
of the board or the other.
- Each of 9 different pieces were modeled through one or two layers of heirachical modeling,
allowing an easy way to move each model. The hierachical modeling for this project was rather simple in
nature as each of the piece models only consisted of 4 or 5 different shape components (all spheres and
cubes in this case). The movement of the pieces was modified at the highest heirachical layer in order to
translate the entire object, while the individual piece animations were mostly done at lower levels to move
or rotate certain components.
- The most difficult aspect of the project was designing the program to allow the user to control any
given piece model in the same way. This was accomplished by setting up two structs. The first was to manage each square
of the board, keeping track of its location, whether or not it was occupied by a piece, and a pointer to
the piece if it was. The other was to define a piece, which incorporated its world coordinates, its color (or
material), a boolean for whether it is currently moving or not, and lastly a function pointer. The function
pointer was then initialized to point to the piece's respective model construction function. This allowed me
to greatly simplify the process for rendering all the pieces by not having to check the piece's type. Instead I
just check if the piece is moving (updating its world location as necessary), and otherwise just call its draw
function, whatever model that may be. The cell structure came in handy for managing the board itself, allowing for a
simple way to keep track of each piece's location on the board.
Project Screenshots
Default camera rotation and highlight position when the program is run
A few pieces moved, and the highlight system showing a selected piece and destination
Pieces taken are moved off to their respective side
King being animated while moving across the board
Board reset, camera zoomed in and rotated
Camera set to behind white instead of black