예제 #1
0
    int getStickEnd(ushort[] depthData, Kinect.CameraSpacePoint handCameraPoint, Kinect.DepthSpacePoint handDepthPoint)
    {
        //depthData = (ushort[])depthData.Clone();
        //cutDepthData(depthData, (int)handDepthPoint.Y + 100, (int)(handCameraPoint.Z * 1000));

        return(DFS(depthData, (int)handDepthPoint.X, (int)handDepthPoint.Y));
    }
예제 #2
0
    private float getDistanceWithDepthSpacePoint(Kinect.DepthSpacePoint p, Kinect.DepthSpacePoint q, ushort[] depthData)
    {
        Kinect.CameraSpacePoint P = _Mapper.MapDepthPointToCameraSpace(p, depthData[Pos2Idx((int)p.X, (int)p.Y)]);
        Kinect.CameraSpacePoint Q = _Mapper.MapDepthPointToCameraSpace(q, depthData[Pos2Idx((int)q.X, (int)q.Y)]);

        return(Mathf.Sqrt((P.X - Q.X) * (P.X - Q.X) + (P.Y - Q.Y) * (P.Y - Q.Y) + (P.Z - Q.Z) * (P.Z - Q.Z)));
    }
예제 #3
0
    public void Update(KinectManager manager, Kinect.CameraSpacePoint leftTip, Kinect.CameraSpacePoint rightTip)
    {
        leftHandPos  = Utility.CameraSpacePointToWorld(leftTip);
        rightHandPos = Utility.CameraSpacePointToWorld(rightTip);

        leftKneePos  = Utility.CameraSpacePointToWorld(manager.JointData[Windows.Kinect.JointType.KneeLeft].Position);
        rightKneePos = Utility.CameraSpacePointToWorld(manager.JointData[Windows.Kinect.JointType.KneeRight].Position);

        if (prevTime == 0)
        {
            prevLeftHandPos  = leftHandPos;
            prevRightHandPos = rightHandPos;
            prevLeftKneePos  = leftKneePos;
            prevRightKneePos = rightKneePos;
        }
        // vel
        float currTime = Time.time;
        float timeDiff = currTime - prevTime;

        leftHandVel  = (leftHandPos - prevLeftHandPos) / timeDiff;
        rightHandVel = (rightHandPos - prevRightHandPos) / timeDiff;
        leftKneeVel  = (leftKneePos - prevLeftKneePos) / timeDiff;
        rightKneeVel = (rightKneePos - prevRightKneePos) / timeDiff;

        // update prev, lasttime
        prevLeftHandPos  = leftHandPos;
        prevRightHandPos = rightHandPos;
        prevLeftKneePos  = leftKneePos;
        prevRightKneePos = rightKneePos;

        prevTime = currTime;

        checkFootDrum();
        checkHandClear();
    }
예제 #4
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        filter.UpdateFilter(ref body);
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.HandRight; jt++)
        {
            //Kinect.Joint sourceJoint = body.Joints [jt];
            GameObject avatarSpineBase            = GameObject.FindGameObjectsWithTag(Kinect.JointType.SpineBase.ToString())[0];
            Transform  jointObj                   = bodyObject.transform.FindChild(jt.ToString());
            Kinect.CameraSpacePoint jointPosition = filter.FilteredJoints[jt].Position;
            jointPosition.Z = -jointPosition.Z;
            jointDataRecorder.Append(string.Format("{0},{1},{2},{3}", System.DateTime.Now, jointPosition.X, jointPosition.Y, jointPosition.Z));

            if (jt == Kinect.JointType.SpineBase)
            {
                transformDistance = new Vector3(jointPosition.X - avatarSpineBase.transform.position.x,
                                                jointPosition.Y - avatarSpineBase.transform.position.y,
                                                jointPosition.Z - avatarSpineBase.transform.position.z);
            }

            jointObj.position = new Vector3((jointPosition.X - transformDistance.x),
                                            (jointPosition.Y - transformDistance.y),
                                            (jointPosition.Z - transformDistance.z));

            /*if (jt <= Kinect.JointType.ShoulderLeft || jt == Kinect.JointType.ShoulderRight) {
             *                  GameObject avatarJoint = GameObject.FindGameObjectsWithTag (jt.ToString ()) [0];
             *                  avatarJoint.transform.position = jointObj.transform.position;
             *          }*/
        }
        jointDataRecorder.Append("\n");
    }
