using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/***Kinect坐标转换为屏幕坐标***/
public class KinectPointToScreenPoint
{
public static Vector3 Rec(KinectInterop.JointType trackedJoint)
{
KinectManager manager = KinectManager.Instance;
if (manager && manager.IsInitialized())
{
int iJointIndex = (int)trackedJoint;
if (manager.IsUserDetected())
{
long userId = manager.GetPrimaryUserID();
if (manager.IsJointTracked(userId, iJointIndex))
{
Vector3 jointPosV3 = manager.GetJointKinectPosition(userId, iJointIndex);
if (jointPosV3 != Vector3.zero)
{
//3d position to depth
Vector2 depthPos = manager.MapSpacePointToDepthCoords(jointPosV3);
ushort depthValue = manager.GetDepthForPixel((int)depthPos.x, (int)depthPos.y);
if (depthValue > 0)
{
//depth pos to color pos
Vector2 colorPos = manager.MapDepthPointToColorCoords(depthPos, depthValue);
float xNorm = (float)colorPos.x / manager.GetColorImageWidth();
float yNorm = 1.0f - (float)colorPos.y / manager.GetColorImageHeight(); //视口坐标
Vector3 v3 = Camera.main.ViewportToScreenPoint(new Vector3(xNorm, yNorm, 0));
return v3;
}
}
}
}
}
return Vector3.zero;
}
}
Kinect for Unity中 角色相对与Kinect设备的位置到屏幕中坐标位置的转换
最新推荐文章于 2022-11-28 15:28:16 发布