예제 #1
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));
    }
예제 #2
0
    // Update is called once per frame
    void Update () {
        if (BodySourceManager == null)
        {
            return;
        }

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

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

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

            if (body.IsTracked)
            {
                CameraSpacePoint cameraSpacePoint = body.Joints[Windows.Kinect.JointType.HandLeft].Position;
                colorSpacePoint = kinectSensor.CoordinateMapper.MapCameraPointToColorSpace(cameraSpacePoint);
            }
        }
    }
예제 #3
0
        public static Vector3 MapToColor(Kinect.Joint joint)
        {
            //Joint Pos to Color Coordinates
            if (joint == null)
            {
                return(new Vector3(0, 0, -1));
            }
            Kinect.ColorSpacePoint colorPoint = _Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
            if (float.IsInfinity(colorPoint.X))
            {
                colorPoint.X = 0;
            }
            if (float.IsInfinity(colorPoint.Y))
            {
                colorPoint.Y = 0;
            }

            Vector3 vec = new Vector3(colorPoint.X, colorPoint.Y, 0);

            //Color Coordinates to actual Screensize/ Pos
            vec.x *= resFactorX;
            vec.y *= resFactorY;
            //to do: actual ScreenPos to Viewport Pos
            vec.x = vec.x / Screen.width;
            vec.y = 1 - vec.y / Screen.height;
            // Viewport Pos to 3d Space
            vec.z = joint.Position.Z * 10;
            vec   = cam.ViewportToWorldPoint(vec);
            return(vec);
        }
예제 #4
0
    /// <summary>
    /// Maps the depth point to color coords.
    /// </summary>
    /// <returns>The depth point to color coords.</returns>
    /// <param name="depthPos">Depth position.</param>
    /// <param name="depthVal">Depth value.</param>
    public Vector2 MapDepthPointToColorCoords(Vector2 depthPos, ushort depthVal)
    {
        Vector2 vPoint = Vector2.zero;
        Kinect.CoordinateMapper coordMapper = m_MultiSourceManager.GetCoordinateMapper();

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

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

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

            Kinect.ColorSpacePoint[] colPoints = new Kinect.ColorSpacePoint[1];
            coordMapper.MapDepthPointsToColorSpace(depthPoints, depthVals, colPoints);

            Kinect.ColorSpacePoint colPoint = colPoints [0];
            vPoint.x = colPoint.X;
            vPoint.y = colPoint.Y;
        }

        return vPoint;
    }
    private int returnColorFrameIndex(ColorSpacePoint csp)
    {
        int colorX = (int)(Mathf.Floor(csp.X + 0.5f));
        int colorY = (int)(Mathf.Floor(csp.Y + 0.5f));
        int colorIndex = (int)colorBytesPerPixel * (colorX + (colorY * colorWidth));

        return colorIndex;
    }
예제 #6
0
    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)));
    }
예제 #7
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));
    }
예제 #8
0
    void UpdateTexture(KinectOneDepth depth, KinectOneLabelMap labelmap, KinectOneImage image)
    {
        int trackedUserId = -1;

        if (m_engageuser != null && m_engageuser.engagedTrackedUser != null)
        {
            trackedUserId = m_engageuser.engagedTrackedUser.Id;
        }
        if (trackedUserId == -1)
        {
            GetNoTrackingTexture(depth);
        }
        else
        {
            Kinect.ColorSpacePoint[] colorSpacePoints = new Kinect.ColorSpacePoint[depth.xres * depth.yres];
            _mapper.MapDepthFrameToColorSpace(depth.GetData(), colorSpacePoints);
            GetRemoveBackground(labelmap, image, colorSpacePoints);
        }
        texture.SetPixels32(outputPixels);
        texture.Apply();
    }
예제 #9
0
    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));
    }
예제 #11
0
 public bool Equals(ColorSpacePoint obj)
 {
     return(X.Equals(obj.X) && Y.Equals(obj.Y));
 }
    // 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;
    }