예제 #5
0
    private Vector3 GetVector3FromJoint(Kinect.Joint joint)
    {
        // x and y in [-1,1], I think
        Kinect.CameraSpacePoint cameraPoint = joint.Position;

        // x and y in [0, 1080]
        Kinect.ColorSpacePoint colorPoint = _Sensor.CoordinateMapper.MapCameraPointToColorSpace(cameraPoint);

        // Match format for hold bounding box
        float[] coordinates     = new float[] { colorPoint.X, colorPoint.Y, 0, 0 }; // 0, 0 is filler for the bounding box
        float[] projectorBounds = StateManager.instance.getProjectorBounds();

        // Transform into the appropriate coordinates to project
        float[] transformedCoordinates = transformOpenCvToUnitySpace(projectorBounds, coordinates);


        // Now convert back into unity space so joints can be added to the scene
        float camHeight = 2f * this.mainCam.orthographicSize;
        float camWidth  = camHeight * this.mainCam.aspect;

        float x = transformedCoordinates[0] * camWidth - camWidth / 2f;
        float y = transformedCoordinates[1] * camHeight - camHeight / 2f;

        return(new Vector3(-1f * x, -1f * y, 0));
    }
예제 #6
0
    public void CreateCustomizeMenuDrum(Kinect.CameraSpacePoint position)
    {
        Vector3 neckPos = Utility.CameraSpacePointToWorld(position);

        menuDrum = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/MenuDrum"));
        menuDrum.transform.Translate(neckPos);
        Camera.SetupCurrent(drum.GetComponentInChildren <Camera>());
    }
 private static Kinect.CameraSpacePoint Vector3ToSkeletonPoint(Vector3 position)
 {
     //Kinect.Joint joint = new Kinect.Joint();
     Kinect.CameraSpacePoint Position = new Kinect.CameraSpacePoint();
     Position.X = position.x / 10f;
     Position.Y = position.y / 10f;
     Position.Z = position.z / 10f;
     return(Position);
 }
예제 #8
0
    public void DisplayPlayer(KinectManager manager, Kinect.CameraSpacePoint leftTip, Kinect.CameraSpacePoint rightTip)
    {
        Kinect.CameraSpacePoint leftHand  = manager.JointData[Kinect.JointType.HandLeft].Position;
        Kinect.CameraSpacePoint rightHand = manager.JointData[Kinect.JointType.HandRight].Position;

        leftStick.transform.position  = Utility.CameraSpacePointToWorld(leftHand);
        rightStick.transform.position = Utility.CameraSpacePointToWorld(rightHand);
        leftStick.transform.LookAt(Utility.CameraSpacePointToWorld(leftTip));
        rightStick.transform.LookAt(Utility.CameraSpacePointToWorld(rightTip));
    }
예제 #9
0
    private float jointDistance(Kinect.Joint a, Kinect.Joint b)
    {
        Kinect.CameraSpacePoint _a = a.Position;
        Kinect.CameraSpacePoint _b = b.Position;

        float dx = _a.X - _b.X;
        float dy = _a.Y - _b.Y;
        float dz = _a.Z - _b.Z;

        return(Mathf.Sqrt(dx * dx + dy * dy + dz * dz));
    }
        // ==================================== <summary>
        // kinect座標型をvector3に変換
        // </summary> ===================================
        private Vector3 kinectPointToVector3(Kinect.CameraSpacePoint _pos, Vector3?_offset = null)
        {
            Vector3 offset = _offset ?? Vector3.zero;
            Vector3 pos    = new Vector3(
                _pos.X + offset.x,
                _pos.Y + offset.y,
                _pos.Z + offset.z
                );

            return(pos);
        }
예제 #11
0
    private Vector3 transformKinectToUnitySpace(Kinect.CameraSpacePoint point, float depth, Camera cam, int kinectWidth, int kinectHeight)
    {
        Kinect.ColorSpacePoint colorPoint = _Sensor.CoordinateMapper.MapCameraPointToColorSpace(point);

        float newX = ((2 * colorPoint.X - kinectWidth) / kinectWidth) * (cam.orthographicSize * cam.aspect);
        float newY = ((kinectHeight - 2 * colorPoint.Y) / kinectHeight) * cam.orthographicSize;

        if (!StateManager.instance.debugView)
        {
            newX = newX * -1;
        }

        return(new Vector3(newX, newY, depth));
    }
