Quantcast
Channel: Kinect - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 530

This is urgent situation!! How to connect between hand postion and mouseX/Y in kinet?

$
0
0

The problem is about connection between hand position and mouseX/mouseY It does work in the computer but the particles doesn't follow my hand position in kinect when I change the mouseX/Y into just x/y. How to change the mouseX/Y as followed by hand position.

I couldn't find the right way

I need some help urgently.

Can you help me how to solve this?

Capture_2016_01_15_16_07_23_952 Capture_2016_01_15_16_07_39_689

import KinectPV2.KJoint; import KinectPV2.*;

int num= 60; PVector [] loc = new PVector [num]; PVector [] dir = new PVector [num]; float [] s = new float [num];

KinectPV2 kinect; Particle Particle = new Particle();

float zVal = 300; float rotX = PI;

void setup() {

smooth(); frameRate(130); size(1024, 768, P3D);

initVariables();

kinect = new KinectPV2(this);

kinect.enableColorImg(true);

//enable 3d with (x,y,z) position kinect.enableSkeleton3DMap(true);

kinect.init(); }

void draw() { //background(0); image(kinect.getColorImage(), 0, 0, 320, 240);

//translate the scene to the center pushMatrix(); //translate(width/2, height/2, 0); //scale(zVal); //rotateX(rotX);

ArrayList skeletonArray = kinect.getSkeleton3d();

//individual JOINTS for (int i = 0; i < skeletonArray.size(); i++) { KSkeleton skeleton = (KSkeleton) skeletonArray.get(i); if (skeleton.isTracked()) { KJoint[] joints = skeleton.getJoints();

  KJoint leftHandJoint = joints[KinectPV2.JointType_HandLeft];
  //TODO: store a reference to this position and use it to draw some graphics.
  PVector leftHandPosition = leftHandJoint.getPosition();
  Particle.draw(leftHandPosition);
  leftHandJoint.getOrientation();


  KJoint rightHandJoint = joints[KinectPV2.JointType_HandRight];
  rightHandJoint.getPosition();
  PVector rightHandPosition = rightHandJoint.getPosition();
  Particle.draw(rightHandPosition);
  rightHandJoint.getOrientation();


  //Draw body
  color col  = skeleton.getIndexColor();
  stroke(col);
}

} popMatrix();

fill(255, 0, 0); text(frameRate, 50, 50); }

void handState(int handState) { switch(handState) { case KinectPV2.HandState_Open: stroke(0, 255, 0); break; case KinectPV2.HandState_Closed: stroke(255, 0, 0); break; case KinectPV2.HandState_Lasso: stroke(0, 0, 255); break; case KinectPV2.HandState_NotTracked: stroke(100, 100, 100); break; } }

public class Particle { public void draw(PVector handPosition) { //map(x, 0, width, 50, 150);

float x = map(handPosition.x, -1, 1, 0, width);
float y = map(handPosition.y, 1, -1, 0, height);

strokeWeight(0);
point(x, y, 10);

fill (#57385c, 50);
noStroke();
rect (0, 0, width, height);


fill (#ffedbc);
int i = 0;
while (i < s.length)
{
  moveBall(loc [i], dir [i], s [i]);
  checkEdges (loc [i], dir [i]);
  drawBall( loc [i]);
  i = i + 1;
}

} } void checkEdges (PVector location, PVector direction) { if (location.x < 0) { location.x = 0; direction.x = direction.x * -1; } if (location.x > width) { location.x = width; direction.x = direction.x * -1; }

if (location.y < 0) { location.y = 0; direction.y = direction.y * -1; } if (location.y > height) { location.y = height; direction.y = direction.y * -1; } }

void moveBall (PVector location, PVector direction, float speed) { float angle = atan2 (y - location.y, x - location.x); PVector target = new PVector ( cos (angle), sin (angle)); target.mult (0.26);

direction.add (target); direction.normalize();

PVector velocity = direction.get(); // kopiert direction velocity.mult (speed); location.add (velocity); }

void drawBall (PVector location) { ellipse (location.x, location.y, 26, 26); }

void initVariables () { int i = 0; while (i < s.length) { PVector location = new PVector (width/2, height/2);

float angle = random (TWO_PI);
PVector direction = new PVector (cos (angle) * 1, sin (angle) * 1);

float speed = random (50, 26);

loc [i] = location;
dir [i] = direction;
s[i] = speed;

i = i + 1;
smooth();

} }

your helps can save my life....


Viewing all articles
Browse latest Browse all 530

Trending Articles