예제 #13
0
 // Token: 0x06002C0D RID: 11277 RVA: 0x000DC664 File Offset: 0x000DAA64
 public bool Equals(ColorSpacePoint obj)
 {
     return(this.X.Equals(obj.X) && this.Y.Equals(obj.Y));
 }
 public bool Equals(ColorSpacePoint obj)
 {
     return((X == obj.X) && (Y == obj.Y));
 }
    private void RefreshMesh(ushort[] depthData, int colorWidth, int colorHeight)
    {
        var frameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;

        ColorSpacePoint[] colorSpace = new ColorSpacePoint[depthData.Length];
        mapper.MapDepthFrameToColorSpace(depthData, colorSpace);

        for (int y = 0; y < frameDesc.Height; y += downsampleSize)
        {
            for (int x = 0; x < frameDesc.Width; x += downsampleSize)
            {
                int indexX = x / downsampleSize;
                int indexY = y / downsampleSize;
                int smallIndex = (indexY * (frameDesc.Width / downsampleSize)) + indexX;

                //double avg = GetAvg(depthData, x, y, frameDesc.Width, frameDesc.Height);

                vertices[smallIndex].x = (float)pointCloud[(y * frameDesc.Width) + x].x;
                vertices[smallIndex].y = (float)pointCloud[(y * frameDesc.Width) + x].y;
                vertices[smallIndex].z = (float)pointCloud[(y * frameDesc.Width) + x].z - 10.0f;

                // Update UV mapping with CDRP
                var colorSpacePoint = colorSpace[(y * frameDesc.Width) + x];
                uv[smallIndex] = new Vector2(colorSpacePoint.X / colorWidth, colorSpacePoint.Y / colorHeight);
            }
        }

        mesh.vertices = vertices;
        mesh.uv = uv;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
    }
예제 #16
0
 public bool Equals(ColorSpacePoint obj)
 {
     return(X == obj.X && Y == obj.Y);
 }
 public bool Equals(ColorSpacePoint obj)
 {
     return (X == obj.X) && (Y == obj.Y);
 }
    public Vector2 MapDepthPointToColorCoords(KinectInterop.SensorData sensorData, Vector2 depthPos, ushort depthVal)
    {
        Vector2 vPoint = Vector2.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;

            ColorSpacePoint[] colPoints = new ColorSpacePoint[1];
            coordMapper.MapDepthPointsToColorSpace(depthPoints, depthVals, colPoints);

            ColorSpacePoint colPoint = colPoints[0];
            vPoint.x = colPoint.X;
            vPoint.y = colPoint.Y;
        }

        return vPoint;
    }
예제 #19
0
    // Update the user histogram map
    void UpdateUserHistogramImage()
    {
        int numOfPoints = 0;
        Array.Clear(usersHistogramMap, 0, usersHistogramMap.Length);

        // Calculate cumulative histogram for depth
        for (int i = 0; i < usersMapSize; i++)
        {
            // Only calculate for depth that contains users
            if (sensorData.bodyIndexImage[i] != 255)
            {
                ushort depth = sensorData.depthImage[i];
                if(depth > 5000)
                    depth = 5000;

                usersHistogramMap[depth]++;
                numOfPoints++;
            }
        }

        if (numOfPoints > 0)
        {
            for (int i = 1; i < usersHistogramMap.Length; i++)
            {
                usersHistogramMap[i] += usersHistogramMap[i - 1];
            }

            for (int i = 0; i < usersHistogramMap.Length; i++)
            {
                usersHistogramMap[i] = 1.0f - (usersHistogramMap[i] / numOfPoints);
            }
        }

        ColorSpacePoint[] colorCoords = null;
        if(sensorData.colorImage != null)
        {
            colorCoords = new ColorSpacePoint[sensorData.depthImageWidth * sensorData.depthImageHeight];
            sensorData.coordMapper.MapDepthFrameToColorSpace(sensorData.depthImage, colorCoords);
        }

        // Create the actual users texture based on label map and depth histogram
        Color32 clrClear = Color.clear;
        for (int i = 0; i < usersMapSize; i++)
        {
            ushort userMap = sensorData.bodyIndexImage[i];
            ushort userDepth = sensorData.depthImage[i];

            ushort nowUserPixel = userMap != 255 ? (ushort)((userMap << 13) | userDepth) : userDepth;
            ushort wasUserPixel = usersPrevState[i];

            // draw only the changed pixels
            if(nowUserPixel != wasUserPixel)
            {
                usersPrevState[i] = nowUserPixel;

                if (userMap == 255)
                {
                    usersHistogramImage[i] = clrClear;
                }
                else
                {
                    if(sensorData.colorImage != null)
                    {
                        int cx = (int)(colorCoords[i].X);
                        int cy = (int)(colorCoords[i].Y);
                        int colorIndex = cx + cy * sensorData.colorImageWidth;

                        if(colorIndex >= 0 && colorIndex < usersClrSize)
                        {
                            int ci = colorIndex << 2;
                            Color32 colorPixel = new Color32(sensorData.colorImage[ci], sensorData.colorImage[ci + 1], sensorData.colorImage[ci + 2], 230);

                            usersHistogramImage[i] = colorPixel;
                        }
                    }
                    else
                    {
                        // Create a blending color based on the depth histogram
                        float histDepth = usersHistogramMap[userDepth];
                        Color c = new Color(histDepth, histDepth, histDepth, 0.9f);

                        switch(userMap % 4)
                        {
                        case 0:
                            usersHistogramImage[i] = Color.red * c;
                            break;
                        case 1:
                            usersHistogramImage[i] = Color.green * c;
                            break;
                        case 2:
                            usersHistogramImage[i] = Color.blue * c;
                            break;
                        case 3:
                            usersHistogramImage[i] = Color.magenta * c;
                            break;
                        }
                    }
                }

            }
        }
    }