예제 #12
0
    public StickRecognizer(KinectManager manager)
    {
        _Width                  = manager.DepthFrameDesc.Width;
        _Height                 = manager.DepthFrameDesc.Height;
        _LeftTipCache           = new Kinect.CameraSpacePoint();
        _RightTipCache          = new Kinect.CameraSpacePoint();
        _LeftCacheElapsedFrame  = 10;
        _RightCacheElapsedFrame = 10;
        _Mapper                 = manager.Mapper;

        //debugPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
        //debugPlane.transform.Translate(-10, 2, 0);
        //debugPlane.transform.Rotate(-90, 180, 0);
        //debugTexture = new Texture2D(manager.DepthFrameDesc.Width, manager.DepthFrameDesc.Height, TextureFormat.RGB24, false);
    }
예제 #13
0
    bool[] getStickIndex(ushort[] depthData)
    {
        bool[] stickIndex = new bool[depthData.Length];
        for (int i = 0; i < depthData.Length; i++)
        {
            stickIndex[i] = false;
        }

        Kinect.CameraSpacePoint leftHandCameraPoint  = joints[Kinect.JointType.HandLeft].Position;
        Kinect.DepthSpacePoint  leftHandDepthPoint   = mapper.MapCameraPointToDepthSpace(leftHandCameraPoint);
        Kinect.CameraSpacePoint rightHandCameraPoint = joints[Kinect.JointType.HandRight].Position;
        Kinect.DepthSpacePoint  rightHandDepthPoint  = mapper.MapCameraPointToDepthSpace(rightHandCameraPoint);

        depthData = (ushort[])depthData.Clone();
        cutDepthData(depthData, (int)Mathf.Min(leftHandDepthPoint.Y, rightHandDepthPoint.Y) + 300, (int)(Mathf.Max(leftHandCameraPoint.Z, rightHandCameraPoint.Z) * 1000));

        //  left hand
        int  leftStickEndInd = getStickEnd(depthData, leftHandCameraPoint, leftHandDepthPoint);
        bool useCache        = leftStickEndInd == 0;

        if (useCache)
        {
            return(null);
        }
        int rightStickEndInd = getStickEnd(depthData, rightHandCameraPoint, rightHandDepthPoint);

        useCache |= rightStickEndInd == 0;
        if (useCache)
        {
            return(null);
        }

        depthDataCache = (ushort[])depthData.Clone();

        addStickIndex(stickIndex, depthData, leftHandDepthPoint, leftStickEndInd);

        //  right hand
        addStickIndex(stickIndex, depthData, rightHandDepthPoint, rightStickEndInd);

        stickIndexCache = (bool[])stickIndex.Clone();


        return(stickIndex);
    }
예제 #14
0
    void ZigTrackedUserCenter(KinectOneLabelMap labelmap)
    {
        if (m_engageuser == null || m_engageuser.engagedTrackedUser == null)
        {
            trackedUserIndex = 255;
            return;
        }
        ZigTrackedUser _engagedUser = m_engageuser.engagedTrackedUser;

        Kinect.CameraSpacePoint positionPoint = new Kinect.CameraSpacePoint();
        positionPoint.X = _engagedUser.Position.x;
        positionPoint.Y = _engagedUser.Position.y;
        positionPoint.Z = _engagedUser.Position.z;
        Kinect.DepthSpacePoint depthSpacePoint = _mapper.MapCameraPointToDepthSpace(positionPoint);
        short[] labelData = labelmap.data;
        int     index     = (int)(depthSpacePoint.Y * depthInfo.xres + depthSpacePoint.X);

        trackedUserIndex = (index >= 0 && index < labelData.Length) ? labelData[index] : (short)255;
    }
