Assignment 4 - User Input
Due Date: Thursday February 8th, 11:59PM
Questions? Check out the Assignment 4 FAQ and discussion page.
In this assignment you'll use a gamepad or joystick as input and create a simple user interface. You'll have to implement a small set of fixed functionality, but the rest of the assignment leaves it up to you to come up with creative ways to use the input devices.
Steps
Download and build the starter code
Begin by downloading the Assigment 4 starter code and latest version of the libST source here. Note that you must use the new version of libST, it has been updated since the previous assignment.
- Build libST. Building libST should require the same steps on your development system as it did in previous assignments. A number of changes have been made to the code which are significant for this assignment. See the descriptions below for the full details of the changes, which you should look over and understand at a high level.
Build the assignment 4 starter code. The subdirectory /assignment4 contains the starting code for your project. This directory should contain the C++ source file control.cpp. You will provide us your modified version of control.cpp as part of this assignment's handin. The directory also contains a sample texture.
Understanding Changes to libST
There have been some significant changes to libST for this assignment. Make sure you understand these changes before continuing as they'll be helpful and/or necessary to complete the assignment.
STTransform is now represented as a 4x4 matrix, making it much more flexible. It also provides a multiplication operator so transformations can be easily composed. It still provides the convenience functions to generate simple rotations, translations, and scales. If needed you could easily add other transformations, such as shear.
STTexture is a new class which uses an STImage as the source for an OpenGL texture. Note that if you're using an older GL your textures can only use images that are powers of two in width and height.
STShape's can now be assigned an STTexture to be used when drawing, and will do so if texture coordinates have been assigned.
Finally, and most important to this assignment, is the STJoystick class. It provides a platform independent interface for accessing joysticks and gamepads. The platform independent parts are in STJoystick.{h,cpp}. Platform dependent parts are in STJoystick_<platform>.cpp. The joystick interface requires that you do a one time initialization before using any joysticks and a final destruction when you're done using the joysticks. These are performed using the static members STJoystick::Initialize and STJoystick::Destroy. Once initialized, still without accessing any joysticks, you can find out how many (STJoystick::NumJoysticks) joysticks are attached and their names (STJoystick::GetName). To open a joystick, use STJoystick::OpenJoystick. This is a static function and returns an STJoystick object ready for use. Note that you never create an STJoystick object yourself, you can only get one using OpenJoystick. Joysticks work by polling, so before reading their state you need to call STJoystick::Update. The methods to access state are self explanatory. Finally, when you are done with a joystick you should make sure its destructor is called to release the related data.
Briefly read through the implementation of the STJoystick class to familiarize yourself with its implementation. However, its not necessary to understand all the detail, i.e. you don't need to understand all the low level workings of the platform specific code.
Understand the Types of Joystick Input
- Axes
- D-pad
- Buttons
- Balls
Answer These Questions
(Please include answers to the following with your handin)
Guidelines
Hints for Getting Started
- (note about d-pad weirdness on linux)
Grading
Submission Instructions
We would like submission to be in the form of a single .zip archive. This archive should contain your modified version of control.cpp, and a text file containing answers to assignment questions. Make sure you let us know if you implemented any additional features on the assignment, we'd certainly like to see. We imagine you could choose to become extremely creative on this assignment.
Please email this zip file to cs148-win0607-staff@lists.stanford.edu before the deadline. Please make the subject line of this email "CS148 Assignment 4 Handin".