Search code examples
c#unity-game-enginekinectkinect-sdk

How to convert Kinect ColorSpacePoint in Unity WorldPoint


PreInformation: Using Kinect v2 and Unity3D v5.4

Background: I have programmatically created GameObject objects, like Cubes and Spheres. The Position of these GameObject items I'm setting with: gameObject.transform.position. With the Kinect I'm detecting the current Handposition of the user. What I want to do is to check if the Handposition is near the position of the created GameObject.

Problem: My Problem right now is how I can convert the handposition. The handposition I converted from CameraSpacePoint to ColorSpacePoint:

ColorSpacePoint csPoint=_Sensor.CoordinateMapper.MapCameraPointToColorSpace(handPosition);

How can I convert these ColorSpacePoint objects now to the Unity positions(transform.position)?


Solution

  • cspoint and transform.position are both two different types of vectors: cspoint is a 2d vector, transform.position a 3d vector.

    So, what you'll need is a convert function.

    Vector3 toUnityVector3(ColorSpacePoint point)
    {
       return new Vector3(point.x,point.y,0); //swap the parameters around as you see fit
    }