ok guys want rotate pvector have in method. method replaces posx , posy x , y of pvector. movement determinated joystick comes arduino moves image in x , y turn vector depending on axis joystick looking
public void moverpjuno(pvector coordenadas) { if(areaxad==-1 && areaxat==-1){ mipersonaje.setposx((mipersonaje.getposx())+(int)coordenadas.x); } if(areayab==-1 && areayar==-1){ mipersonaje.setposy((mipersonaje.getposy())+(int)coordenadas.y); } }
i don't have arduino hooked , don't know kind of information joystick giving you, made processing example uses mouse imitate joystick:
int rad = 100; void setup() { size(400, 400); } void draw() { background(255); ellipse(width/2, height/2, rad*2, rad*2); // using mouse mimic position of joystick float theta = atan2(mousey-height/2, mousex-width/2); // new position float x = width/2+cos(theta)*rad; float y = height/2+sin(theta)*rad; // show new position ellipse(x, y, 30, 30); } the atan2 function gives angle mouse position, replace arguments equivalent of joystick position. smaller ellipse being drawn shows mipersonaje set based on x , y earlier in code. rad variable arbitrary , displaying purposes, can set whatever want (if needed @ all).
Comments
Post a Comment