PBox 2D

edited May 2016 in Kinect

Hello ! I need library PBox 2D master to work with the kinect . All that meeting did not work , install , but the sketch always says missing library in question. Someone can help me?

Tagged:

Answers

  • post your code

  • did you download and install the lib?

  • edited May 2016
    import pbox2d.*;
    import org.jbox2d.common.*;
    import org.jbox2d.dynamics.joints.*;
    import org.jbox2d.collision.shapes.*;
    import org.jbox2d.collision.shapes.Shape;
    import org.jbox2d.common.*;
    import org.jbox2d.dynamics.*;
    import org.jbox2d.dynamics.contacts.*;
    
    import SimpleOpenNI.*;
    
    SimpleOpenNI kinect;
    PBox2D box2d;
    Box box_left_hand, box_right_hand;
    Spring spring_left_hand, spring_right_hand;
    ArrayList<Particle> particles = new ArrayList<Particle>();
    
    void setup() {
      kinect = new SimpleOpenNI( this );
      kinect.enableDepth();
      kinect.enableUser( SimpleOpenNI.SKEL_PROFILE_ALL );
      kinect.setMirror( true );
      size( int( kinect.depthWidth() * 1.5 ), int( kinect.depthHeight() * 1.5 ));
    
      box2d = new PBox2D( this );
      box2d.createWorld();
      box2d.setGravity( 0, -20 );
      box2d.listenForCollisions();
    
      box_left_hand = new Box( (width / 2) + 50, height / 2 );
      box_right_hand = new Box( (width / 2) - 50, height / 2 );
    
      spring_left_hand = new Spring();
      spring_left_hand.bind( (width / 2) + 50, height / 2, box_left_hand );
      spring_right_hand = new Spring();
      spring_right_hand.bind( (width / 2) - 50, height / 2, box_right_hand );
    }
    
    void draw() {
      scale( 1.5 );
      background( 0 );
      kinect.update();
      //image( kinect.depthImage(), 0, 0 );
      int[] user_list = kinect.getUsers();
      if ( user_list.length > 0 ) {
        if ( kinect.isTrackingSkeleton( user_list[0] ) ) {
          box2d.step ();
    
          drawSkeleton( user_list[0] );
    
          if ( particles.size() < 10 ) {
            particles.add( new Particle( random( 20, kinect.depthWidth() - 20 ), -20 ) ); 
          }
          for ( int i = particles.size() - 1; i >= 0; --i ) {
            Particle _particle = particles.get( i );
            if ( !_particle.done() ) {
              _particle.display();
            }
            else {
              particles.remove( i );   
            }
          }  
        }
      }
    }
    
    void drawSkeleton( int user_id ) {
      PVector temp_joint = new PVector();
    
      //Remember: left is right & right is left
      PVector user_head = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_HEAD, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_head );
      PVector user_neck = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_NECK, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_neck );
      PVector user_left_shoulder = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_LEFT_SHOULDER, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_left_shoulder );
      PVector user_left_elbow = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_LEFT_ELBOW, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_left_elbow );
      PVector user_left_hand = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_LEFT_HAND, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_left_hand );
      PVector user_right_shoulder = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_RIGHT_SHOULDER, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_right_shoulder );
      PVector user_right_elbow = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_RIGHT_ELBOW, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_right_elbow );
      PVector user_right_hand = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_RIGHT_HAND, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_right_hand );
      PVector user_torso = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_TORSO, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_torso );
      PVector user_left_hip = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_LEFT_HIP, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_left_hip );
      PVector user_left_knee = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_LEFT_KNEE, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_left_knee );
      PVector user_left_foot = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_LEFT_FOOT, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_left_foot );
      PVector user_right_hip = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_RIGHT_HIP, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_right_hip );
      PVector user_right_knee = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_RIGHT_KNEE, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_right_knee );
      PVector user_right_foot = new PVector();
      kinect.getJointPositionSkeleton( user_id, SimpleOpenNI.SKEL_RIGHT_FOOT, temp_joint );
      kinect.convertRealWorldToProjective( temp_joint, user_right_foot );
    
      stroke( #FFF64B );
      strokeWeight( 5 );
      line( user_head.x, user_head.y, user_neck.x, user_neck.y ); 
      line( user_left_shoulder.x, user_left_shoulder.y, user_neck.x, user_neck.y );
      line( user_left_shoulder.x, user_left_shoulder.y, user_left_elbow.x, user_left_elbow.y );
      line( user_left_hand.x, user_left_hand.y, user_left_elbow.x, user_left_elbow.y );
      line( user_right_shoulder.x, user_right_shoulder.y, user_neck.x, user_neck.y );
      line( user_right_shoulder.x, user_right_shoulder.y, user_right_elbow.x, user_right_elbow.y );
      line( user_right_hand.x, user_right_hand.y, user_right_elbow.x, user_right_elbow.y );
      line( user_left_shoulder.x, user_left_shoulder.y, user_torso.x, user_torso.y );
      line( user_right_shoulder.x, user_right_shoulder.y, user_torso.x, user_torso.y );
      line( user_left_hip.x, user_left_hip.y, user_torso.x, user_torso.y );
      line( user_left_hip.x, user_left_hip.y, user_left_knee.x, user_left_knee.y );
      line( user_left_knee.x, user_left_knee.y, user_left_foot.x, user_left_foot.y );
      line( user_right_hip.x, user_right_hip.y, user_left_hip.x, user_left_hip.y );
      line( user_right_hip.x, user_right_hip.y, user_torso.x, user_torso.y );
      line( user_right_hip.x, user_right_hip.y, user_right_knee.x, user_right_knee.y );
      line( user_right_knee.x, user_right_knee.y, user_right_foot.x, user_right_foot.y );
    
      noStroke();
      fill( #FF0000 );
      ellipse( user_head.x, user_head.y, 5, 5 );
      ellipse( user_neck.x, user_neck.y, 5, 5 );
      ellipse( user_left_shoulder.x, user_left_shoulder.y, 5, 5 );
      ellipse( user_left_elbow.x, user_left_elbow.y, 5, 5 );
      ellipse( user_right_shoulder.x, user_right_shoulder.y, 5, 5 );
      ellipse( user_right_elbow.x, user_right_elbow.y, 5, 5 );
      ellipse( user_torso.x, user_torso.y, 5, 5 );
      ellipse( user_left_hip.x, user_left_hip.y, 5, 5 );
      ellipse( user_left_knee.x, user_left_knee.y, 5, 5 );
      ellipse( user_left_foot.x, user_left_foot.y, 5, 5 );
      ellipse( user_right_hip.x, user_right_hip.y, 5, 5 );
      ellipse( user_right_knee.x, user_right_knee.y, 5, 5 );
      ellipse( user_right_foot.x, user_right_foot.y, 5, 5 );
    
      spring_left_hand.update( user_left_hand.x, user_left_hand.y );
      box_left_hand.display();
      spring_right_hand.update( user_right_hand.x, user_right_hand.y );
      box_right_hand.display();
    }
    
    // user-tracking callbacks!
    void onNewUser( int userId ) { 
      println( "Start pose detection" );
      kinect.startPoseDetection( "Psi", userId ); 
    }
    
    void onStartPose( String pose, int userId ) { 
      println( "Start pose detected. Starting calibration" );
      kinect.stopPoseDetection( userId );
      kinect.requestCalibrationSkeleton( userId, true ); 
    }
    
    void onEndCalibration( int userId, boolean successful ) {
      if ( successful ) { 
        println( "User calibrated !!!" ); 
        kinect.startTrackingSkeleton( userId ); 
      }  
      else { 
        println( "Failed to calibrate user !!!" );
        kinect.startPoseDetection( "Psi", userId );
      }
    }
    
    //box2d collition callbacks
    void beginContact( Contact cp ) {
      Fixture f1 = cp.getFixtureA();
      Fixture f2 = cp.getFixtureB();
    
      Body b1 = f1.getBody();
      Body b2 = f2.getBody();
    
      Object o1 = b1.getUserData();
      Object o2 = b2.getUserData();
    
      if ( o1.getClass() == Box.class && o2.getClass() == Particle.class ) {
        Particle _particle = (Particle) o2;
        _particle.changeColor();
      }
    
      if ( o2.getClass() == Box.class && o1.getClass() == Particle.class ) {
        Particle _particle = (Particle) o1;
        _particle.changeColor();
      } 
    }
    
    void endContact( Contact cp ) {
    }
    
  • edited May 2016

    Not against library PBox 2D . She changed her name? Already tried to install , but says: "the package "pbox2d" does not exist...

  • did you try menue the manager?

  • I did not understand ! What is this? I am a student and need to make a program work. I'm not a programmer , I'm still learning , sorry ! But this is very important for my final project.

  • I'm having thesame problem did you resolve it?

  • @MRASH420 --

    1. What is the exact error message you are getting?
    2. Did you already download and install the missing library, and if so how?
  • @jeremeydouglass

    ive downloaded everything to do with pbox, jbox and box2d but nothing works im using the sketch from https://kinectsen.wikispaces.com/Processing+Kinect+Resources and the code is called kinect physics.

  • What is the exact error message you are getting?

  • After you install any libraries in Processing, I would run the provided examples to ensure the libraries are set properly. Then I will try running any other external code. Try running the examples first and if you get any errors, copy and paste the error you get here as part of your post. The more details you provide, the easier for forum goers to get back to you with quality feedback.

    Kf

  • it says the class Pbox2d does not exist?

  • ive saved many library downloads of pbox2d and saved them into (library)-(sketchbook) ill send the hyperlink of the sketch im using please help

  • edited February 2017

    Try using "import shiffman/box2D.*" instead of import PBox2D".

Sign In or Register to comment.