Skip to content

Instantly share code, notes, and snippets.

@brysonian
Created April 22, 2009 22:50
Show Gist options
  • Save brysonian/100144 to your computer and use it in GitHub Desktop.
Save brysonian/100144 to your computer and use it in GitHub Desktop.
[Processing] Simple example of connecting processing to a SpaceNavigator via OSCulator
/*
Simple example showing how to use the
SpaceNavigator <http://www.3dconnexion.com/3dmouse/spacenavigator.php>
with processing via OSC and OSCulator <http://www.osculator.net/>.
*/
import processing.opengl.*;
import oscP5.*;
OscP5 oscP5;
PVector snTranslation;
PVector snRotation;
int boxSize;
void setup() {
size(400,400, OPENGL);
frameRate(25);
noStroke();
oscP5 = new OscP5(this,9000);
oscP5.plug(this, "onSNRotate", "/sp/1/rot/xyz");
oscP5.plug(this, "onSNTranslate", "/sp/1/trans/xyz");
oscP5.plug(this, "onSNButton1", "/sp/1/button/1");
oscP5.plug(this, "onSNButton2", "/sp/1/button/2");
snTranslation = new PVector();
snRotation = new PVector();
boxSize = 100;
}
void draw() {
background(0);
lights();
pushMatrix();
translate(200+snTranslation.x, 200+snTranslation.y, 0+snTranslation.z);
rotateX(snRotation.x);
rotateY(snRotation.y);
rotateZ(snRotation.z);
box(boxSize);
popMatrix();
}
void onSNRotate(float x, float y, float z) {
snRotation.x = map(x, 0, 1, PI, -PI);
snRotation.y = map(y, 0, 1, PI, -PI);
snRotation.z = map(z, 0, 1, -PI, PI);
}
void onSNTranslate(float x, float y, float z) {
snTranslation.x = map(x, 0, 1, -width/2, width/2);
snTranslation.y = map(y, 0, 1, -height/2, height/2);
snTranslation.z = map(z, 0, 1, 250, -250);
}
void onSNButton1(float v) {
if (v == 1.0) boxSize+=5;
}
void onSNButton2(float v) {
if (v == 1.0) boxSize-=5;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment