2013-05-06 62 views
0

好吧我想旋转一个PVector,我有这种方法。 该方法用PVector的x和y替换posX和posY。 运动是由来自Arduino的是移动图像在X和Y,但我想转视轴矢量操纵杆正在旋转一个PVector

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); 

} 

} 

回答

1

我没有一个Arduino操纵杆determinated迷上了,我不知道什么样的信息,你的手柄是给你的,所以我做了使用鼠标模仿操纵杆的处理实例:

int rad = 100; 

void setup() { 
    size(400, 400); 
} 

void draw() { 
    background(255); 
    ellipse(width/2, height/2, rad*2, rad*2); 

    // Using the mouse to mimic the position of the joystick 
    float theta = atan2(mouseY-height/2, mouseX-width/2); 

    // Get the new position 
    float x = width/2+cos(theta)*rad; 
    float y = height/2+sin(theta)*rad; 

    // Show the new position 
    ellipse(x, y, 30, 30); 
} 

atan2功能使角到鼠标位置,用相当于操纵杆位置的参数替换。较小的ellipse正在绘制显示你的miPersonaje将基于xy先前在代码中设置。 rad变量是任意的,仅用于显示目的,你可以将它设置为任何你想要的(如果需要的话)。

+0

好的,我会尽力的。谢啦 ;) – user2321978 2013-05-06 03:31:42