2013-04-23 5 views
0

저는 현재 Fine Art에서 BA 과정을 밟고 있으며, 최근 Greg Borenstein의 'Making Things See'를 읽음으로써 프로그래밍을 배우려고 시작했습니다.Kinect. 함수에서 서로 영향을 미치지 않으면 서 다중 질량 중심으로 어떻게 작업합니까?

내가 개발중인 작품은 시청자가 Kinect를 사용하여 갤러리 공간을 돌아 다니면서 여러 개의 질량 중심을 추적하려는 시도입니다. 시청자가 화면에 흔적을 남길 수 있기를 바랬습니다. 또한 특정 지역에 가까워지면 선이나 기타 등으로 그 근접이 표시됩니다. 나는 하나의 흔적을 남길 수 있었지만, 다른 사람이 시야에 들어 오자마자 그들의 점수가 갑자기 연결됩니다. '근접선'은 또한 현재 사용자가 아닌 이전 사용자에게만 작용하는 것처럼 보입니다.

내 질문에 정말 내 모든 사용자에게 적용 할 수있는 함수 또는 클래스를 만들 수 있도록 각 새 사용자를 분리하는 방법에 오는 것 같아요하지만 서로 간섭하지 ..? 어떤 도움은 대단히 감사하겠습니다

class Hotpoint { 
    PVector center; 
    color fillColor; 
    color strokeColor; 
    int size; 
    int pointsIncluded; 
    int maxPoints; 
    boolean wasJustHit; 
    int threshold; 


    Hotpoint(float centerX, float centerY, float centerZ, int boxSize) { 
    center = new PVector(centerX, centerY, centerZ); 
    size = boxSize; 
    pointsIncluded = 0; 
    maxPoints = 1000; 
    threshold = 0; 

    strokeColor = color(random(255), random(255), random(255)); 
    fillColor = 0; 
    } 

    void setThreshold(int newThreshold){ 
    threshold = newThreshold; 
    } 

    void setMaxPoints(int newMaxPoints){ 
    maxPoints = newMaxPoints; 
    } 

    void setColor(float red, float blue, float green){ 
    fillColor = strokeColor = color(red, blue, green); 
    } 

    boolean check(PVector point) { 
    boolean result = false; 

    if (point.x > center.x - size/2 && point.x < center.x + size/2) { 
     if (point.y > center.y - size/2 && point.y < center.y + size/2) { 
     if (point.z > center.z - size/2 && point.z < center.z + size/2) { 
      result = true; 
      pointsIncluded++; 
     } 
     } 
    } 

    return result; 
    } 

    void draw() { 
    pushMatrix(); 
     translate(center.x, center.y, center.z); 
     shapeMode(LINES); 
     noFill(); 
     stroke(red(strokeColor), blue(strokeColor), green(strokeColor), 255); 
     box(size); 
    popMatrix(); 
    } 


    float percentIncluded() { 
    return map(pointsIncluded, 0, maxPoints, 0, 1); 
    } 


    boolean currentlyHit() { 
    return (pointsIncluded > threshold); 
    } 


    boolean isHit() { 
    return currentlyHit() && !wasJustHit; 
    } 

    void clear() { 
    wasJustHit = currentlyHit(); 
    pointsIncluded = 0; 
    } 
} 

여기에 프로그램이 지금까지의 ...

import processing.opengl.*; 
import SimpleOpenNI.*; 
import peasy.*; 

PeasyCam cam; 
SimpleOpenNI kinect; 

ArrayList<PVector> trails; 

Hotpoint piece; 

PVector currentPosition; 
PVector previousPosition; 

int pieceX = 0; 
int pieceY = 0; 
int pieceZ = 2000; 
int pieceSize = 500; 

void setup() { 
    size(1280, 680, OPENGL); 
    kinect = new SimpleOpenNI(this); 
    kinect.enableDepth(); 
    kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE); 
    kinect.setMirror(true); 

    trails = new ArrayList(); 

    piece = new Hotpoint(pieceX, pieceY, pieceZ, pieceSize); 

    cam = new PeasyCam(this, 0, 0, 0, 1000); 
} 

void draw() { 
    background(255); 
    kinect.update(); 
    rotateX(radians(180)); 

    lights(); 

    stroke(0); 
    strokeWeight(3); 

    IntVector userList = new IntVector(); 
    kinect.getUsers(userList); 

    piece.draw(); 

    for (int i=0; i<userList.size(); i++) { 
    int userId = userList.get(i); 

    PVector positionCenter = new PVector(); 
    kinect.getCoM(userId, positionCenter); 

    trails.add(positionCenter); 

    createTrail(); 

    piece.check(positionCenter); 

    if(piece.check(positionCenter) == true) { 
     stroke(255, 0, 0); 
     line(positionCenter.x, positionCenter.y, positionCenter.z, 
      pieceX, pieceY, pieceZ); 
     stroke(0); 
    } 
    } 
} 

void createTrail() { 
    for (int e=1; e < trails.size(); e++) { 
    currentPosition = trails.get(e); 
    previousPosition = trails.get(e-1); 
    if (currentPosition.z < 1) { 
     trails.clear(); 
    } 
    else { 
     stroke(0); 
     line(previousPosition.x, previousPosition.y, previousPosition.z, 
     currentPosition.x, currentPosition.y, currentPosition.z); 
    } 
    } 
} 

그리고 이것은 트리플 클래스 부분입니다 ...!


편집 :

