rlishere
YaBB Newbies
Offline
Posts: 4
3DConnexion SpaceNavigator at work
Jan 27th , 2008, 9:19pm
This demonstrates the 3D input device. Tranlation an rotation is fetched from the SpaceNavigator. The mouse is still available. Button1, button2 or both are visualized by the cube's color. The original device driver must be installed. http://www.3dconnexion.de/ The device is interfaced by the procontroll library (HID support) which must be installed. http://www.texone.org/procontroll/ have fun rl Code: import procontroll.*; //based on JInput (HID Suport) //3DConnexion SpaceNavigator Demo for rotation, translation and buttons //Device must be correctly installed //procontroll must be installed //Ralf Löhmer - rl@loehmer.de ControllIO controll; ControllDevice device; //my SpaceNavigator ControllSlider sliderXpos; //Positions ControllSlider sliderYpos; ControllSlider sliderZpos; ControllSlider sliderXrot; //Rotations ControllSlider sliderYrot; ControllSlider sliderZrot; ControllButton button1; //Buttons ControllButton button2; void setup(){ size(400,400,P3D); colorMode(RGB); controll = ControllIO.getInstance(this); device = controll.getDevice("SpaceNavigator");//magic name device.setTolerance(5.00f); sliderXpos = device.getSlider("X-Achse");//German in all drivers??? sliderYpos = device.getSlider("Y-Achse"); sliderZpos = device.getSlider("Z-Achse"); sliderXrot = device.getSlider("X-Rotation"); sliderYrot = device.getSlider("Y-Rotation"); sliderZrot = device.getSlider("Z-Rotation"); button1 = device.getButton("Taste 0"); button2 = device.getButton("Taste 1"); sliderXpos.setMultiplier(0.01); //sensitivities sliderYpos.setMultiplier(0.01); sliderZpos.setMultiplier(0.01); sliderXrot.setMultiplier(0.0001); sliderYrot.setMultiplier(0.0001); sliderZrot.setMultiplier(0.0001); rectMode(CENTER); } float totalX = 0; //inits float totalY = 0; float totalZ = 0; float totalXrot = 0; float totalYrot = 0; float totalZrot = 0; void draw(){ background(33,170,170); totalX = constrain(totalX + sliderXpos.getValue(),10,width-10); totalY = constrain(totalY + sliderYpos.getValue(),10,height-10); totalZ = constrain(totalZ + sliderZpos.getValue(),-500,210); totalXrot = constrain(totalXrot + sliderXrot.getValue(),0,TWO_PI); totalYrot = constrain(totalYrot + sliderYrot.getValue(),0,TWO_PI); totalZrot = constrain(totalZrot + sliderZrot.getValue(),0,TWO_PI); if(button1.pressed() && button2.pressed()){ //shows the buttons pressed fill(255,0,0); }else if(button2.pressed()){ fill(0,255,0); }else if(button1.pressed()){ fill(0,0,255); }else{ fill(255,255,255); } lights(); translate(totalX,totalY,totalZ); rotateX(totalXrot); rotateY(totalYrot); rotateZ(totalZrot); noStroke(); box(90); stroke (255,0,0);//X line(-100, 0, 0, 100, 0, 0); stroke (0,255,0);//Y line(0, -100, 0, 0, 100, 0); stroke (0,0,255);//Z line(0, 0, -100, 0, 0, 100); }