예제 #15
0
    public void FindTip(KinectManager manager,
                        out Kinect.CameraSpacePoint leftTipCameraPoint, out Kinect.CameraSpacePoint rightTipCameraPoint,
                        out bool leftStatus, out bool rightStatus)
    {
        Kinect.CameraSpacePoint leftHandCameraPoint  = manager.JointData[Kinect.JointType.HandLeft].Position;
        Kinect.DepthSpacePoint  leftHandDepthPoint   = manager.Mapper.MapCameraPointToDepthSpace(leftHandCameraPoint);
        Kinect.CameraSpacePoint rightHandCameraPoint = manager.JointData[Kinect.JointType.HandRight].Position;
        Kinect.DepthSpacePoint  rightHandDepthPoint  = manager.Mapper.MapCameraPointToDepthSpace(rightHandCameraPoint);
        byte[] colorData = new byte[3 * manager.DepthData.Length];

        ushort[] tempDepthData = new ushort[manager.DepthData.Length];
        tempDepthData = (ushort[])manager.DepthData.Clone();


        for (int i = 0; i < tempDepthData.Length; i++)
        {
            if (tempDepthData[i] > (tempDepthData[Pos2Idx((int)leftHandDepthPoint.X, (int)leftHandDepthPoint.Y)] + 30))
            {
                tempDepthData[i] = 0;
            }
        }

        int leftStickEndIdx = GetStickEnd(tempDepthData, leftHandCameraPoint, leftHandDepthPoint, ref colorData);

        if (leftStickEndIdx == 0)
        {
            leftTipCameraPoint = _LeftTipCache;
            if (_LeftCacheElapsedFrame >= 10)
            {
                leftStatus = false;
            }
            else
            {
                leftStatus = true;
                _LeftCacheElapsedFrame++;
            }
        }
        else
        {
            Kinect.DepthSpacePoint leftTipDepthPoint = new Kinect.DepthSpacePoint();
            leftTipDepthPoint.X = leftStickEndIdx % _Width;
            leftTipDepthPoint.Y = leftStickEndIdx / _Width;
            leftTipCameraPoint  = manager.Mapper.MapDepthPointToCameraSpace(leftTipDepthPoint, manager.DepthData[leftStickEndIdx]);

            _LeftTipCache          = leftTipCameraPoint;
            _LeftCacheElapsedFrame = 0;

            leftStatus = true;
        }

        tempDepthData = (ushort[])manager.DepthData.Clone();

        for (int i = 0; i < tempDepthData.Length; i++)
        {
            if (tempDepthData[i] > (tempDepthData[Pos2Idx((int)rightHandDepthPoint.X, (int)rightHandDepthPoint.Y)] + 30))
            {
                tempDepthData[i] = 0;
            }
        }

        //int rightStickEndIdx = GetStickEnd(manager.DepthData, rightHandCameraPoint, rightHandDepthPoint);
        int rightStickEndIdx = GetStickEnd(tempDepthData, rightHandCameraPoint, rightHandDepthPoint, ref colorData);

        if (rightStickEndIdx == 0)
        {
            rightTipCameraPoint = _RightTipCache;
            if (_RightCacheElapsedFrame >= 10)
            {
                rightStatus = false;
            }
            else
            {
                rightStatus = true;
                _RightCacheElapsedFrame++;
            }
        }
        else
        {
            Kinect.DepthSpacePoint rightTipDepthPoint = new Kinect.DepthSpacePoint();
            rightTipDepthPoint.X = rightStickEndIdx % _Width;
            rightTipDepthPoint.Y = rightStickEndIdx / _Width;
            rightTipCameraPoint  = manager.Mapper.MapDepthPointToCameraSpace(rightTipDepthPoint, manager.DepthData[rightStickEndIdx]);


            _RightTipCache          = rightTipCameraPoint;
            _RightCacheElapsedFrame = 0;

            rightStatus = true;
        }


        ushort[] depthData = manager.DepthData;
        //DrawDebugImg(manager, leftStickEndIdx, rightStickEndIdx);
    }
예제 #16
0
 public static Vector3 CameraSpacePointToWorld(Kinect.CameraSpacePoint p)
 {
     return(new Vector3(-10 * p.X, 10 * p.Y, 13 * p.Z));
 }
예제 #17
0
 public static Vector3 GetPosition(Kinect.CameraSpacePoint point)
 {
     return(new Vector3(point.X, point.Y, point.Z));
 }
예제 #18
0
        public Vector3 MapDepthPointToSpaceCoords(KinectInterop.SensorData sensorData, Vector2 depthPos, ushort depthVal)
        {
            Vector3 vPoint = Vector3.zero;

            if (coordMapper != null && depthPos != Vector2.zero)
            {
                DepthSpacePoint depthPoint = new DepthSpacePoint();
                depthPoint.X = depthPos.x;
                depthPoint.Y = depthPos.y;

                DepthSpacePoint[] depthPoints = new DepthSpacePoint[1];
                depthPoints[0] = depthPoint;

                ushort[] depthVals = new ushort[1];
                depthVals[0] = depthVal;

                CameraSpacePoint[] camPoints = new CameraSpacePoint[1];
                coordMapper.MapDepthPointsToCameraSpace(depthPoints, depthVals, camPoints);

                CameraSpacePoint camPoint = camPoints[0];
                vPoint.x = camPoint.X;
                vPoint.y = camPoint.Y;
                vPoint.z = camPoint.Z;
            }

            return vPoint;
        }
