private Vector3 GetVector3FromJoint(Kinect.Joint joint) { var valid = joint.TrackingState != Kinect.TrackingState.NotTracked; if (ConvertCamera != null || valid) { // KinectのCamera座標系(3次元)をColor座標系(2次元)に変換する var point = _CoordinateMapper.MapCameraPointToColorSpace(joint.Position); var point2 = new Vector3(point.X, point.Y, 0); if ((0 <= point2.x) && (point2.x < _KinectWidth) && (0 <= point2.y) && (point2.y < _KinectHeight)) { // スクリーンサイズで調整(Kinect->Unity) point2.x = point2.x * Screen.width / _KinectWidth; point2.y = point2.y * Screen.height / _KinectHeight; // Unityのワールド座標系(3次元)に変換 var colorPoint3 = ConvertCamera.ScreenToWorldPoint(point2); // 座標の調整 // Y座標は逆、Z座標は-1にする(xもミラー状態によって逆にする必要あり) colorPoint3.y *= -1; colorPoint3.z = -1; return(colorPoint3); } } return(new Vector3(joint.Position.X * 10, joint.Position.Y * 10, -1)); //joint.Position.Z * 10 }
private Vector3 GetVector3FromJoint(Kinect.Joint joint) { // 変換用カメラがあり、関節がトラッキング中 if (ConvertCamera != null || (joint.TrackingState != Kinect.TrackingState.NotTracked)) { // 関節座標をカラー画像座標に変換 var kinectColorPoint = _CoordinateMapper.MapCameraPointToColorSpace(joint.Position); // Kinectカラー座標からUnity座標に変換 Vector3 unityPoint = new Vector3(kinectColorPoint.X, kinectColorPoint.Y, 0); if ((0 <= unityPoint.x) && (unityPoint.x < _KinectWidth) && (0 <= unityPoint.y) && (unityPoint.y < _KinectHeight)) { // スクリーンサイズを調整 unityPoint.x = unityPoint.x * Screen.width / _KinectWidth; unityPoint.y = unityPoint.y * Screen.height / _KinectHeight; // Unityの座標に変換(同じ大きさに合わせた変換用カメラを使用) Vector3 colorPoint3 = ConvertCamera.ScreenToWorldPoint(unityPoint); // 向きを合わせる colorPoint3.y *= -1; colorPoint3.z = -1; return(colorPoint3); } } // ない場合仕方なく今まで通り return(new Vector3(joint.Position.X * 10, joint.Position.Y * 10, -1)); }
private Vector3 GetVector3FromJoint(Kinect.Joint joint) { var valid = joint.TrackingState != Kinect.TrackingState.NotTracked; if (_cameraForCoordinatemap != null || valid) { // KinectのCamera座標系(3次元)をColor座標系(2次元)に変換する var point = _CoordinateMapper.MapCameraPointToColorSpace(joint.Position); var point2 = new Vector3(point.X, point.Y, 0); if ((0 <= point2.x) && (point2.x < SensorWidth) && (0 <= point2.y) && (point2.y < SensorHeight)) { // スクリーンサイズで調整(Kinect->Unity) point2.x = point2.x * Screen.width / SensorWidth; point2.y = point2.y * Screen.height / SensorHeight; // Unityのワールド座標系(3次元)に変換 var colorPoint3 = _cameraForCoordinatemap.ScreenToWorldPoint(point2); // 座標の調整 // Y座標は逆、Z座標は0にする(Xもミラー状態によって逆にする必要あり) colorPoint3.y *= -1; colorPoint3.z = 0; return(colorPoint3); } } // 適当に返す return(new Vector3(joint.Position.X * 10, joint.Position.Y * 10, 0)); }
private Vector3 GetVector3FromJoint(Kinect.Joint joint) { var valid = joint.TrackingState != Kinect.TrackingState.NotTracked; if (ConvertCamera == null && !valid) { return(new Vector3(joint.Position.X * 10, joint.Position.Y * 10, -1)); } var point = _CoordinateMapper.MapCameraPointToColorSpace(joint.Position); var point2 = new Vector3(point.X, point.Y, 0); if (!((0 <= point2.x) && (point2.x < _KinectWidth) && (0 <= point2.y) && (point2.y < _KinectHeight))) { return(new Vector3(joint.Position.X * 10, joint.Position.Y * 10, -1)); } point2.x = point2.x * Screen.width / _KinectWidth; point2.y = point2.y * Screen.height / _KinectHeight; var colorPoint = ConvertCamera.ScreenToWorldPoint(point2); colorPoint.y *= -1; colorPoint.z = -1; return(colorPoint); }
private Vector3 GetVector3FromJoint(Kinect.CoordinateMapper mapper, Kinect.Joint joint) { Kinect.ColorSpacePoint colorPoint = mapper.MapCameraPointToColorSpace(joint.Position); //Debug.Log("Position of " + joint.JointType.ToString() + ": " + joint.Position.X + "," + joint.Position.Y + "," + joint.Position.Z); float newX = (joint.Position.X * 10); float newY = joint.Position.Y * 10; return(new Vector3(newX, newY, gameObject.transform.position.z - (joint.Position.Z * 10))); }
private void UpdateClothHandlers(Kinect.Body body) { foreach (AbstractClothHandler handler in clothHandlers) { for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++) { if (jt != handler.jointType) // If it's not the joint the handler wants, { continue; // Skip! } Kinect.Joint joint = body.Joints[jt]; Kinect.CoordinateMapper mapper = _BodyManager.Sensor().CoordinateMapper; Kinect.ColorSpacePoint screenPos = mapper.MapCameraPointToColorSpace(joint.Position); Vector3 jointPos = new Vector3(screenPos.X, screenPos.Y, joint.Position.Z); // Z should be distance to kinect plane //Vector3 legacy = GetVector3FromJoint(_BodyManager.Sensor().CoordinateMapper, joint); handler.UpdatePosition(body.TrackingId, joint, jointPos); } } }
private Vector3 GetVector3FromJoint(Kinect.Joint joint) { bool valid = joint.TrackingState != Kinect.TrackingState.NotTracked; if (convert_camera_ != null || valid) { Kinect.ColorSpacePoint point = coordinate_mapper_.MapCameraPointToColorSpace(joint.Position); Vector3 point2 = new Vector3(point.X, point.Y, 0); if ((point2.x >= 0) && (point2.x < kKinectWidth) && (point2.y >= 0) && (point2.y < kKinectHeight)) { point2.x = point2.x * Screen.width / kKinectWidth; point2.y = point2.y * Screen.height / kKinectHeight; Vector3 color_point3 = convert_camera_.ScreenToWorldPoint(point2); color_point3.y *= -1; color_point3.z = -1; return(color_point3); } } return(new Vector3(joint.Position.X * 10, joint.Position.Y * 10, joint.Position.Z * 10)); }
// Update is called once per frame void Update() { if (DEBUG) { // Mouse Mode mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); transform.position = new Vector3(mousePos.x, mousePos.y); if (Input.GetMouseButtonDown(0) && !isHandRightClosed) { isHandRightClosed = true; m_animator.SetBool("handclosebool", true); KillMosquito(); } else if (Input.GetMouseButtonUp(0) && isHandRightClosed) { isHandRightClosed = false; m_animator.SetBool("handclosebool", false); } } else { // Fetch Body[] Information every time update() called bodies = bodyManager.GetBodies(); if (bodies == null) { bodyID = -1; } else if (bodyID == -1 || bodies[bodyID].IsTracked == false) { // Finding a new bodyID bodyID = -1; for (int _i = 0; _i < bodies.Length; ++_i) { if (bodies[_i].IsTracked) { bodyID = _i; break; } } } // If no any active body, byebye if (bodyID == -1) { return; } Kinect.CameraSpacePoint _cameraSpacePoint = bodies[bodyID].Joints[Kinect.JointType.HandRight].Position; Kinect.ColorSpacePoint _colorSpacePoint = coordinate.MapCameraPointToColorSpace(_cameraSpacePoint); transform.position = new Vector3(scalar_X * (_colorSpacePoint.X - solution_X) / solution_X, -scalar_Y * (_colorSpacePoint.Y - solution_Y) / solution_Y); stateInfo = m_animator.GetCurrentAnimatorStateInfo(0); if (bodies[bodyID].HandRightState == Kinect.HandState.Closed && !isHandRightClosed) { isHandRightClosed = true; m_animator.SetBool("handclosebool", true); KillMosquito(); Debug.Log("右手關起來ㄌ"); if (ActiveUIButtonList.Count != 0) { // Only invoke first ActiveUIButton HandClickEvent e = ActiveUIButtonList[0].GetComponent <HandClickEvent>(); Debug.Log("觸發 UI_Button 事件"); e.onHandClick.Invoke(); } ActiveUIButtonList.Clear(); if (isHandOnWiney) { isNormalBackground = false; Debug.Log("換背景"); background.GetComponent <SpriteRenderer>().sprite = winey; winey_bgm.Play(); } else if (isHandOnMoney) { isNormalBackground = false; Debug.Log("換背景"); background.GetComponent <SpriteRenderer>().sprite = money; money_bgm.Play(); } } else if (bodies[bodyID].HandRightState != Kinect.HandState.Closed && isHandRightClosed) { isHandRightClosed = false; m_animator.SetBool("handclosebool", false); Debug.Log("右手打開ㄌ"); if (!isNormalBackground) { background.GetComponent <SpriteRenderer>().sprite = normalBackground; } } if (bodies[bodyID].HandLeftState == Kinect.HandState.Closed && !isHandLeftClosed) { isHandLeftClosed = true; // 左手關閉表示進入 stop if (GlobalVars.MainGameStop != 1) { mainGameFunction.Stop(); } } else if (bodies[bodyID].HandLeftState != Kinect.HandState.Closed && isHandLeftClosed) { isHandLeftClosed = false; } } GlobalVars.lastCursorPosition = GlobalVars.cursorPosition; GlobalVars.cursorPosition = transform.position; }
// Update is called once per frame void Update() { if (DEBUG) { // Mouse Mode mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); transform.position = new Vector3(mousePos.x, mousePos.y); if (Input.GetMouseButtonDown(0) && !isHandRightClosed) { isHandRightClosed = true; m_animator.SetBool("handclosebool", true); } else if (Input.GetMouseButtonUp(0) && isHandRightClosed) { isHandRightClosed = false; m_animator.SetBool("handclosebool", false); } } else { // Fetch Body[] Information every time update() called bodies = bodyManager.GetBodies(); if (bodies == null) { bodyID = -1; } else if (bodyID == -1 || bodies[bodyID].IsTracked == false) { // Finding a new bodyID bodyID = -1; for (int _i = 0; _i < bodies.Length; ++_i) { if (bodies[_i].IsTracked) { bodyID = _i; break; } } } // If no any active body, byebye if (bodyID == -1) { return; } Kinect.CameraSpacePoint _cameraSpacePoint = bodies[bodyID].Joints[Kinect.JointType.HandRight].Position; Kinect.ColorSpacePoint _colorSpacePoint = coordinate.MapCameraPointToColorSpace(_cameraSpacePoint); transform.position = new Vector3(scalar_X * (_colorSpacePoint.X - solution_X) / solution_X, -scalar_Y * (_colorSpacePoint.Y - solution_Y) / solution_Y); stateInfo = m_animator.GetCurrentAnimatorStateInfo(0); if (bodies[bodyID].HandRightState == Kinect.HandState.Closed && !isHandRightClosed) { isHandRightClosed = true; m_animator.SetBool("handclosebool", true); if (isHoldStartButton) { StartButton.onClick.Invoke(); } } else if (bodies[bodyID].HandRightState != Kinect.HandState.Closed && isHandRightClosed) { isHandRightClosed = false; m_animator.SetBool("handclosebool", false); } if (bodies[bodyID].HandLeftState == Kinect.HandState.Closed && !isHandLeftClosed) { isHandLeftClosed = true; } else if (bodies[bodyID].HandLeftState != Kinect.HandState.Closed && isHandLeftClosed) { isHandLeftClosed = false; } } GlobalVars.lastCursorPosition = GlobalVars.cursorPosition; GlobalVars.cursorPosition = transform.position; }