求问!能获取世界坐标,但是用camera.main,WorldToScreenPoint()后,屏幕坐标x=NaN,不知道怎么回事

qq_36474498 2017-10-11 11:14:59
我是新手,通过水果忍者游戏教学视频学习U3D,发现红色方块没法追踪右手运动,而且锚点在屏幕左下角,然后发现是世界坐标转换到屏幕坐标的时候出现问题的,x、y坐标都是0,后来修改摄像机参数,忘了改了啥坐标又变成x=NaN,y=582了,红色方块还是不动。下面是部分程序:

if(KinectManager.Instance.IsUserDetected())
{
//User is detected.
long userId = KinectManager.Instance.GetPrimaryUserID();//Get user's ID.
int JointType=(int)KinectInterop.JointType.HandRight;//Righthand is the detected joint.

if(KinectManager.Instance.IsJointTracked(userId,JointType))
{

Vector3 rightHandPos = KinectManager.Instance.GetJointPosition(userId,JointType);
Vector3 rightHandScreenPos = Camera.main.WorldToScreenPoint(rightHandPos);
print("rHPx= "+rightHandPos.x+" rHPy= "+rightHandPos.y+" rHPz= "+rightHandPos.z);
print("rHSx= "+rightHandScreenPos.x+" rHSy= "+rightHandScreenPos.y+" rHSz= "+rightHandScreenPos.z);
Vector2 rightHandSenPos = new Vector2( rightHandScreenPos.x, rightHandScreenPos.y);
Vector2 rightHandUguiPos;

if(RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)canvas.transform, rightHandSenPos, null, out rightHandUguiPos))
{
//Right hand is in the rectangle of canvas.
RectTransform rightRectTf = rightHand.transform as RectTransform ;
rightRectTf.anchoredPosition = rightHandUguiPos ;

}

}
}

...全文
571 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,537

社区成员

发帖
与我相关
我的任务
社区描述
Unity3D相关内容讨论专区
游戏unity 技术论坛(原bbs)
社区管理员
  • Unity3D
  • 芝麻粒儿
  • 「已注销」
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

Unity3D社区公告:

  1. 社区致力于解决各种Unity3D相关的“疑难杂症”。
  2. 社区不允许发布与Unity3D或相关技术无关内容。
  3. 社区版主邀请各位一道为打造优秀社区不懈努力。

试试用AI创作助手写篇文章吧