2013-10-18 3 views
1

처리 용 멀티 터치 게임 패드 컨트롤을 만들고 원격 Arduino 로봇을 제어하는 ​​데 사용하고 싶습니다. Processing에서 GUI를 만들고 Android 용으로 컴파일하고 싶습니다. 여기 Processing + Arduino Robot을 제어하기위한 Android 용 게임 패드

처리를 위해 GUI 게임 패드입니다 지금까지 만든 :

float easing = 0.09; 
// start position 
int posX = 50; 
int posY = 200; 
// target position 
int targetX = 50; 
int targetY = 200; 

boolean dragging = false; 

void setup() 
{ 
    size(500,250); 
    smooth(); 
} 

void draw() 
{ 
background(255); 
if (!dragging) 
{ 
    // calculate the difference in position, apply easing and add to vx/vy 
    float vx = (targetX - (posX)) * easing; 
    float vy = (targetY - (posY)) * easing; 


    // Add the velocity to the current position: make it move! 
    posX += vx; 
    posY += vy; 
} 

if(mousePressed) 
{ 
    dragging = true; 
    posX = mouseX; 
    posY = mouseY; 
} 
else 
{ 
    dragging = false; 
} 

DrawGamepad(); 
DrawButtons(); 
} 

void DrawGamepad() 
{ 
    //fill(0,155,155); 
    //rect(0, 150, 100, 100, 15); 

    ellipseMode(RADIUS); // Set ellipseMode to RADIUS 

    fill(0,155,155); // Set fill to blue 
    ellipse(50, 200, 50, 50); // Draw white ellipse using RADIUS mode 

    ellipseMode(CENTER); // Set ellipseMode to CENTER 
    fill(255); // Set fill to white// 
    ellipse(posX, posY, 35, 35); // Draw gray ellipse using CENTER mode 
} 

void DrawButtons() 
{ 
    fill(0,155,155); // Set fill to blue 
    ellipse(425, 225, 35, 35); 
    ellipse(475, 225, 35, 35); 
    fill(255,0,0); // Set fill to blue 
    ellipse(425, 175, 35, 35); 
    ellipse(475, 175, 35, 35); 
} 

나는 그래서이 링크

에서 발견 다른 코드를 내놓았다 아마 코드가 안드로이드 멀티 터치 이벤트를 지원하지 않습니다 실현

Can Processing handle multi-touch?

그래서이 프로젝트의 목적은 내 아두 이노 로봇을 제어하는 ​​데 사용할 수 드 멀티 터치 게임 패드를 만드는 것입니다. 게임 패드는 조이스틱의 방향뿐만 아니라 어떤 키가 눌 렸는지 탐지해야합니다.

도움을 주시면 감사하겠습니다.

+0

정확히 질문은 무엇입니까? http://stackoverflow.com/questions/17166522/can-processing-handle-multi-touch에서 코드를 사용할 수없는 이유는 무엇입니까? –

+1

요점은 내가 지금 두 개의 코드가 있다는 것입니다. 하나는 multitouchevents를 처리하고 다른 하나는 gamepad control입니다. 둘 다 단일 코드로 결합하여 Android 장치에서 실행하고 싶습니다. 기능성 게임 패드를 완성하고 멀티 터치 코드와 결합하고 싶지만 작동시킬 수는 없습니다. 나는 어떤 도움을 주셔서 감사합니다. 감사합니다. – Iker

답변

1

내가 먼저 말하고자하는 것은 당신이 아마도 멀티 터치 호환성을 구현할 필요가 없다는 것입니다.

나는 이것을에 테스트하는 안드로이드를 가지고 있지 않지만, 다음 코드는 작동합니다 :

import android.view.MotionEvent; 

int TouchEvents; 

/* 
* xTouch and yTouch are arrays of the x and y coordinates of all fingers touching the screen, in arbitrary order. 
* e.g. xTouch[2] and yTouch[2] are the coordinates of the third arbitrarily ordered finger touching the screen. 
*/ 
float[] xTouch; 
float[] yTouch; 
int currentPointerId = 0; 
boolean printFPS; 