예제 #19
0
 //--------------------------------------------------------------------------------------
 // if joint is 0 it is not valid.
 //--------------------------------------------------------------------------------------
 bool JointPositionIsValid( CameraSpacePoint vJointPosition )
 {
     return ( vJointPosition.X != 0.0f ||
                 vJointPosition.Y != 0.0f ||
                 vJointPosition.Z != 0.0f );
 }
예제 #20
0
        CameraSpacePoint CSVectorSubtract(CameraSpacePoint p1, CameraSpacePoint p2)
        {
            CameraSpacePoint diff = new CameraSpacePoint();

            diff.X = p1.X - p2.X;
            diff.Y = p1.Y - p2.Y;
            diff.Z = p1.Z - p2.Z;

            return diff;
        }
예제 #21
0
        CameraSpacePoint CSVectorScale(CameraSpacePoint p, float scale)
        {
            CameraSpacePoint point = new CameraSpacePoint();

            point.X = p.X * scale;
            point.Y = p.Y * scale;
            point.Z = p.Z * scale;

            return point;
        }
예제 #22
0
    // 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;
    }
예제 #23
0
 private Kinect.CameraSpacePoint CreateEndPoint(Kinect.CameraSpacePoint startP, float[] vec)
 {
     Kinect.CameraSpacePoint point = new Kinect.CameraSpacePoint();
     point.X = startP.X + vec[0];
     point.Y = startP.Y + vec[1];
     point.Z = startP.Z + vec[2];
     return point;
 }
예제 #24
0
 private static Vector3 GetVector3FromCameraSpacePoint(Kinect.CameraSpacePoint point)
 {
     return(new Vector3(-point.X, point.Y, point.Z));
 }
예제 #25
0
 public SkeletonJoint(JointType type, int confidence, CameraSpacePoint position, Orientation orientation)
 {
     this.Type = type;
     this.Confidence = confidence;
     this.Position = new Vector3(position.X, position.Y, position.Z);
     this.Rotation = new Quaternion(orientation.X, orientation.Y, orientation.Z, orientation.W);
     this.State = 0;
 }
    // 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;
    }
