0

私は現在、ファイン アートの学士号を取得しており、最近、グレッグ ボレンスタインの「Making Things See」を読んでプログラミングを学び始めました。

私が開発している作品は、視聴者が Kinect を使用してギャラリー スペースを移動するときに、複数の重心を追跡する試みです。視聴者が画面上に軌跡を残すことを期待していました。また、視聴者が特定の領域に近づいたときに、その距離が線などで示されることも期待していました。なんとか1本の軌跡をたどったのですが、別の人が視界に入るやいなや、それらのポイントは突然接続されます。「近接ライン」も現在のユーザーに対してのみ機能し、以前のユーザーには機能しないようです。

私の質問は、新しいユーザーをそれぞれ分離して、それらすべてに適用されるが互いに干渉しない関数またはクラスを作成できるようにする方法に本当に帰着すると思います..?

ここまでのプログラムは…

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

そして、これが Hotpoint クラスのパーツです...

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

どんな助けでも大歓迎です!


編集:

@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();
    }
  }
}

したがって、これは 2 人で機能し、非常に長いプログラムを作成して多数の限られた人数で機能するようにすることもできますが、私が本当に望んでいるのは、それが動的であることです... 'if (userId = = 1) {', 私はそれが誰にとってもうまくいくことを望みます.そして、トレイル部分では、新しい人が視界に入るたびに 'void を使用するように、トレイルの新しい配列が必要になります. onNewUser(int userId) {' または何か..?

4

1 に答える 1