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

openKinect + Fisica. movement

$
0
0

Hello. Before I ask nothing, i mean 2 things. 1. My native language is Spanish and 2. I'm not a professional programmer, I'm learning. So please excuse my car for all the gramatical errors and programming errors or the messy code.

Ok, I want to make some "organisms", that move alone, and then when someone is closer to the kinect, can modify the movement of these "organisms" For this, I been using fisica library and openKinect library, but I can't move them with the data taken from the kinect.

this is my code

Thanks for any help.


/*BASADO EN TUTORIAL DANIERL SHIFFMAN */

import org.openkinect.processing.*;

Kinect kinect; PImage img; float minThresh = 485; float maxThresh = 770;

import fisica.*; FWorld world;

int cantidad = 10; ArrayList noctilucas;

FBox box;

void setup(){

size(640, 520, P3D); kinect = new Kinect(this); kinect.initDepth(); img = createImage(kinect.width, kinect.height, RGB);

//---------MUNDO... Fisica.init(this); world = new FWorld(); world.setGravity(0, 0); world.setEdges();

box = new FBox(60,60);

noctilucas = new ArrayList ();

for (int i = 0; i < cantidad; i ++) { Noctilucas n = new Noctilucas(); world.add(n); noctilucas.add(n); n.crea(32, 233, 245); }

}

void draw(){

background(0);

img.loadPixels();

/calibración de profundidad la kinect versiión 1 o 1414 tiene los valores entre cero y.... para modificar las variables min y maxThresh/ // minThresh = map(mouseX, 0, width, 0, 4500); //maxThresh = map(mouseY, 0, height, 0, 4500); //println(minThresh, maxThresh);

int[] depth = kinect.getRawDepth();

/cantidad de pixeles en X, cantidad de pixeles en Y suma total de todos los pixeles en X y Y/

float sumX = 0; float sumY = 0; float totalPixels = 0;

//buscar la profundidad de cada pixel

for (int x = 0; x < kinect.width; x++){ for(int y = 0; y < kinect.height; y++){

  int offset = x + y * kinect.width;
  float d = depth[offset];

  //espacio minimo y máximo. dentro del que
  //debe estar el interactor.

  if(d > minThresh && d < maxThresh && x > 105){

  /*pixeles que están entre el minimo
  y máximo threshold (profundidad) violeta*/

  img.pixels[offset] = color(255, 0 , 150);

  /*sumando a cada pixel un pixel de los
  que están dentro de la profundidad elegida
  en X y Y*/

  sumX += x;
  sumY += y;
  totalPixels++;

}else{

    img.pixels[offset] = color(0);
  }
}

}

img.updatePixels(); image(img, 0, 0);

/avg es la variable para el promedio/

float avgX = sumX / totalPixels; float avgY = sumY / totalPixels; fill(150, 0, 255); //ellipse(avgX, avgY, 64, 64);

for (int i = noctilucas.size()-1; i>= 0; i --) { Noctilucas n = noctilucas.get(i); n.movimiento(); n.kinectDepth(avgX, avgY); }

world.step(); world.draw(); }

//-------class Noctilucas------- class Noctilucas extends FBlob {

float s = random(10, 20 ); float x, y;

Noctilucas() {

super();

}

void crea(color r, color g, color b) {

x = width/2-200 + random(-5, 5);
y = height/2-10 + random(-5, 5);

setAsCircle(random(x - 10), random(y - 10), s, 10);
setStroke(r, g, b);
setStrokeWeight(1);
//setNoStroke();
setFill(94, 133, 157, 70);
setGrabbable(false);
setName("hijas");

}

void movimiento() {

if (frameCount % 2 == 0)
{
  x = random(-70, 70);
  y = random(-30, 30);


  addForce(x, y);
}

}

void kinectDepth(float mX, float mY) {

setPosition(mX, mY);

} }


Viewing all articles
Browse latest Browse all 530

Trending Articles