예제 #20
0
 private void RefreshData(ushort[] depthData, int colorWidth, int colorHeight)
 {
     var frameDesc = _Sensor.DepthFrameSource.FrameDescription;
     
     ColorSpacePoint[] colorSpace = new ColorSpacePoint[depthData.Length];
     _Mapper.MapDepthFrameToColorSpace(depthData, colorSpace);
     
     for (int y = 0; y < frameDesc.Height; y += _DownsampleSize)
     {
         for (int x = 0; x < frameDesc.Width; x += _DownsampleSize)
         {
             int indexX = x / _DownsampleSize;
             int indexY = y / _DownsampleSize;
             int smallIndex = (indexY * (frameDesc.Width / _DownsampleSize)) + indexX;
             
             double avg = GetAvg(depthData, x, y, frameDesc.Width, frameDesc.Height);
             
             avg = avg * _DepthScale;
             
             _Vertices[smallIndex].z = (float)avg;
             
             // Update UV mapping with CDRP
             var colorSpacePoint = colorSpace[(y * frameDesc.Width) + x];
             _UV[smallIndex] = new Vector2(colorSpacePoint.X / colorWidth, colorSpacePoint.Y / colorHeight);
         }
     }
     
     _Mesh.vertices = _Vertices;
     _Mesh.uv = _UV;
     _Mesh.triangles = _Triangles;
     _Mesh.RecalculateNormals();
 }
예제 #21
0
파일: PointF.cs 프로젝트: Smoothstep/VRChat
 // Token: 0x06002870 RID: 10352 RVA: 0x000D1C55 File Offset: 0x000D0055
 public bool Equals(ColorSpacePoint obj)
 {
     return(this.X == obj.X && this.Y == obj.Y);
 }
예제 #22
0
    private void RefreshData(ushort[] depthData, int colorWidth, int colorHeight)
    {
        var frameDesc = _Sensor.DepthFrameSource.FrameDescription;

        ColorSpacePoint[] colorSpace = new ColorSpacePoint[depthData.Length];
        _Mapper.MapDepthFrameToColorSpace(depthData, colorSpace);
        //byte[] bodyIndexData = new byte[frameDesc.Width * frameDesc.Height];
        bodyIndexData = _MultiManager.GetBodyIndexData ();

        for (int y = 0; y < frameDesc.Height; y++)
        {
            for (int x = 0; x < frameDesc.Width; x++) {
                int bodyIndex = y * frameDesc.Width + x;
                byte player = bodyIndexData[bodyIndex];
                if(player == 0xFF)
                    depthData [bodyIndex] = 0;
            }
        }

        for (int y = 0; y < frameDesc.Height; y += _DownsampleSize)
        {
            for (int x = 0; x < frameDesc.Width; x += _DownsampleSize)
            {
                int indexX = x / _DownsampleSize;
                int indexY = y / _DownsampleSize;
                int smallIndex = (indexY * (frameDesc.Width / _DownsampleSize)) + indexX;
                double avg = GetAvg(depthData, x, y, frameDesc.Width, frameDesc.Height);

                avg = avg * _DepthScale;

                _Vertices[smallIndex].z = (float)avg;

                var colorSpacePoint = colorSpace[(y * frameDesc.Width) + x];

                // Update UV mapping with CDRP

                if(colorSpacePoint.X != -1.0f && colorSpacePoint.Y != 1.0f)
                {
                    _UV[smallIndex] = new Vector2(colorSpacePoint.X / colorWidth, colorSpacePoint.Y / colorHeight);
                }
                //_UV[smallIndex] = new Vector2(colorSpacePoint.X / colorWidth, colorSpacePoint.Y / colorHeight);

            }
        }

        /*
        //get vertices depth position
        if (Input.GetButtonDown ("Fire1")) {
            using (StreamWriter writer = new StreamWriter("Assets/Resources/test1.txt")) {
                for(int i = 0; i < _Vertices.Length; i++){
                    float z = _Vertices[i].z;
                    string ss;
                    ss = z.ToString ();

                    //writer = new StreamWriter("Assets/Resources/"+fileName+".txt");
                    writer.WriteLine (ss);
                }
                writer.Close();

            }
        }
        */
        _Mesh.vertices = _Vertices;
        _Mesh.uv = _UV;
        _Mesh.triangles = _Triangles;
        _Mesh.RecalculateNormals();
    }
예제 #23
0
 void UpdateTexture(KinectOneDepth depth, KinectOneLabelMap labelmap, KinectOneImage image)
 {
     int trackedUserId = -1;
     if (m_engageuser != null && m_engageuser.engagedTrackedUser != null)
         trackedUserId = m_engageuser.engagedTrackedUser.Id;
     if (trackedUserId == -1)
     {
         GetNoTrackingTexture(depth);
     }
     else
     {
         Kinect.ColorSpacePoint[] colorSpacePoints = new Kinect.ColorSpacePoint[depth.xres * depth.yres];
         _mapper.MapDepthFrameToColorSpace(depth.GetData(), colorSpacePoints);
         GetRemoveBackground(labelmap, image, colorSpacePoints);
     }
     texture.SetPixels32(outputPixels);
     texture.Apply();
 }
예제 #24
0
 public bool Equals(ColorSpacePoint obj)
 {
     return X.Equals(obj.X) && Y.Equals(obj.Y);
 }
예제 #25
0
    //透過不同模式所傳入的資料來源將從不同的Script匯入該Function中,去運算每次Update中所得到的Mesh。
    private void RefreshData(ushort[] depthData, int colorWidth, int colorHeight)
    {
        Debug.Log("W = " + colorWidth);
        Debug.Log("H = " + colorHeight);
        var frameDesc = _Sensor.DepthFrameSource.FrameDescription;

        ColorSpacePoint[] colorSpace = new ColorSpacePoint[depthData.Length];
        Debug.Log("Old " + depthData.Length);
        _Mapper.MapDepthFrameToColorSpace(depthData, colorSpace);
        Debug.Log("New " + depthData.Length);

        for (int y = 0; y < frameDesc.Height; y += _DownsampleSize)
        {
            for (int x = 0; x < frameDesc.Width; x += _DownsampleSize)
            {
                int indexX = x / _DownsampleSize;//Mesh的X軸點數。
                int indexY = y / _DownsampleSize;//Mesh的Y軸點數。
                int smallIndex = (indexY * (frameDesc.Width / _DownsampleSize)) + indexX; //Mesh的所有點數以一維方式排列所取得的總數。

                double avg = GetAvg(depthData, x, y, frameDesc.Width, frameDesc.Height);//計算每4X4個Pixel的深度平均值。

                avg = avg * _DepthScale;//降低深度的比率。

                _Vertices[smallIndex].z = (float)avg;//給予每個Mesh的點Z值。

                // Update UV mapping with CDRP
                var colorSpacePoint = colorSpace[(y * frameDesc.Width) + x];

                _UV[smallIndex] = new Vector2(colorSpacePoint.X / colorWidth, colorSpacePoint.Y / colorHeight);
            }
        }

        _Mesh.vertices = _Vertices;
        _Mesh.uv = _UV;
        _Mesh.triangles = _Triangles;
        _Mesh.RecalculateNormals();
    }
예제 #26
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;
    }