float easing = 0.09; 
// start position 
float posX = 50; 
float posY = 200; 
// target position 
float targetX = 50; 
float targetY = 200; 

boolean dragging = false; 

void setup() 
{ 
    size(500,250); 
    smooth(); 
    //size(displayWidth, displayHeight); 
    orientation(LANDSCAPE); 
    background(0, 255, 0); 
    fill(0, 0, 244); 
    rect(100, 100, 100, 100); 
    stroke(255); 

    // Initialize Multitouch x y arrays 
    xTouch = new float [10]; 
    yTouch = new float [10]; // Don't use more than ten fingers! 
} 

void draw() 
{ 
    background(255); 
    if (!dragging) 
    { 
    // calculate the difference in position, apply easing and add to vx/vy 
    float vx = (targetX - (posX)) * easing; 
    float vy = (targetY - (posY)) * easing; 


    // Add the velocity to the current position: make it move! 
    posX += vx; 
    posY += vy; 

    for (int i = 0; i < xTouch.length; i++) 
    { 
     ellipse(xTouch[i], yTouch[i], 150, 150); 
    } 
    } 
    DrawGamepad(); 
    DrawButtons(); 

    targetX = xTouch[currentPointerId]; 
    targetY = yTouch[currentPointerId]; 
} 

void DrawGamepad() 
{ 
    //fill(0,155,155); 
    //rect(0, 150, 100, 100, 15); 

    ellipseMode(RADIUS); // Set ellipseMode to RADIUS 

    fill(0,155,155); // Set fill to blue 
    ellipse(50, 200, 50, 50); // Draw white ellipse using RADIUS mode 

    ellipseMode(CENTER); // Set ellipseMode to CENTER 
    fill(255); // Set fill to white// 
    ellipse(posX, posY, 35, 35); // Draw gray ellipse using CENTER mode 
} 

void DrawButtons() 
{ 
    fill(0,155,155); // Set fill to blue 
    ellipse(425, 225, 35, 35); 
    ellipse(475, 225, 35, 35); 
    fill(255,0,0); // Set fill to blue 
    ellipse(425, 175, 35, 35); 
    ellipse(475, 175, 35, 35); 
} 

public boolean surfaceTouchEvent(MotionEvent event) 
{ 
    // Number of places on the screen being touched: 
    TouchEvents = event.getPointerCount(); 

    // If no action is happening, listen for new events else 
    for(int i = 0; i < TouchEvents; i++) 
    { 
    int pointerId = event.getPointerId(i); 
    xTouch[pointerId] = event.getX(i); 
    yTouch[pointerId] = event.getY(i); 
    float siz = event.getSize(i); 
    } 

    // ACTION_DOWN 
    if(event.getActionMasked() == 0) 
    { 
    print("Initial action detected. (ACTION_DOWN)"); 
    print("Action index: " +str(event.getActionIndex())); 
    } 
    // ACTION_UP 
    else if(event.getActionMasked() == 1) 
    { 
    print("ACTION_UP"); 
    print("Action index: " +str(event.getActionIndex())); 
    } 
    // ACTION_POINTER_DOWN 
    else if(event.getActionMasked() == 5) 
    { 
    print("Secondary pointer detected: ACTION_POINTER_DOWN"); 
    print("Action index: " +str(event.getActionIndex())); 
    } 
    // ACTION_POINTER_UP 
    else if(event.getActionMasked() == 6) 
    { 
    print("ACTION_POINTER_UP"); 
    print("Action index: " +str(event.getActionIndex())); 
    } 
    // 
    else if(event.getActionMasked() == 4) 
    { 

    } 

    // If you want the variables for motionX/motionY, mouseX/mouseY etc. 
    // to work properly, you'll need to call super.surfaceTouchEvent(). 
    return super.surfaceTouchEvent(event); 
} 
+1

답변 해 주셔서 감사합니다. 코드가 100 % 작동하지 않지만 제대로 작동 할 것입니다. 따라서 큰 원 안에 조이스틱 단추를 가져오고 단추 키를 누를 때마다 작업 작업을 수행하는 코드를 작성해야합니다. – Iker