Loading...
Logo
Processing Forum
i am trying to track the user's CoM ("center of mass") via kinect and the SimpleOpenNI library 
and then attaching the rotation of a 3D object to the PVector of the CoM of the user... 
essentially I am trying to make it so that when i move around there is a 3D object following my movements by rotating back and forth...

this is the code i have so far but i am having trouble with it. ... 
the object will appear in the far top right corner, which has to do with model orientation i am sure...
but i also tried model.rotation, and using rotation instead of model orientation.. i got glitchy results with the object scaling back and forth based on position of the CoM...

any suggestions, i know there must be a more simple way to do this...
thanks...




import processing.opengl.*;
import saito.objloader.*;
import SimpleOpenNI.*;
SimpleOpenNI kinect;

//declare object called model
OBJModel model;
float rotX;
float rotY;
float rotZ;

int Scal = 40;

void setup()
{
    size(600, 600, OPENGL);
    smooth();
    // making an object called "model" that is a new instance of OBJModel
    model = new OBJModel(this, "bone.obj", "relative", TRIANGLES);
    model.load("bone.obj");
    stroke(255);
 
    // turning on the debug output (it's all the stuff that spews out in the black box down the bottom)
    model.enableDebug();

    model.scale(Scal);

    noStroke();

  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();
  kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);
}
  
  
  
void draw()
{
    background(255);
    lights();

  kinect.update();
  IntVector userList = new IntVector();
  kinect.getUsers(userList);
  
  for (int i=0; i<userList.size(); i++) {
    int userId = userList.get(i);
 
  PVector position = new PVector();
  kinect.getCoM(userId, position);
  
  PVector modelOrientation = new PVector(1,0,0);
  float angle = acos(modelOrientation.dot(position));
  PVector axis = modelOrientation.cross(position);
  
  
    pushMatrix();
    translate(position.x, position.y, position.z);
    rotateX(rotX);
    rotateY(rotY);
    rotateZ(rotZ);
    //rotate(angle, axis.x, axis.y, axis.z);
    model.draw();

    popMatrix();
  }

Replies(1)

Hi ghrls!
I got this to work!!!! check it out!!


here is the code i figured out:

import SimpleOpenNI.*;
import processing.opengl.*;
import saito.objloader.*;

SimpleOpenNI kinect;

//declare object called model
OBJModel model;
float rotX;
float rotY; 
float rotZ;
 



void setup()
{
    size(600, 600, OPENGL);
    smooth();
    frameRate(30);//change
    model = new OBJModel(this, "bone.obj", "absolute", TRIANGLES);
    model.load("bone.obj");
    stroke(255);
 
  
    model.enableDebug();

    model.scale(40);
    model.translateToCenter();//change
    noStroke();

  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();
  kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);
}
  
  
  
void draw()
{
    background(255);
    lights();
    
   
  kinect.update();
  IntVector userList = new IntVector();
  kinect.getUsers(userList);
  
  for (int i=0; i<userList.size(); i++) {
    int userId = userList.get(i);
 
  PVector userposition = new PVector();
  kinect.getCoM(userId, userposition);
  
  PVector modelrotation = new PVector(userposition.x,userposition.y,userposition.z);
  //float angle = acos(modelrotation.dot(userposition));
  //PVector axis = modelrotation.cross(userposition);
  
   pushMatrix();
    translate(width/2, height/2, 0);
    rotateX(radians(modelrotation.x));
    rotateY(radians(modelrotation.y));
    rotateZ(radians(modelrotation.z));
    model.draw();

    popMatrix();
    
  }






HOWEVER, it runs really slowly and not smoothly at all. Lots of kinks to work out. Let me know if you have any advice for cleaning up this code...