Created
October 14, 2015 01:29
-
-
Save kaorun55/e78b2d87a84c1be881a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Vector3 GetVector3FromJoint(Kinect.Joint joint) | |
| { | |
| var valid = joint.TrackingState != Kinect.TrackingState.NotTracked; | |
| if ( Camera != 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 = _Camera.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 ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment