
Above is a short video of my Exercise 2 and the physical interface that I made to control it.
==============================================================
Description:
This interactive driving applet consists of a Processing applet that simulates a road and a physical interface that controls it. The physical interface was created by rewiring an optical mouse to switches and mounting them in a foam core enclosure that I made to resemble a car interior.
==============================================================
Controls:
Steering Wheel/Mouse Wheel: Turn left or right.
Gas Pedal/Left Click: Accelerate.
Shifter/Right Click: Reverse On/Off.
Brake Pedal/Middle Click: Brake.
==============================================================
Code:
PImage road;
float y = -1200;
boolean inDrive;
boolean inReverse;
boolean brake;
boolean turnLeft;
boolean turnRight;
void setup(){
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
mouseWheel(evt.getWheelRotation());
}
}
);
road = loadImage (“Road.jpg”);
size(800,600);
background(0);
}
void mousePressed() {
if ( (mouseEvent.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
inDrive=false;
inReverse=false;
brake=true;
}
else if (mouseButton==LEFT){
inReverse=false;
brake=false;
inDrive=true;
}
else if (mouseButton==RIGHT) {
inDrive=false;
brake=false;
inReverse=true;
}
else if(mouseButton!=RIGHT){
inReverse=false;
}
}
void draw(){
if(y>0){
y=-1600;
}
if(y<-1600){
y=0;
}
if(inDrive){
y+=20;
}
if(inReverse){
y-=10;
}
if(turnLeft){
rotate(PI/10);
}
if(turnRight){
rotate(-PI/10);
}
image(road,-200,y);
}
void mouseWheel(int delta) {
println(delta);
if(delta<0){
turnLeft=false;
turnRight=true;
}
if(delta>0){
turnRight=false;
turnLeft=true;
}
}