Kinect,RotateY,PopMatrix,PushMatrix

edited September 2016 in Kinect

hello guys,here i have 3 examples of the same code,the two of them is with kinect and the other with a static point and the mouse.The final installation will be with the two hands of the kinect.I have one problem with the kinect and one with pushMatrix popMatrix and rotate().I will explain in the code below.What are the problems and the what i want to achieve

First example:here the examples are not rotating(the cubes,the models and the area that influence the models)It works perfect except that for the model to be shown,it has to calibrate first with the kinect because the if statements.

import peasy.*;
import saito.objloader.*;
import SimpleOpenNI.*;
import spout.*;

//PrintWriter output;
OBJModel model ;
OBJModel Smodel ;
OBJModel tmpmodel ;

Spout spout;

PeasyCam cam;

SimpleOpenNI kinect;


float z=0;
float easing = 0.005;
float r;
float k;
int VertCount;
PVector[] Verts;
PVector[] locas;
PVector Mouse;
PVector Mouse2;

void setup()
{
  size(640*3, 480*3, P3D);
  frameRate(30);
  noStroke();

  kinect = new SimpleOpenNI(this);

  kinect.enableDepth();
  kinect.enableUser();

  model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  model.enableDebug();
  model.scale(200);
  model.translateToCenter();

  Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  Smodel.enableDebug();
  Smodel.scale(200);
  Smodel.translateToCenter();

  tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  tmpmodel.enableDebug();
  tmpmodel.scale(200);
  tmpmodel.translateToCenter();

  //output = createWriter("positions.txt"); 

  cam = new PeasyCam(this, width/2, height/2, 0, 2300);

  spout = new Spout(this);

  spout.createSender("Self kinect");
}


void draw()
{
  background(0);
  lights();

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

  int VertCount = model.getVertexCount ();
  Verts = new PVector[VertCount];
  locas = new PVector[VertCount];
  r =300;
  //k = k + 0.01;

  cam.setMouseControlled(false);


  if (userList.size() > 0) {

    textSize(300);
    text("Start1", width/2-150, height/2-150); 
    fill(0, 102, 153);

    int userId = userList.get(0);

    if ( kinect.isTrackingSkeleton(userId)) {

      textSize(300);
      text("Start2", width/2-150, height/2-150); 
      fill(0, 102, 153);

      PVector rightHand = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, rightHand);

      PVector convertedRightHand = new PVector();
      kinect.convertRealWorldToProjective(rightHand, convertedRightHand);

      PVector leftHand = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, leftHand);

      PVector convertedLeftHand = new PVector();
      kinect.convertRealWorldToProjective(leftHand, convertedLeftHand);


      PVector rightShoulder = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, rightShoulder);

      PVector convertedRightShoulder = new PVector();
      kinect.convertRealWorldToProjective(rightShoulder, convertedRightShoulder);


      PVector leftShoulder = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, leftShoulder);

      PVector convertedleftShoulder = new PVector();
      kinect.convertRealWorldToProjective(leftShoulder, convertedleftShoulder);


      //output.println(" This is the firstPose "+"rightHand "+rightHand+" leftHand "+leftHand);



      float rightHandZ =  map(rightHand.z, 5500, 7500, 1100, 1500);
      float ConrightHandZ = map(rightHandZ, 1100, 1500, 0, 1440);

      float leftHandZ =map(leftHand.z, 5500, 7500, 1100, 1500);
      float ConleftHandZ = map(leftHandZ, 1100, 1500, 0, 1440);

      Mouse = new PVector(rightHand.x, -rightHand.y, z);
      Mouse2 = new PVector(leftHand.x, -leftHand.y, z);


      println("rightHand "+rightHand.z+"leftHand "+leftHand.z);
      //println(frameCount);

      pushMatrix();

      translate(width/2, height/2, 0);
      rotateY(k);


      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);

        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);


        //PVector tmpv = new PVector();


        if (frameCount> 100) {



          float randX = noise(randomGaussian());
          float randY = noise(randomGaussian());
          float randZ = noise(randomGaussian());

          PVector Ran = new PVector(randX, randY, randZ);

          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;

          if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          } else {   

            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;

            if (Verts[i].x > width/2 ) {
              Verts[i].x=-width/2;
            } else if (Verts[i].x < -width/2) {
              Verts[i].x=width/2;
            }
            if (Verts[i].y > height/2 ) {
              Verts[i].y=-height/2;
            } else if (Verts[i].y < -height/2) {
              Verts[i].y=height/2;
            }

            if (Verts[i].z < -720 ) {  
              Verts[i].z=800/2;
            } else if ( Verts[i].z > 720) {
              Verts[i].z=-800/2;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }

      pushMatrix();
      rotateY(-k); //-----------------HERE
      translate(Mouse.x, Mouse.y, Mouse.z);
      rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      strokeWeight(3);
      box(r, r, 1920);
      popMatrix();


      pushMatrix();
      rotateY(-k); //-----------------HERE
      translate(Mouse2.x, Mouse2.y, Mouse2.z);
      rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      strokeWeight(3);
      box(r, r, 1920);
      popMatrix();


      noStroke();

      tmpmodel.draw();

      popMatrix();



      pushMatrix();
      translate(width/2, height/2, 0);
      rotateY(k);
      noFill();
      stroke(255);
      strokeWeight(7);
      box(width, height, 1920);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      //println(z);
    }
  }

  spout.sendTexture();
}


