saito obj loader (OpenGL)+ SimpleOpenNI= help needed!!!?!?!
in
Contributed Library Questions
•
1 year ago
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();
}
1