Assignment4

Assignment 4 - User Input

Due Date: Thursday February 8th, 11:59PM

Questions? Check out the Assignment 4 FAQ and discussion page.

The Assignment 4 Joystick Signup 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 so you probably won't have to deal directly with the matrix. 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.)

Access to Joysticks

We are providing a set of joysticks and gamepads that can be checked out for 1 day at a time. There will be 4 days you can check out a joystick and you MUST return the joystick by the specified time the following day. Given the limited supply of joysticks you'll probably have 24 hours to complete the assignment. People who start early (i.e. those who choose to pick up a joystick on Friday) get the entire weekend to use the joystick. On the last day the joysticks will be available on a first come, first served basis. Go to the [JoystickSignup] page to sign up for a joystick. Make sure you have the skeleton code compiled and running before you sign out the joystick so you don't waste any time.

If you have a joystick or gamepad of your own, please feel free to use it. However, we also suggest checking out devices that are unlike ones that you already have access to in order to experiment with the entire range of input devices. If you want to buy your own gamepad or joystick the cheapest ones are about $15 at Fry's. If you have a joystick and it isn't working with the STJoystick class, let us know and we may be able to help get it working.

Please start on the assignment early so you'll have enough time to get a joystick multiple times if you don't have one of your own. We want you to have time to experiment with them and don't want access to joysticks to become a problem the night the assignment is due.

Where to Work

Currently the myth computers don't allow you to access the joysticks once they have been plugged in. While we are waiting for that to be fixed you can use any lab computer with Windows and Visual Studio to work on. For example, the computers in Tresidder Lair, Meyer Library, and Green Library should all work fine. Of course working on your own computer is also fine.

Answer This Question

(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. You should describe your joystick, what code you wrote to learn about it, how the inputs mapped to the STJoystick interface we provide, ranges of values returned, etc.

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 skeleton code creates a textured square and your interface should control this object in various ways. Feel free to add to or change the scene, but focus on interaction techniques, not making a great demo scene. No matter what scene you choose, 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 (or equivalently, translation of the object)

Here are some additional ideas you can implement:

  • Use buttons to activate/deactivate high level functions, e.g. make the object bounce around the screen, make a series of textured squares rotate in a circle (like a ticker), etc.
  • Buttons can act as modifiers for other actions, e.g. the speed of some function can be increased or decreased when a button is pushed
  • Non-linear response - the speed or effect of some action doesn't need to be directly proportional to the input.

Be creative, we're looking for creative, intuitive controls.

In order to get full credit you must use at least

  • 1 analog stick or 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 stars - explored joystick
  • 3 stars - explored joystick + implemented some controls
  • 4 stars - 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 and details about your control scheme. Also note what joystick you used and what subset of its functionality is necessary to use your interface (e.g. 2 analog sticks, 1 hat, 8 buttons).

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