void onNewUser(SimpleOpenNI kinect, int userID) {


  kinect.startTrackingSkeleton(userID);
}

//startTracking is alterd 
void onEndCalibration(int userId, boolean successful) {
  if (successful) {
    println(" User calibrated !!!");
    kinect.startTrackingSkeleton(userId);
  } else {
    println("  Failed to calibrate user !!!");
    kinect.startTrackingSkeleton(userId);
  }
}

//There is aproblem here,deleted the pose



void keyPressed() {
  if (keyCode == UP) {
    z++;
  }
  if (keyCode == DOWN) {
    z--;
  }
}

Second Example: Here is the same example with above,but i tried to move out the kinect calibration from the general animation of the model,which is difined by RanX,RanY,RanZ and Nor.I tried to solve the problem with a boolean.The problem is that when the Kinect calibrates the user the animation stops.

import peasy.*;
import saito.objloader.*;
import SimpleOpenNI.*;
import spout.*;

//PrintWriter output;
OBJModel model ;
OBJModel Smodel ;
OBJModel tmpmodel ;

Spout spout;

PeasyCam cam;

SimpleOpenNI kinect;


float z=0;
float easing = 0.005;
float r;
float k;
int VertCount;
PVector[] Verts;
PVector[] locas;
PVector Mouse;
PVector Mouse2;
PVector rightHand;
PVector convertedRightHand;
PVector leftHand;
PVector convertedLeftHand;
PVector rightShoulder;
PVector convertedRightShoulder;
PVector leftShoulder;
PVector convertedleftShoulder;
float rightHandZ;
float ConrightHandZ;
float leftHandZ;
float ConleftHandZ;

`boolean Kin = false;`

void setup()
{
  size(640*3, 480*3, P3D);
  frameRate(30);
  noStroke();

  kinect = new SimpleOpenNI(this);

  kinect.enableDepth();
  kinect.enableUser();

  model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  model.enableDebug();
  model.scale(200);
  model.translateToCenter();


  Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  Smodel.enableDebug();
  Smodel.scale(200);
  Smodel.translateToCenter();


  tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  tmpmodel.enableDebug();
  tmpmodel.scale(200);
  tmpmodel.translateToCenter();

  //output = createWriter("positions.txt"); 

  cam = new PeasyCam(this, width/2, height/2, 0, 2300);


  spout = new Spout(this);

  spout.createSender("Self kinect");
}



