Hi everybody,
has someone already connected the new Kinect for Windows to Greenfoot successfully?
Thank you
Steffen
// KinectWorld.java
// Include in BlueJ preferences, tab 'Libraries':
// jaw.jar
// KinectJLib.jar
// KinectHandler.dll (or for 64-bit Java: KinectHandler64.dll) must reside in path, e.g. c:\windows
import greenfoot.*;
import ch.aplu.jaw.*;
import ch.aplu.kinect.*;
public class KinectWorld extends World
{
String dllPath = Kinect.is64bit()? "KinectHandler64" : "KinectHandler";
String title = "Greenfoot Kinect Video Frame - Paint with your right hand - Raise left hand to erase";
int ulx = 10; // Upper left x of window
int uly = 20; // Upper left y of window
int width = 600; // Width of window in pixels
int height = 400; // Height of window in pixels
static int xRightHand = 1000;
static int yRightHand = 1000;
static int yLeftHand = 1000;
public KinectWorld()
{
super(600, 400, 1);
Painter p = new Painter();
addObject(p, 300, 200);
Greenfoot.setSpeed(50);
Greenfoot.start();
new Thread()
{
public void run()
{
runKinect();
}
}.start();
}
void runKinect()
{
Kinect kinect = new Kinect(dllPath, title, ulx, uly, width, height,
NativeHandler.WS_BORDER | NativeHandler.WS_VISIBLE);
Point3D[] joints = new Point3D[20];
for (int i = 0; i < 20; i++)
joints[i] = new Point3D();
while (true)
{
int skeletonId = kinect.getJoints(joints, 20); // Blocks max 200 ms
if (skeletonId > -1) // Valid skeleton
{
int rightHandIndex = SkeletonJoint.HAND_RIGHT.ordinal();
xRightHand = joints[rightHandIndex].x;
yRightHand = joints[rightHandIndex].y;
int leftHandIndex = SkeletonJoint.HAND_LEFT.ordinal();
yLeftHand = joints[leftHandIndex].y;
}
else // No valid skeleton
{
xRightHand = 1000;
yRightHand = 1000;
yLeftHand = 1000;
}
}
}
}
// Painter.java
import greenfoot.*;
public class Painter extends Actor
{
public Painter()
{
setImage(new GreenfootImage(600, 400));
getImage().setColor(java.awt.Color.GREEN);
}
public void act()
{
if (KinectWorld.yLeftHand < 100)
getImage().clear();
else
getImage().fillOval(KinectWorld.xRightHand, KinectWorld.yRightHand, 20, 20);
}
}