Second image doesnt dissapear

edited September 2016 in Kinect

Hello,i have this code with two image appearing as instruction,the first appears and dissapears well,but the second image doesnt disappear,i want to be disappear after some seconds,but it doesnt work,i tried boolean,framecount,custom count.but it doesnt disappear.I think maybe the problem is the if tracking statement.

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

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

Spout spout;

SimpleOpenNI kinect;

PeasyCam cam;

float z=0;

float r;
float k;
int VertCount;
PVector[] Verts;
PVector[] locas;
PVector[] Bez;
PVector[] Bez2;
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;

boolean Text1;
boolean Text2;

PImage img;
PImage img2;


int Tmeter=0;

int VECS = 800;


void setup()
{
  size(1920, 1440, P3D);

  //hypotenuse 2450

  frameRate(30);
  noStroke();

  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();
  kinect.enableUser();

  //800*800-->200,1920*1440-->300
  model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  model.enableDebug();
  model.scale(300);
  model.translateToCenter();


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


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

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

  cam = new PeasyCam(this, width/2, height/2, 0, 2610);
  //800*800 --> cam 1600,1920*1440--> cam 2610
  spout = new Spout(this);
  spout.createSender("Self kinect");

  img = loadImage("Text1.png");
  img2 = loadImage("Text2.png");
}



void draw()
{
  background(0);
  pointLight(255, 255, 255, 
  width/2, height/2, width*2);

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

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



  PVector psVerts[] = new PVector[VECS];
  PVector psVerts2[]= new PVector[VECS];


  cam.setMouseControlled(false);

  if (userList.size() <= 0) {
    Text1 = false;
    Text2= false;
    Tmeter=0;
  }

  if (userList.size() > 0) {


    int userId = userList.get(0);
    Text1 = true;

    if ( kinect.isTrackingSkeleton(userId)) {



      Kin= true;


      Text1 = false;


      Text2=true;



      pushMatrix();
      translate(0, 0, 1255);
      //the hypotenuse

      image(img2, 0, 0);

      popMatrix();
      Tmeter+=1;


      if (Tmeter>=10 ) {
        Text2=false;
        //print("ok");
        //print(Text2);
      }

      print(Tmeter);

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






      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();
      //-----------------HERE
      translate(Mouse2.x, Mouse2.y, Mouse2.z);
      //-------------AND HERE
      noFill();
      stroke(255);
      strokeWeight(3);
      box(r, r, 2450);
      popMatrix();



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


      popMatrix();
    }
  }

  pushMatrix();




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



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





    //+4 for 1920*1440
    float randX = noise(randomGaussian())+4;
    float randY = noise(randomGaussian())+4;
    float randZ = noise(randomGaussian())+4;

    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 < -width/2 ) {  
      Verts[i].z=800/2;
    } else if ( Verts[i].z > width/2) {
      Verts[i].z=-width/2;
    }


    pushMatrix();
    translate(width/2, height/2, 0);
    rotateY(k);
    tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
    popMatrix();




    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  - 1225 && Verts[i].z <  Mouse.z  + 1225)||(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  - 1225 && Verts[i].z <  Mouse2.z  + 1225)) {




        pushMatrix();
        rotateY(k);


        tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
        popMatrix();
      }
    }
  }




  rotateY(k);
  noStroke();
  tmpmodel.draw();








  popMatrix();
  if (Text1==true) {

    pushMatrix();
    translate(0, 0, 1255);
    //the hypotenuse

    image(img, 0, 0);

    popMatrix();
  }





  spout.sendTexture();
  //println(Tmeter);
}




void onNewUser(SimpleOpenNI kinect, int userID) {
  kinect.startTrackingSkeleton(userID);
}


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

Answers

  • That code is way too long, most people will not read all of it.
    Why not post only the relevant parts of code?

  • I didn't read all of it, but I think the problem is where you are drawing the images. Image 1 is drawn only if that "Text1" variable is true, why not something similar for image2?

  • Hey mate,i didnt put the second image at all,for the presentation,i think that the problem is that the if tracking runs continously

Sign In or Register to comment.