예제 #27
0
        CameraSpacePoint CSVectorAdd(CameraSpacePoint p1, CameraSpacePoint p2)
        {
            CameraSpacePoint sum = new CameraSpacePoint();

            sum.X = p1.X + p2.X;
            sum.Y = p1.Y + p2.Y;
            sum.Z = p1.Z + p2.Z;

            return sum;
        }
		// Update is called once per frame
		void Update ()
		{
			float deltaTime = Time.deltaTime;
			currentVector = transform.position;

			mousePosX = CrossPlatformInputManager.GetAxis ("Mouse X");
			mousePosY = CrossPlatformInputManager.GetAxis ("Mouse Y");

			//Debug.Log ("MouseScroll "+Input.GetAxis ("Mouse ScrollWheel"));
			if (Input.GetMouseButtonDown (0))
				mouseClicked = true;
			else if (Input.GetMouseButtonUp (0))
				mouseClicked = false;

			if (mouseClicked) {
				//transform.RotateAround (transform.parent.position, new Vector3 (0, 1, 0), mousePosX * 200 * deltaTime);
				//transform.RotateAround (transform.parent.position, new Vector3 (1, 0, 0), mousePosY * 300 * deltaTime);
				transform.position = Quaternion.Euler(mousePosY*200*deltaTime, mousePosX*300*deltaTime,0) *  transform.position;
				//transform.position = Quaternion.AngleAxis(mousePosX*300*deltaTime, gameObject.transform.up) * transform.position;
				transform.LookAt(transform.parent.position);
			}


			transform.Translate (-currentVector*Input.GetAxis("Mouse ScrollWheel")*2*deltaTime, Space.World);
			transform.LookAt (transform.parent.position, transform.up);
		


			if (Input.GetKey(KeyCode.Escape)) {
				Application.LoadLevel ("SplashScreen");
			}



			/*
			if (Input.GetMouseButtonDown (1))
				repositioning = true;

			if (repositioning) {
				transform.RotateAround (transform.parent.position, new Vector3 (0, 1, 0), rootPosition.x * 300 * deltaTime);
				transform.RotateAround (transform.parent.position, new Vector3 (1, 0, 0), rootPosition.y * 300 * deltaTime);
			}
			*/


			//Debug.Log(gameObject.transform.rotation.x);
			//Kinect
			if (bodyManager == null) {
				return;
			}
			bodies = bodyManager.GetData ();
			
			if (bodies == null) {
				return;
			}
			
			foreach (var body in bodies) {
				if (body == null){
					continue;
				}
				if (body.IsTracked)
				{
                    
                    //Cursor
                    TrackHandMovement(body);
                    //Click gesture

                    Debug.Log(body.Joints[JointType.ShoulderLeft].Position.Z - body.Joints[JointType.HandLeft].Position.Z > 0.4);
                    
                    if (body.Joints[JointType.ShoulderLeft].Position.Z - body.Joints[JointType.HandLeft].Position.Z > 0.4)
                    //if (body.Joints[JointType.HandTipRight].Position.X > body.Joints[JointType.WristRight].Position.X + 0.02)
                    {
                        
                            Debug.Log("Click");
                        if (active != null)
                        {
                            clickTime = clickTime + deltaTime;
                            if (clickTime > 0.5)
                            {
                                click = true;
                                clickTime = 0;
                            }
                        }
                    }
                    //Debug.Log(body.Joints[JointType.HandRight].TrackingState);
                    //Cursor end


                    if (body.HandLeftState == HandState.Closed){
						if(grab == false){
							lastPos = body.Joints[JointType.HandLeft].Position;
							lastCameraPos = gameObject.transform.rotation;
						}
						grab = true;
						
						var pos = body.Joints[JointType.HandLeft].Position;

						transform.RotateAround (transform.parent.position, new Vector3 (0, 1, 0), (pos.X - lastPos.X) * multiplier);
						transform.RotateAround (transform.parent.position, new Vector3 (1, 0, 0), (pos.Y - lastPos.Y) * multiplier);


						//transform.Translate (-currentVector*(pos.Z - lastPos.Z), Space.World);

						transform.LookAt (transform.parent.position, transform.up);
					}
					else if (body.HandLeftState == HandState.Open){
						grab = false;
					}

					if(body.HandRightState == HandState.Closed){
						if(grabR == false){
							lastPosR = body.Joints[JointType.HandRight].Position;
						}
						grabR = true;

						transform.Translate (-currentVector*((body.Joints[JointType.HandRight].Position.Z - lastPosR.Z)/4), Space.World);
					}
					else if (body.HandRightState == HandState.Open){
						grabR = false;
					}
				}
			}

            //raycast
            Ray ray = Camera.main.ScreenPointToRay(new Vector3((float)RightHandX + 12, Screen.height-(float)RightHandY, 0));

            if (active == null)
            {
                clickTime = 0;
            }
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {                           
                if(active != null && active != hit.transform.gameObject)
                {
                    active.GetComponent<OnClickCenterView>().OnKinectExit();
                    clickTime = 0;
                }
                active = hit.transform.gameObject;
                //active = GameObject.Find(hit.transform.gameObject.name).transform;
                //Debug.Log("HIT");
                //Debug.Log(hit.transform.gameObject);                
                active.GetComponent<OnClickCenterView>().OnKinectEnter((float)RightHandX + 12, Screen.height - (float)RightHandY);
                if(click == true)
                {
                    active.GetComponent<OnClickCenterView>().OnMouseDown();
                    click = false;
                }                
            }
            else
            {
               if (active != null)
                {
                    active.GetComponent<OnClickCenterView>().OnKinectExit();
                    active = null;
                    clickTime = 0;
                }
            }

            Debug.DrawRay(ray.origin, ray.direction, Color.red);

        }
예제 #29
0
 float CSVectorLength(CameraSpacePoint p)
 {
     return Mathf.Sqrt(p.X * p.X + p.Y * p.Y + p.Z * p.Z);
 }
 public Windows.Kinect.CameraSpacePoint ToKinectPosition()
 {
     CameraSpacePoint result = new CameraSpacePoint ();
     result.X = position.x;
     result.Y = position.y;
     result.Z = position.z;
     return result;
 }
예제 #31
0
        CameraSpacePoint CSVectorSet(float x, float y, float z)
        {
            CameraSpacePoint point = new CameraSpacePoint();

            point.X = x;
            point.Y = y;
            point.Z = z;

            return point;
        }
예제 #32
0
 private Vector3 GetBodyPosition(Kinect.Body body, Kinect.JointType jointType)
 {
     Kinect.CameraSpacePoint pos = body.Joints[jointType].Position;
     return(new Vector3(pos.X, pos.Y, pos.Z));
 }
