- Home /
Projecting kinect coordinates to Unity screen coordinates
I have got the following code which takes the coordinates of the hand in kinect v2 and tries to handle the position of the cursor by using the position of the hand.
Vector2 lastPosition, newPosition;
float smoothingRate = 3f;
void Update(){
bodies = bodyManager.GetData ();
if (bodies!=null) {
rightHandScreenPosition = GetRightHandScreenSpacePosition ();
rightHandScreenPosition = TransformOntoActiveResolution(rightHandScreenPosition);
POINT current = new POINT ();
GetCursorPos (out current);
lastPosition = new Vector2(current.X,current.Y);
newPosition = Vector2.Lerp (lastPosition, rightHandScreenPosition,smoothingRate*Time.deltaTime);
SetCursorPos ((int)newPosition.x, (int)newPosition.y);
}
}
Vector2 TransformOntoActiveResolution (Vector2 rightHandScreenPosition)
{
Vector2 scaledScreenPosition = new Vector2 ((rightHandScreenPosition.x / 1920) * Screen.width, (rightHandScreenPosition.y / 1080) * Screen.height);
return scaledScreenPosition;
}
My issue is that the cursor couldn't reach all the area of the screen but a small area near the tracked body. Any idea about this? Basically in order to be able to browse to the screen I have to move my body. I want to be able to access in all screen without moving my skeleton. Any idea about how can I do this? Basically my answer is how to map kinect coordinates to screen coordinates of the unity project. My function TransformOntoActiveResolution is not seem to work properly.
Your answer
Follow this Question
Related Questions
Adding commands to buttons? 1 Answer
A bit of the scene is cut off in build 0 Answers
click on screen to get the coordinate on the ground(x,z plane) 1 Answer
Why does my screen turn grey when I zoom in? 1 Answer
Title Screen & Scene Help ? 2 Answers