Anney-N.
YaBB Newbies
Offline
Posts: 1
need help with joystick
Jan 28th , 2008, 4:47pm
hello everybody, i'm newbie in processing and need some help with my project. i want to controll the directions of a litte triangle with a joystick by proControll lib. the triangle should have some trig but right now its just twiggling round in the upper left corner and not following the joystick and i don't know what i made wrong. I would be pleased about some help. ------ Code ------ import procontroll.*; import java.io.*; ControllIO controll; ControllDevice device; ControllStick stick; ControllButton button; // triangle float predCntrX, predCntrY; float predX[] = new float[3]; float predY[] = new float[3]; float predLen = 8.0; float predAng, predRot; float easing = .05; void setup(){ size(400,400); predCntrX = width/2; predCntrY = height/2; smooth(); //get controller instance controll = ControllIO.getInstance(this); //list controller controll.printDevices(); //controller id 2 device = controll.getDevice(2); println("STICKS:"); device.printSticks(); println("SLIDERS:"); device.printSliders(); device.setTolerance(0.05f); ControllSlider sliderX = device.getSlider(0); ControllSlider sliderY = device.getSlider(1); stick = new ControllStick(sliderX,sliderY); //repaint background fill(255, 40); rect(0, 0, width, height); } float totalX = (width/2); float totalY = (height/2); void draw(){ background(255); //get x/y distance between stick and triangle float deltaX = (stick.getX()-predCntrX); float deltaY = (stick.getY()-predCntrY); //decelerate deltaX *= easing; deltaY *= easing; predCntrX += deltaX; predCntrY += deltaY; // orient triangle predRot = atan2(deltaY, deltaX); totalX = constrain(deltaX + stick.getX(),10,width-10); totalY = constrain(deltaY + stick.getY(),10,height-10); // draw triangle createPredatoryTriangle(); //println("X: "+stick.getX()); } void createPredatoryTriangle(){ // draw triangle with some trig fill(0); beginShape(); for (int i=0; i<3; i++){ predX[i] = predCntrX+cos(radians(predAng)+predRot)*predLen; predY[i] = predCntrY+sin(radians(predAng)+predRot)*predLen; vertex(predX[i], predY[i]); predAng += 120; } endShape(CLOSE); }