Revision 3 as of 2007-01-31 22:53:02

    Assignment4

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

  1. 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.

  2. 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.
  3. 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 - Analog sticks are called axes by STJoystick. Each analog stick has 2 axes.
  • Hats - also known as direction-pads or d-pads, only offer 9 settings (centered, up, up+left, left, down+left, down, down+right, right, up+right). (Linux doesn't differentiate between hats and axes. Hats will show up as axes but they will only take on the maximum and minimum values.)
  • Buttons - Only have 2 states, pressed and released.
  • Balls - Trackballs, as demonstrated in class. (Some platforms don't support these, but they also are not common anymore.)

Answer These Questions

(Please include answers to the following with your handin)

  1. Describe your exploration of your device - how you did it and what you found - in detail.

Explore Your Device

The first step is to figure out what capabilities your device has and how they are exposed by libST. The skeleton code has a function setup() which initializes the joystick library and sets up a simple scene. Here you'll need to add the code that opens your joystick for use. You'll probably also want to print out some information you can get from the joystick system at this point for debugging purposes.

In order to explore your joystick you'll need to poll the joystick for new state. You need to do this periodically, so we've set up the idle function to be called whenever GLUT has nothing else to do. In that function, add some code to poll the joystick and print out its current state (to the console is fine). Use this to explore the different parts of your joystick and discover how actions are relayed to you.

Create an Interface

Now that you know how input maps to state in an STJoystick you should use that input to create an interface. The simplest choice is to have input perform operations on the textured rectangle. No matter what you choose to do, you must include at least the following functionality:

  • A reset button - this should reset the scene to its original state
  • Rotation of an object - the control should be intuitive (note we've switched to perspective projection to make this easier to see)
  • Scaling of an object - you might make the dimensions scale independently
  • Panning (i.e. translation)

Here are some more ideas of controls to implement:

  • Adapt some code from assignment 1 and make parameters of what you drew be controlled using joystick input
  • A small game (e.g. Pacman with more controls)
  • An Etch-a-sketch-like program (draws lines, dpad for etch-a-sketch like controls, analog for the control everybody wishes etch-a-sketches had, buttons to change colors, zoom in/out on your current position, etc).
  • Buttons can act as modifiers for other actions, e.g. think of walking vs. running in many video games.

Like Assignment 1, anything goes here. We're looking for creative, intuitive controls.

In order to get full credit you must use at least

  • 1 analog stick (both axes)
  • 1 hat (both axes)
  • 6 buttons

Hints for Getting Started

  • You'll probably notice quickly that analog sticks don't always report 0 when they are at rest. In order not to get drift you'll need to experiment to find a reasonable cutoff magnitude, below which the input is interpreted as 0.
  • You may find aspects of libST too inflexible to achieve some effects. Feel free to change any code you want, just be sure to include and note any changes in your submission.

Grading

  • 1 star - answered the questions correctly
  • 2 stars - answered questions + fully explored joystick
  • 3 stars - answered questions + fully explored joystick + implemented some controls
  • 4 stars - answered questions + fully explored joystick + implemented all controls

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".

Recent