예제 #33
0
        CameraSpacePoint CSVectorZero()
        {
            CameraSpacePoint point = new CameraSpacePoint();

            point.X = 0.0f;
            point.Y = 0.0f;
            point.Z = 0.0f;

            return point;
        }
 public static Vector3 ToVector3(CameraSpacePoint cameraSpacePoint)
 {
     return new Vector3(-cameraSpacePoint.X, cameraSpacePoint.Y, cameraSpacePoint.Z);
 }
예제 #35
0
    /// <summary>
    /// Maps the space point to depth coords.
    /// </summary>
    /// <returns>The space point to depth coords.</returns>
    /// <param name="spacePos">Space position.</param>
    private Vector2 MapSpacePointToDepthCoords(Vector3 spacePos)
    {
        Vector2 vPoint = Vector2.zero;

        Kinect.CoordinateMapper coordMapper = m_MultiSourceManager.GetCoordinateMapper();

        if (coordMapper != null)
        {
            Kinect.CameraSpacePoint camPoint = new Kinect.CameraSpacePoint();
            camPoint.X = spacePos.x;
            camPoint.Y = spacePos.y;
            camPoint.Z = spacePos.z;

            Kinect.CameraSpacePoint[] camPoints = new Kinect.CameraSpacePoint[1];
            camPoints [0] = camPoint;

            Kinect.DepthSpacePoint[] depthPoints = new Kinect.DepthSpacePoint[1];
            coordMapper.MapCameraPointsToDepthSpace(camPoints, depthPoints);

            Kinect.DepthSpacePoint depthPoint = depthPoints [0];

            if (depthPoint.X >= 0 && depthPoint.X < cDepthImageWidth &&
                depthPoint.Y >= 0 && depthPoint.Y < cDepthImageHeight)
            {
                vPoint.x = depthPoint.X;
                vPoint.y = depthPoint.Y;
            }
        }

        return vPoint;
    }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);

                const float             mtoft   = 100f / 30.48f;
                Kinect.CameraSpacePoint headPos = body.Joints[Kinect.JointType.Head].Position;
                float distHead = headPos.Z * mtoft;

                Kinect.CameraSpacePoint spineBasePos = body.Joints[Kinect.JointType.SpineBase].Position;
                float distSpineBase = spineBasePos.Z * mtoft;
                BodyDistanceText.text = string.Format("{0}\n{1}\n\n{2}\n{3}\n",
                                                      distHead.ToString("0.0"), distSpineBase.ToString("0.0"),
                                                      headPos.Z.ToString("0.0"), spineBasePos.Z.ToString("0.0"));
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
예제 #37
0
        public Vector2 MapSpacePointToDepthCoords(KinectInterop.SensorData sensorData, Vector3 spacePos)
        {
            Vector2 vPoint = Vector2.zero;

            if (coordMapper != null)
            {
                CameraSpacePoint camPoint = new CameraSpacePoint();
                camPoint.X = spacePos.x;
                camPoint.Y = spacePos.y;
                camPoint.Z = spacePos.z;

                CameraSpacePoint[] camPoints = new CameraSpacePoint[1];
                camPoints[0] = camPoint;

                DepthSpacePoint[] depthPoints = new DepthSpacePoint[1];
                coordMapper.MapCameraPointsToDepthSpace(camPoints, depthPoints);

                DepthSpacePoint depthPoint = depthPoints[0];

                if (depthPoint.X >= 0 && depthPoint.X < sensorData.depthImageWidth &&
                   depthPoint.Y >= 0 && depthPoint.Y < sensorData.depthImageHeight)
                {
                    vPoint.x = depthPoint.X;
                    vPoint.y = depthPoint.Y;
                }
            }

            return vPoint;
        }
