Exemple #1
0
    //컨트롤러 제스처 Draw 처리, 라벨링/ 위치 값/ 활성화 트리거(true = 시작 , false= 끝) / 플레이어 머리 transform
    public int GestureDraw(Vector3 position, bool active, Transform head, bool isTransform)
    {
        bool state = active;

        if (state == true)
        {
            if (isStart == false && isInit == false)
            {
                isStart = true;
                isInit  = true;
            }
            isEnd = false;
        }
        else
        {
            if (isPress == true)
            {
                isEnd = true;
            }
            isPress = false;
        }

        currPos = position;
        Vector3 t_currPos = user.getLocalizedPoint(currPos, head);

        //클릭이 시작된 경우(클릭하는 순간)
        if (isStart == true)
        {
            //Debug.Log("start");
            vertexCount = 0;                              //버텍스카운트 0
            points.Clear();                               //포인트 리스트 클리어
            t_points.Clear();
            currentGestureLineRenderer.SetVertexCount(0); //Line Renderer 초기화
            points.Add(currPos);                          //Current Pos 추가
            t_points.Add(t_currPos);
            prePos  = currPos;
            isPress = true;
        }
        //누르고 있는 경우
        if (isPress == true)
        {
            //이전 Pos와 현재 Pos의 거리구해서 points 추가
            if (Vector3.Distance(currPos, prePos) > 0.001f)
            {
                points.Add(currPos);
                t_points.Add(t_currPos);
            }
            //points의 개수가 1개 이상일 경우1
            if (points.Count > 0)
            {
                //points가 2개 이상인 경우
                if (points.Count > 1)
                {
                    if (points.Count > vertexCount)
                    {
                        //가장 최근(마지막)에 들어온 벡터 사이를 threshold(pixel_Interpolation)에 따라  보간
                        GUtil.getInterpolationBetweenLastVector(ref points, pixel_Interpolation);
                        //가장 최근(마지막)에 들어온 벡터 사이를 threshold(pixel_Interpolation)에 따라  보간
                        GUtil.getInterpolationBetweenLastVector(ref t_points, pixel_Interpolation);

                        //Line Renderer에 적용
                        int start = vertexCount;
                        for (int i = start; i < points.Count; i++)
                        {
                            vertexCount += 1;
                            currentGestureLineRenderer.SetVertexCount(vertexCount);
                            currentGestureLineRenderer.SetPosition(vertexCount - 1, points[vertexCount - 1]);
                        }
                    }
                }
                //points가 1개인 경우
                else
                {
                    vertexCount = 1;
                    currentGestureLineRenderer.SetVertexCount(vertexCount);
                    currentGestureLineRenderer.SetPosition(vertexCount - 1, points[points.Count - 1]);
                }
            }
        }
        //클릭이 끝난 경우(끝나는 순간)
        if (isEnd == true)
        {
            isInit = false;

            if (points.Count > 1)
            {
                float[] input;
                if (isTransform == true)
                {
                    input = GUtil.Preprocess1(t_points, GConfig.Hand.RIGHT);
                }
                else
                {
                    input = GUtil.Preprocess1(points, GConfig.Hand.RIGHT);
                }
                return(classifier.RunClassifier(input));
            }
        }
        prePos = currPos;

        return(-1);
    }