void draw()
{
  background(0);
  lights();

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

  int VertCount = model.getVertexCount ();
  Verts = new PVector[VertCount];
  locas = new PVector[VertCount];
  r =300;
  //k = k + 0.01;




  cam.setMouseControlled(false);







  if (userList.size() > 0) {

    textSize(300);
    text("Start1", width/2-150, height/2-150); 
    fill(0, 102, 153);

    int userId = userList.get(0);

    if ( kinect.isTrackingSkeleton(userId)) {
      `Kin=true;`
      textSize(300);
      text("Start2", width/2-150, height/2-150); 
      fill(0, 102, 153);

      rightHand = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, rightHand);

      convertedRightHand = new PVector();
      kinect.convertRealWorldToProjective(rightHand, convertedRightHand);

      leftHand = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, leftHand);

      convertedLeftHand = new PVector();
      kinect.convertRealWorldToProjective(leftHand, convertedLeftHand);


      rightShoulder = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, rightShoulder);

      convertedRightShoulder = new PVector();
      kinect.convertRealWorldToProjective(rightShoulder, convertedRightShoulder);


      leftShoulder = new PVector();
      kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, leftShoulder);

      convertedleftShoulder = new PVector();
      kinect.convertRealWorldToProjective(leftShoulder, convertedleftShoulder);


      //output.println(" This is the firstPose "+"rightHand "+rightHand+" leftHand "+leftHand);



      rightHandZ =  map(rightHand.z, 5500, 7500, 1100, 1500);
      ConrightHandZ = map(rightHandZ, 1100, 1500, 0, 1440);

      leftHandZ =map(leftHand.z, 5500, 7500, 1100, 1500);
      ConleftHandZ = map(leftHandZ, 1100, 1500, 0, 1440);

      Mouse = new PVector(rightHand.x, -rightHand.y, z);
      Mouse2 = new PVector(leftHand.x, -leftHand.y, z);

      pushMatrix();
      translate(width/2, height/2, 0);
      pushMatrix();
      rotateY(-k); //-----------------HERE
      translate(Mouse.x, Mouse.y, Mouse.z);
      rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      strokeWeight(3);
      box(r, r, 1920);
      popMatrix();


      pushMatrix();
      rotateY(-k); //-----------------HERE
      translate(Mouse2.x, Mouse2.y, Mouse2.z);
      rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      strokeWeight(3);
      box(r, r, 1920);
      popMatrix();
      popMatrix();
    }
  }


  //println("rightHand "+rightHand.z+"leftHand "+leftHand.z);
  //println(frameCount);




  pushMatrix();




  translate(width/2, height/2, 0);
  rotateY(k);


  for (int i = 0; i < VertCount; i++) {
    //PVector orgv = model.getVertex(i);

    locas[i]= model.getVertex(i);
    Verts[i]= Smodel.getVertex(i);


    //PVector tmpv = new PVector();


    if (frameCount> 10) {



      float randX = noise(randomGaussian());
      float randY = noise(randomGaussian());
      float randZ = noise(randomGaussian());

      PVector Ran = new PVector(randX, randY, randZ);

      //float norX = abs(cos(k)) * randX;
      //float norY = abs(cos(k)) * randY;
      //float norZ = abs(cos(k)) * randZ;








     ` if (Kin==true) {`
        if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
          tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
        }
     ` } else if (Kin==true||Kin==false) {   `



        Verts[i].x+=Ran.x;
        Verts[i].y+=Ran.y;
        Verts[i].z+=Ran.z;

        if (Verts[i].x > width/2 ) {
          Verts[i].x=-width/2;
        } else if (Verts[i].x < -width/2) {
          Verts[i].x=width/2;
        }
        if (Verts[i].y > height/2 ) {
          Verts[i].y=-height/2;
        } else if (Verts[i].y < -height/2) {
          Verts[i].y=height/2;
        }

        if (Verts[i].z < -720 ) {  
          Verts[i].z=800/2;
        } else if ( Verts[i].z > 720) {
          Verts[i].z=-800/2;
        }
        tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
      }
    }
    // output.println("Verts " + Verts[i] + " locas " +locas[i]);
  }




  noStroke();

  tmpmodel.draw();

  popMatrix();



  pushMatrix();
  translate(width/2, height/2, 0);
  rotateY(k);
  noFill();
  stroke(255);
  strokeWeight(7);
  box(width, height, 1920);
  popMatrix();
  //output.flush(); // Writes the remaining data to the file
  //output.close(); // Finishes the file
  //saveFrame();
  //println(z);
  if (userList.size() < 0) {
    Kin=false;
  }

  spout.sendTexture();
  println(Kin);
}


