My Array is not showing up

edited February 2015 in Kinect

So I am trying to write the array that will show in this case 12 lines with random x and z values. I thought the best way to do it is to write a class for a line and then an array for the position and number of the lines. when I troubleshoot it, it endlessly counts to 12 and never stops also it doesn't draw the line.

Crossposted: http://stackoverflow.com/questions/28547809/my-array-is-printed-but-not-drawn

    import processing.opengl.*;
    import SimpleOpenNI.*;
    SimpleOpenNI  kinect;
    lines mylines;
    final int LINES_NB = 12;
    float[] posX = new float[LINES_NB];
    float[] posZ = new float[LINES_NB];
    float truz;
    float trux;

    void setup() { 
      size(1028, 768, OPENGL);
      for (int i = 0; i < LINES_NB; i++)
      {
        // Initialize the ball's data
        posZ[i] = random(-1000, 2000);
        posX[i] = random(50, 800);
      }   
      ambientLight(0, 0, 255);
      kinect = new SimpleOpenNI(this);
      kinect.enableDepth();
      kinect.enableUser();
      kinect.setMirror(true);

      // Initialize the ball's data
    }

    void draw() { 

      kinect.update();
      background(255);


      translate(width/2, height/2, 0);
      rotateX(radians(180));
      //float prp = -1000;
      //  float vrp = 50; 
      //      float z = random(prp,2000);
      //  float x = random(vrp,800);
      //   while (i >200);{
      //     truz = posZ[i] ;
      //     trux = posX[i] ;
      for (int i = 0; i < LINES_NB; i++)
      {

        displaylines(i);
        println(i);
      }

      //println(z);

      IntVector userList = new IntVector();

      kinect.getUsers(userList);
      if (userList.size() > 0) {
        int userId = userList.get(0);
        if ( kinect.isTrackingSkeleton(userId)) {
          PVector leftHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, leftHand);
          PVector rightHand = new PVector();
          kinect.getJointPositionSkeleton(userId, 
          SimpleOpenNI.SKEL_RIGHT_HAND, 
          rightHand);
          PVector leftFoot = new PVector();
          kinect.getJointPositionSkeleton(userId, 
          SimpleOpenNI.SKEL_LEFT_FOOT, 
          leftFoot);                                
          //PVector differenceVector = PVector.sub(leftHand, rightHand);
          //float magnitude = differenceVector.mag(); 
          //differenceVector.normalize();
          kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HAND, SimpleOpenNI.SKEL_RIGHT_HAND);

          stroke(255, 0, 0);
          strokeWeight(5);
          drawSkeleton(userId);
          pushMatrix(); 
          stroke(175); 
          strokeWeight(1); 
          println(leftFoot.x);
          println(leftFoot.y);
          println(leftFoot.z);
          line(leftFoot.x, leftFoot.y, leftFoot.z, leftFoot.x+100, leftFoot.y+100, leftFoot.z+1000);
          line(leftHand.x, leftHand.y, leftHand.z, rightHand.x, rightHand.y, rightHand.z);
          fill(250);
          translate(rightHand.x, rightHand.y, rightHand.z); 
          popMatrix();
        }
      }
    }
    void drawSkeleton(int userId) {
      drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);
      drawLimb(userId, SimpleOpenNI.SKEL_NECK, 
      SimpleOpenNI.SKEL_LEFT_SHOULDER);
      drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, 
      SimpleOpenNI.SKEL_LEFT_ELBOW);
      drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, 
      SimpleOpenNI.SKEL_LEFT_HAND);
      drawLimb(userId, SimpleOpenNI.SKEL_NECK, 
      SimpleOpenNI.SKEL_RIGHT_SHOULDER);
      drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, 
      SimpleOpenNI.SKEL_RIGHT_ELBOW);
      drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, 
      SimpleOpenNI.SKEL_RIGHT_HAND);
      drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, 
      SimpleOpenNI.SKEL_TORSO);
      drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, 
      SimpleOpenNI.SKEL_TORSO);
      drawLimb(userId, SimpleOpenNI.SKEL_TORSO, 
      SimpleOpenNI.SKEL_LEFT_HIP);
      drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, 
      SimpleOpenNI.SKEL_LEFT_KNEE);
      drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, 
      SimpleOpenNI.SKEL_LEFT_FOOT);
      drawLimb(userId, SimpleOpenNI.SKEL_TORSO, 
      SimpleOpenNI.SKEL_RIGHT_HIP);
      drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, 
      SimpleOpenNI.SKEL_RIGHT_KNEE);
      drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, 
      SimpleOpenNI.SKEL_RIGHT_FOOT);
      drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, 
      SimpleOpenNI.SKEL_LEFT_HIP);
    }
    void displaylines(int n)
    {
      stroke(255);
      mylines = new lines(posX[n], 0, posZ[n]);
      println();
    }
    void drawLimb(int userId, int jointType1, int jointType2)
    {
      PVector jointPos1 = new PVector();
      PVector jointPos2 = new PVector();
      float  confidence;
      // draw the joint position
      confidence = kinect.getJointPositionSkeleton(userId, jointType1, jointPos1);
      confidence = kinect.getJointPositionSkeleton(userId, jointType2, jointPos2);
      line(jointPos1.x, jointPos1.y, jointPos1.z, 
      jointPos2.x, jointPos2.y, jointPos2.z);
      //println(SimpleOpenNI.SKEL_RIGHT_KNEE);
      println(SimpleOpenNI.SKEL_RIGHT_FOOT);
    }
    //void displayLine(int n)

    // user-tracking callbacks!
    void onNewUser(SimpleOpenNI curContext, int userId) {
      println("start pose detection");
      kinect.startTrackingSkeleton(userId);
    }


    void onLostUser(SimpleOpenNI curContext, int userId)
    {
      //println("onLostUser - userId: " + userId);
    }

    void onVisibleUser(SimpleOpenNI curContext, int userId)
    {
      // println("onVisibleUser - userId: " + userId);
    }
class lines {

  color fillColor;
  color strokeColor;
  PVector dot1;
  PVector dot2;

  lines(float xpos, float ypos, float zpos) {
    dot1 = new PVector(500+xpos, 200, 700+zpos);
    dot2 = new PVector(500+xpos, -400, 700+zpos);
    fillColor = strokeColor = color(random(255), random(255), random(255));
  }
  void display() {
    pushMatrix();

    line (dot1.x, dot1.y, dot1.z, dot2.x, dot2.y, dot2.z);
    stroke(126);
    println("working");
    popMatrix();
  }
  void whatever() {
    println("please");
  }
}

Answers

Sign In or Register to comment.