//Within the draw() function, we will update the Kinect data, and then we will set the perspective settings using the functions rotateX(), rotateY() and scale().
void draw(){
kinect.update(); // update the cam
background(255);
translate(width/2, height/2, 0);
rotateX(rotX);
rotateY(rotY);
scale(zoomF);
// Then, we will declare and initialize the necessary variables for the drawing of the point cloud, as we have done in other projects.
int[] depthMap = kinect.depthMap(); // tip – this line will throw an error if your Kinect is not connected
int steps = 3; // to speed up the drawing, draw every third point
int index;
PVector realWorldPoint;
// We will set the rotation center of the scene for visual purposes 1000 in front of the camera, which is close to the distance from the Kinect to the center of the table.
//To make things clearer, let’s mark a point that is in on Kinect’s z-axis (so it’s X and Y are equal to 0). This code is using realWorldMap array, which is an array of 3d coordinates of each screen point, and we’re simply choosing the one that is in the middle of the screen (hence depthWidth/2 and depthHeight/2). As we are in coordinates of Kinect, where (0,0,0) is the sensor itself, we are sampling the depth there, and placing the red cube using the function drawBox(), that we will implement later.
index = kinect.depthWidth()/2 + kinect.depthHeight()/2 * kinect.depthWidth();
// Now, we will display the value of our tableRotation
println("tableRot = " + tableRotation);
// and z cut-off depth
println("cutOffDepth = " + zCutOffDepth);
kinect.drawCamFrustum(); // draw the kinect cam
}
//Within the KeyPressed() callback function, we will add code that will react to pressing key 1 and 2, changing the values of tableRotation by small increments/decrements. We will also be listening for input from the arrow keys to change the point of view.
void keyPressed()
{
switch(key)
{
case '1':
tableRotation -= 0.05;
break;
case '2':
tableRotation += 0.05;
break;
}
switch(keyCode)
{
case LEFT:
rotY += 0.1f;
break;
case RIGHT:
// zoom out
rotY -= 0.1f;
break;
case UP:
if(keyEvent.isShiftDown())
{
zoomF += 0.02f;
}
else
{
rotX += 0.1f;
}
break;
case DOWN:
if(keyEvent.isShiftDown())
{
zoomF -= 0.02f;
if(zoomF < 0.01)
zoomF = 0.01;
}
else
{
rotX -= 0.1f;
}
break;
case '3':
zCutOffDepth -= 5;
break;
case '4':
zCutOffDepth += 5;
break;
}
}
void drawBox(float x, float y, float z, float size)
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(servo1pin, Arduino.OUTPUT);
arduino.pinMode(servo2pin, Arduino.OUTPUT);
arduino.pinMode(servo3pin, Arduino.OUTPUT);
//allocate memory for our path
for(int i = 0; i < 100; i++){
path[i] = new PVector();
}
}
//Within the draw() function, we will update the Kinect data, and then we will set the perspective settings using the functions rotateX(), rotateY() and scale().
void draw(){
kinect.update(); // update the cam
background(255);
translate(width/2, height/2, 0);
rotateX(rotX);
rotateY(rotY);
scale(zoomF);
// Then, we will declare and initialize the necessary variables for the drawing of the point cloud, as we have done in other projects.
int[] depthMap = kinect.depthMap(); // tip – this line will throw an error if your Kinect is not connected
int steps = 3; // to speed up the drawing, draw every third point
int index;
PVector realWorldPoint;
// We will set the rotation center of the scene for visual purposes 1000 in front of the camera, which is close to the distance from the Kinect to the center of the table.
//To make things clearer, let’s mark a point that is in on Kinect’s z-axis (so it’s X and Y are equal to 0). This code is using realWorldMap array, which is an array of 3d coordinates of each screen point, and we’re simply choosing the one that is in the middle of the screen (hence depthWidth/2 and depthHeight/2). As we are in coordinates of Kinect, where (0,0,0) is the sensor itself, we are sampling the depth there, and placing the red cube using the function drawBox(), that we will implement later.
index = kinect.depthWidth()/2 + kinect.depthHeight()/2 * kinect.depthWidth();
// Now, we will display the value of our tableRotation
println("tableRot = " + tableRotation);
// and z cut-off depth
println("cutOffDepth = " + zCutOffDepth);
kinect.drawCamFrustum(); // draw the kinect cam
}
//Within the KeyPressed() callback function, we will add code that will react to pressing key 1 and 2, changing the values of tableRotation by small increments/decrements. We will also be listening for input from the arrow keys to change the point of view.
void keyPressed()
{
switch(key)
{
case '1':
tableRotation -= 0.05;
break;
case '2':
tableRotation += 0.05;
break;
}
switch(keyCode)
{
case LEFT:
rotY += 0.1f;
break;
case RIGHT:
// zoom out
rotY -= 0.1f;
break;
case UP:
if(keyEvent.isShiftDown())
{
zoomF += 0.02f;
}
else
{
rotX += 0.1f;
}
break;
case DOWN:
if(keyEvent.isShiftDown())
{
zoomF -= 0.02f;
if(zoomF < 0.01)
zoomF = 0.01;
}
else
{
rotX -= 0.1f;
}
break;
case '3':
zCutOffDepth -= 5;
break;
case '4':
zCutOffDepth += 5;
break;
}
}
void drawBox(float x, float y, float z, float size)
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(servo1pin, Arduino.OUTPUT);
arduino.pinMode(servo2pin, Arduino.OUTPUT);
arduino.pinMode(servo3pin, Arduino.OUTPUT);
//allocate memory for our path
for(int i = 0; i < 100; i++){
path[i] = new PVector();
}
}
//Within the draw() function, we will update the Kinect data, and then we will set the perspective settings using the functions rotateX(), rotateY() and scale().
void draw(){
kinect.update(); // update the cam
background(255);
translate(width/2, height/2, 0);
rotateX(rotX);
rotateY(rotY);
scale(zoomF);
// Then, we will declare and initialize the necessary variables for the drawing of the point cloud, as we have done in other projects.
int[] depthMap = kinect.depthMap(); // tip – this line will throw an error if your Kinect is not connected
int steps = 3; // to speed up the drawing, draw every third point
int index;
PVector realWorldPoint;
// We will set the rotation center of the scene for visual purposes 1000 in front of the camera, which is close to the distance from the Kinect to the center of the table.
//To make things clearer, let’s mark a point that is in on Kinect’s z-axis (so it’s X and Y are equal to 0). This code is using realWorldMap array, which is an array of 3d coordinates of each screen point, and we’re simply choosing the one that is in the middle of the screen (hence depthWidth/2 and depthHeight/2). As we are in coordinates of Kinect, where (0,0,0) is the sensor itself, we are sampling the depth there, and placing the red cube using the function drawBox(), that we will implement later.
index = kinect.depthWidth()/2 + kinect.depthHeight()/2 * kinect.depthWidth();
// Now, we will display the value of our tableRotation
println("tableRot = " + tableRotation);
// and z cut-off depth
println("cutOffDepth = " + zCutOffDepth);
kinect.drawCamFrustum(); // draw the kinect cam
}
//Within the KeyPressed() callback function, we will add code that will react to pressing key 1 and 2, changing the values of tableRotation by small increments/decrements. We will also be listening for input from the arrow keys to change the point of view.
void keyPressed()
{
switch(key)
{
case '1':
tableRotation -= 0.05;
break;
case '2':
tableRotation += 0.05;
break;
}
switch(keyCode)
{
case LEFT:
rotY += 0.1f;
break;
case RIGHT:
// zoom out
rotY -= 0.1f;
break;
case UP:
if(keyEvent.isShiftDown())
{
zoomF += 0.02f;
}
else
{
rotX += 0.1f;
}
break;
case DOWN:
if(keyEvent.isShiftDown())
{
zoomF -= 0.02f;
if(zoomF < 0.01)
zoomF = 0.01;
}
else
{
rotX -= 0.1f;
}
break;
case '3':
zCutOffDepth -= 5;
break;
case '4':
zCutOffDepth += 5;
break;
}
}
void drawBox(float x, float y, float z, float size)