이 당신의 시간과 응답 @의 jesses.co.tt 주셔서 너무 감사하지만 예를 들어 ... 그것을 이해하는 데 문제가 있었어요은을 통해 루프 userList는 사용자 배열과 다릅니다. 한 번에 두 가지 이상을 묻는 것이 걱정됩니다. 그래서 사람들이 연결되지 않은 상태에서 여러 개의 산책로를 그리는 방법을 먼저 이해하려고 노력했습니다.

import processing.opengl.*; 
import SimpleOpenNI.*; 
import peasy.*; 

SimpleOpenNI kinect; 
PeasyCam cam; 

ArrayList<PVector> trails1; 
ArrayList<PVector> trails2; 

PVector currentPosition; 
PVector previousPosition; 

void setup() { 
    size(1280, 800, OPENGL); 

    kinect = new SimpleOpenNI(this); 
    kinect.enableDepth(); 
    kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE); 
    kinect.setMirror(true); 

    trails1 = new ArrayList(); 
    trails2 = new ArrayList(); 

    cam = new PeasyCam(this, 0, 0, 0, 1000); 
} 

void draw() { 
    kinect.update(); 
    rotateX(radians(180)); 
    background(255); 

    IntVector userList = new IntVector(); 
    kinect.getUsers(userList); 

    //println(userList); 

    for (int i=0; i<userList.size(); i++) { 
    int userId = userList.get(i); 
    //println(userId); 
    PVector positionCenter = new PVector(); 
    kinect.getCoM(userId, positionCenter); 

    stroke(0); 
    strokeWeight(10); 
    point(positionCenter.x, positionCenter.y, positionCenter.z); 

    if (userId == 1) { 

     trails1.add(positionCenter); 
     createTrail1(); 
    } 
    else if (userId == 2) { 
     trails2.add(positionCenter); 
     createTrail2(); 
    } 
    } 
} 

void createTrail1() { 
    for (int e=1; e < trails1.size(); e++) { 
    currentPosition = trails1.get(e); 
    previousPosition = trails1.get(e-1); 
    if (currentPosition.z < 1) { // [possibly x or y or all?] 
     trails1.clear(); 
    } 
    else { 
     // if (currentPosition.x != 0 || previousPosition.x != 0) { // [not working] 
     stroke(0); 
     line(previousPosition.x, previousPosition.y, previousPosition.z, 
     currentPosition.x, currentPosition.y, currentPosition.z); 
     //trails.clear(); 
    } 
    } 
} 

void createTrail2() { 
    for (int e=1; e < trails2.size(); e++) { 
    currentPosition = trails2.get(e); 
    previousPosition = trails2.get(e-1); 
    if (currentPosition.z < 1) { // [possibly x or y or all?] 
     trails2.clear(); 
    } 
    else { 
     // if (currentPosition.x != 0 || previousPosition.x != 0) { // [not working] 
     stroke(0); 
     line(previousPosition.x, previousPosition.y, previousPosition.z, 
     currentPosition.x, currentPosition.y, currentPosition.z); 
     //trails.clear(); 
    } 
    } 
} 

그래서,이 두 사람을 위해 일 것이다, 나는 많은 사람들 한정된 수의 작업 끔찍하게 긴 프로그램을 쓸 수 있지만, 동적으로 무엇 난 정말 싶습니다 ... 입니다 'if (userId == 1) {'인 경우, 모든 사람들을 위해 일하기를 원합니다. 그런 다음 흔적 부분에서 새 사람이 등장 할 때마다 새로운 길을 따라야합니다. 보기 'void onNewUser (int userId) {'또는 뭔가 사용하는 줄 ..?

+0

아차, 내가, 트리플 클래스를 포함하는 것을 잊었을 거라고는 현재 편집되고 그래서! – basicallyright

답변

0

내가 알 수있는 한, SimpleOpenNI가 이미 제공 한 사용자의 크기를 조정할 수있는 목록을 만들어야하고, 찾은 각 새 사용자에 대해 HotPoint 클래스의 새 인스턴스를 만들어야합니다. 당신이 알려진 사용자의리스트를 적절하게 반복 될 때 당신은 거의 다) 사라 각 사용자 ...

...

당신은에 따라 크기를 조정 HotPoints의 ArrayList를 추가해야합니다 발견 된 사용자의 수 ... 새로운 사용자가 발견되면 포인트의 새로운 인스턴스를 생성합니다. 당신이 지금 가지고있는 방식으로, 당신은 하나의 인스턴스 만 가질 수 있습니다. 그래서 두 명의 사용자가 있다면, 당신을보고있는 것입니다.

필요에 따라 ArrayList에서 항목을 삭제해야합니다.

당신은 정말 가까이있어 ... ;-) 그래서

...

// Global Variables 
ArrayList users; 

그런 다음에 사용자를 통해 루프 ...

// Add a new HotPoint if we have more users than Points 
if(i > users.size()) { 
    users.add(new HotPoint(...)); 
} 
// Delete From ArrayList if we have too many... 
else if(users.size() > userList.size()) { 
    users.remove(...); 
} 

// Cast and call methods 
HotPoint piece = (HotPoint) users.get(i); 
piece.check(positionCenter); 
piece.draw(); 
etc... 
+0

기본적으로 -이 기능이 작동합니까? –

+0

답장을 보내 주셔서 감사합니다. @ jesses.co.tt 아직 이해가 안 되긴하지만 분명히 고무적입니다. 조금만 더 문제를 해결하기 위해 질문을 편집했습니다 ... 더 이상 도움이 될 수 있다면 정말 좋을 것 같습니다! – basicallyright