예제 #38
0
    public void ChangeDrum(State.Status nextStatus, Kinect.CameraSpacePoint position)
    {
        Vector3 neckPos = Utility.CameraSpacePointToWorld(position);
        State   state   = GameObject.Find("MAIN").GetComponent <main>()._State;

        if (drum != null)
        {
            GameObject.Destroy(drum);
        }

        string drumName = null;

        switch (nextStatus)
        {
        case State.Status.Menu:
            drumName = "Prefabs/MenuDrum";
            break;

        case State.Status.Playing:
            if (state.SelectedDesign == State.CustomizeDesignOption.Standard)
            {
                drumName = "Prefabs/RealDrum";
            }
            else
            {
                drumName = "Prefabs/BolbbalganDrum";
            }
            break;

        case State.Status.CustomizeMenu:
            drumName = "Prefabs/CustomizeMenuDrum";
            break;

        case State.Status.PositionCustomizing:
            drumName = "Prefabs/PositionCustomizeMenuDrum";
            break;

        case State.Status.PositionMoving:
            drumName = "Prefabs/PositionCustomizeDrum";
            break;

        case State.Status.SoundCustomizing:
            drumName = "Prefabs/SoundCustomizeDrum";
            break;

        case State.Status.DesignCustomizing:
            drumName = "Prefabs/DesignCustomizeDrum";
            break;

        default:
            break;
        }

        drum = (GameObject)GameObject.Instantiate(Resources.Load(drumName));
        drum.transform.Translate(neckPos);
        if (nextStatus == State.Status.Playing || nextStatus == State.Status.PositionCustomizing || nextStatus == State.Status.PositionMoving || nextStatus == State.Status.DesignCustomizing)
        {
            customizePosition();
        }
        if (nextStatus == State.Status.DesignCustomizing)
        {
            customizeDesign();
        }
        Camera.SetupCurrent(drum.GetComponentInChildren <Camera>());
    }
예제 #39
0
 public void Play(KinectManager manager, Kinect.CameraSpacePoint left, Kinect.CameraSpacePoint right)
 {
 }
예제 #40
0
 public bool Equals(CameraSpacePoint obj)
 {
     return(X.Equals(obj.X) && Y.Equals(obj.Y) && Z.Equals(obj.Z));
 }
예제 #41
0
 private static float VectorLength(Kinect.CameraSpacePoint currentLocation)
 {
     return(new Vector3(currentLocation.X, currentLocation.Y, currentLocation.Z).magnitude);
 }
 private static extern RootSystem.IntPtr Windows_Kinect_CoordinateMapper_MapCameraPointToColorSpace(
     RootSystem.IntPtr pNative, CameraSpacePoint cameraPoint);
예제 #43
0
 public bool Equals(CameraSpacePoint obj)
 {
     return X.Equals(obj.X) && Y.Equals(obj.Y) && Z.Equals(obj.Z);
 }
    // Update is called once per frame
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        for (int i=0; i<data.Length; i++) {

            //foreach(var body in data)
            //{
            if (data [i] == null) {
                continue;
            }

            if (data [i].IsTracked) {
                if(ctr==0){
                    initialPosition = data[i].Joints[JointType.SpineBase].Position
                }
                RefreshBodyObjectOrientation(data[i]);
                ctr++;
            }
        }
    }
예제 #45
0
 void ZigTrackedUserCenter(KinectOneLabelMap labelmap)
 {
     if (m_engageuser == null || m_engageuser.engagedTrackedUser == null)
     {
         trackedUserIndex = 255;
         return;
     }
     ZigTrackedUser _engagedUser = m_engageuser.engagedTrackedUser;
     Kinect.CameraSpacePoint positionPoint = new Kinect.CameraSpacePoint();
     positionPoint.X = _engagedUser.Position.x;
     positionPoint.Y = _engagedUser.Position.y;
     positionPoint.Z = _engagedUser.Position.z;
     Kinect.DepthSpacePoint depthSpacePoint = _mapper.MapCameraPointToDepthSpace(positionPoint);
     short[] labelData = labelmap.data;
     int index = (int)(depthSpacePoint.Y * depthInfo.xres + depthSpacePoint.X);
     trackedUserIndex = (index >= 0 && index < labelData.Length) ? labelData[index] : (short)255;
 }
예제 #46
0
 private int GetStickEnd(ushort[] depthData, Kinect.CameraSpacePoint handCameraPoint, Kinect.DepthSpacePoint handDepthPoint, ref byte[] colorData)
 {
     return(DFS(depthData, (int)handDepthPoint.X, (int)handDepthPoint.Y, ref colorData));
 }
예제 #47
0
 public Joint(Kinect.CameraSpacePoint position, Windows.Kinect.Vector4 rotation)
 {
     this.Position = new Vector3(position.X, position.Y, position.Z);
     this.Rotation = new Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W);
 }
 private static Kinect.CameraSpacePoint Vector3ToSkeletonPoint(Vector3 position)
 {
     //Kinect.Joint joint = new Kinect.Joint();
     Kinect.CameraSpacePoint Position = new Kinect.CameraSpacePoint ();
     Position.X = position.x / 10f;
     Position.Y = position.y / 10f;
     Position.Z = position.z/ 10f;
     return Position;
 }