void onNewUser(SimpleOpenNI kinect, int userID) {


  kinect.startTrackingSkeleton(userID);
}

//startTracking is alterd 
void onEndCalibration(int userId, boolean successful) {
  if (successful) {
    println(" User calibrated !!!");
    kinect.startTrackingSkeleton(userId);
  } else {
    println("  Failed to calibrate user !!!");
    kinect.startTrackingSkeleton(userId);
  }
}

//There is aproblem here,deleted the pose



void keyPressed() {
  if (keyCode == UP) {
    z++;
  }
  if (keyCode == DOWN) {
    z--;
  }
}

Answers

  • Here is the final example i couldnt put it in the question because of length

    Final Example:Here is the example without the kinect,but with one poin that is static and one that is controlled by the mouse.The problem is that i made several PushMatrix() Popmatrix() each inside an other.the bigg pushMatrix that it includes all other is rotateY by (k).The problem is that to have the cubes that transform the models dont rotate i had inside their pushMatrix to rotate them by -k,so to be static in front the screen and to not confuse the user.The problem is that while the cubes are not rotating, their infuence is rotated because it is in the larger popmatrix.

     import peasy.*;
    import saito.objloader.*;
    import spout.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    
    PeasyCam cam;
    
    float z=0;
    float easing = 0.005;
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector[] Bez;
    PVector[] Bez2;
    PVector Mouse;
    PVector Mouse2;
    
    int VECS = 800;
    
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(200);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(200);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(200);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 1600);
    
      spout = new Spout(this);
    
      spout.createSender("Self");
    }
    
    
    
    void draw()
    {
      background(0);
      pointLight(255, 255, 255, 
      width/2, height/2, 1600);
    
    
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      Bez = new PVector[VertCount];
      Bez2 = new PVector[VertCount];
      r =100;
      k = k + 0.01;
    
    
      PVector psVerts[] = new PVector[VECS];
      PVector psVerts2[]= new PVector[VECS];
    
    
      cam.setMouseControlled(false);
    
    
      Mouse = new PVector(mouseX-width/2, mouseY-height/2, z);
      Mouse2 = new PVector(width/2 -height/2, z);
    
    
    
    
    
      //println(frameCount);
     ` pushMatrix();`
    
    
    
    
      translate(width/2, height/2, 0);
      `rotateY(k);`
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
        if (frameCount> 100) {
    
    
    
          float randX = noise(randomGaussian());
          float randY = noise(randomGaussian());
          float randZ = noise(randomGaussian());
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
    
         ` if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {`
    
    
    
    
            pushMatrix();
            pushStyle();
            strokeWeight(0.1);
            stroke(255, 255, 255);
            noFill();
            bezier(locas[i].x, locas[i].y, locas[i].z, -100, -100, -100, -100, -100, -100, Verts[i].x, Verts[i].y, Verts[i].z);
            popStyle();
            popMatrix();
    
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          } else {   
    
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 ) {
              Verts[i].x=-width/2;
            } else if (Verts[i].x < -width/2) {
              Verts[i].x=width/2;
            }
            if (Verts[i].y > height/2 ) {
              Verts[i].y=-height/2;
            } else if (Verts[i].y < -height/2) {
              Verts[i].y=height/2;
            }
    
            if (Verts[i].z < -800/2 ) {  
              Verts[i].z=800/2;
            } else if ( Verts[i].z > 800/2) {
              Verts[i].z=-800/2;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
      /*pushMatrix();
       `rotateY(-k);` //-----------------HERE
       translate(0, 0, 0);
    
       //rotateY(k);
       noFill();
       strokeWeight(3);
       stroke(255, 10, 10);
    
       /* beginShape();
    
       for (int i=0; i < VECS; i+=30 ) {
    
       psVerts[i] = new PVector (Mouse.x, Mouse.y, (Mouse.z+400));
       psVerts2[i] = new PVector(Mouse2.x, Mouse2.y, (Mouse2.z-400));
    
    
    
       vertex(psVerts[i].x, psVerts[i].y, psVerts[i].z);
       vertex(psVerts2[i].x, psVerts2[i].y, width/2-i);
       vertex(noise(-width/2, +width/2), noise(-height/2, +height/2), noise(-width/2, +width/2));
       vertex(random(-width/2, +width/2), random(-height/2, +height/2), random(-width/2, +width/2));
       vertex(psVerts[i].x, psVerts[i].y, psVerts[i].z);
       vertex(psVerts2[i].x, psVerts2[i].y, width/2-i);
       vertex(noise(-width/2, +width/2), noise(-height/2, +height/2), noise(-width/2, +width/2));
       vertex(random(-width/2, +width/2), random(-height/2, +height/2), random(-width/2, +width/2));
       }
       endShape();
       popMatrix();*/
    
    
      pushMatrix();
      pushStyle();
      noLights();
      `rotateY(-k);` //-----------------HERE
      translate(Mouse.x, Mouse.y, Mouse2.z+width/2);
      //rotateY(k); //-------------AND HERE
      fill(255, 0, 0);
      ellipse(0, 0, 10, 10);
      popStyle();
      popMatrix();
    
    
    
    
      pushMatrix();
      pushStyle();
      rotateY(-k); //-----------------HERE
      translate(Mouse2.x, Mouse2.y, Mouse2.z+width/2);
      //rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      strokeWeight(3);
      box(r, r, 800);
      popStyle();
      popMatrix();
    
    
      noStroke();
      tmpmodel.draw();
      popMatrix();
    
    
    
      /*pushMatrix();
       translate(width/2, height/2, 0);
       rotateY(k);
       noFill();
       stroke(255);
       strokeWeight(7);
       box(width, height, 800);
       popMatrix();*/
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      //println(z);
    
      spout.sendTexture();
    }
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    

    It will be very helpfull if you had any solution,Thank you very much.I have only 3 days for my degree and i have to solve it

  • first problem solved.i just move up the animation functions

    import peasy.*;
    import saito.objloader.*;
    import SimpleOpenNI.*;
    import spout.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    PeasyCam cam;
    
    SimpleOpenNI kinect;
    
    
    float z=0;
    float easing = 0.005;
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    PVector Mouse2;
    PVector rightHand;
    PVector convertedRightHand;
    PVector leftHand;
    PVector convertedLeftHand;
    PVector rightShoulder;
    PVector convertedRightShoulder;
    PVector leftShoulder;
    PVector convertedleftShoulder;
    float rightHandZ;
    float ConrightHandZ;
    float leftHandZ;
    float ConleftHandZ;
    
    boolean Kin = false;
    
    void setup()
    {
      size(640*3, 480*3, P3D);
      frameRate(30);
      noStroke();
    
      kinect = new SimpleOpenNI(this);
    
      kinect.enableDepth();
      kinect.enableUser();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(200);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(200);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(200);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 2300);
    
    
      spout = new Spout(this);
    
      spout.createSender("Self kinect");
    }
    
    
    
    void draw()
    {
      background(0);
      lights();
    
      kinect.update();
      IntVector userList = new IntVector();
      kinect.getUsers(userList);
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      r =300;
      //k = k + 0.01;
    
    
    
    
      cam.setMouseControlled(false);
    
    
    
    
    
    
    
      if (userList.size() > 0) {
    
        textSize(300);
        text("Start1", width/2-150, height/2-150); 
        fill(0, 102, 153);
    
        int userId = userList.get(0);
    
        if ( kinect.isTrackingSkeleton(userId)) {
          Kin=true;
          textSize(300);
          text("Start2", width/2-150, height/2-150); 
          fill(0, 102, 153);
    
          rightHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, rightHand);
    
          convertedRightHand = new PVector();
          kinect.convertRealWorldToProjective(rightHand, convertedRightHand);
    
          leftHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, leftHand);
    
          convertedLeftHand = new PVector();
          kinect.convertRealWorldToProjective(leftHand, convertedLeftHand);
    
    
          rightShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, rightShoulder);
    
          convertedRightShoulder = new PVector();
          kinect.convertRealWorldToProjective(rightShoulder, convertedRightShoulder);
    
    
          leftShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, leftShoulder);
    
          convertedleftShoulder = new PVector();
          kinect.convertRealWorldToProjective(leftShoulder, convertedleftShoulder);
    
    
          //output.println(" This is the firstPose "+"rightHand "+rightHand+" leftHand "+leftHand);
    
    
    
          rightHandZ =  map(rightHand.z, 5500, 7500, 1100, 1500);
          ConrightHandZ = map(rightHandZ, 1100, 1500, 0, 1440);
    
          leftHandZ =map(leftHand.z, 5500, 7500, 1100, 1500);
          ConleftHandZ = map(leftHandZ, 1100, 1500, 0, 1440);
    
          Mouse = new PVector(rightHand.x, -rightHand.y, z);
          Mouse2 = new PVector(leftHand.x, -leftHand.y, z);
    
          pushMatrix();
          translate(width/2, height/2, 0);
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse.x, Mouse.y, Mouse.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
    
    
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse2.x, Mouse2.y, Mouse2.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
          popMatrix();
        }
      }
    
    
      //println("rightHand "+rightHand.z+"leftHand "+leftHand.z);
      //println(frameCount);
    
    
    
    
      pushMatrix();
    
    
    
    
      translate(width/2, height/2, 0);
      rotateY(k);
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
    
        float randX = noise(randomGaussian());
        float randY = noise(randomGaussian());
        float randZ = noise(randomGaussian());
    
        PVector Ran = new PVector(randX, randY, randZ);
    
        Verts[i].x+=Ran.x;
        Verts[i].y+=Ran.y;
        Verts[i].z+=Ran.z;
    
        if (Verts[i].x > width/2 ) {
          Verts[i].x=-width/2;
        } else if (Verts[i].x < -width/2) {
          Verts[i].x=width/2;
        }
        if (Verts[i].y > height/2 ) {
          Verts[i].y=-height/2;
        } else if (Verts[i].y < -height/2) {
          Verts[i].y=height/2;
        }
    
        if (Verts[i].z < -720 ) {  
          Verts[i].z=800/2;
        } else if ( Verts[i].z > 720) {
          Verts[i].z=-800/2;
        }
        tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
    
    
    
    
        //float norX = abs(cos(k)) * randX;
        //float norY = abs(cos(k)) * randY;
        //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
        if (Kin==true) {
          if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          }
        }    
    
    
    
    
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
    
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      rotateY(k);
      noFill();
      stroke(255);
      strokeWeight(7);
      box(width, height, 1920);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      //println(z);
      if (userList.size() < 0) {
        Kin=false;
      }
    
      spout.sendTexture();
      println(Kin);
    }
    
    
    void onNewUser(SimpleOpenNI kinect, int userID) {
    
    
      kinect.startTrackingSkeleton(userID);
    }
    
    //startTracking is alterd 
    void onEndCalibration(int userId, boolean successful) {
      if (successful) {
        println(" User calibrated !!!");
        kinect.startTrackingSkeleton(userId);
      } else {
        println("  Failed to calibrate user !!!");
        kinect.startTrackingSkeleton(userId);
      }
    }
    
    //There is aproblem here,deleted the pose
    
    
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    
Sign In or Register to comment.