예제 #1
0
    //------------------------HitRay interaction operations---------------------------

    // change it into function-seleciton
    void RayHit_Navigation(Hand hand, HitBall m_ControllBall_R, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            if (m_pointer != null)
            {
                m_pointer.SetActive(true);
                m_pointer_comp.EnableTeleport();
            }
            else
            {
                m_pointer = new GameObject("MyPointer");
                m_pointer.transform.SetParent(transform);
                m_pointer.transform.localPosition = Vector3.zero;
                m_pointer.transform.localRotation = Quaternion.identity;
                // initialize the pointer component
                m_pointer_comp = m_pointer.AddComponent <Pointer>();
                UnityEngine.Object obj     = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrows.mat");
                Material           goodmat = obj as Material;
                m_pointer_comp.goodTeleMat = goodmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrowsBad.mat");
                Material badmat = obj as Material;
                m_pointer_comp.badTeleMat = badmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/TeleportHighlight.prefab");
                GameObject telhigh = obj as GameObject;
                m_pointer_comp.teleportHighlight = telhigh;
                m_pointer_comp.pointerType       = Pointer.PointerType.Parabola;
            }
            break;

        case IFuncType.Update:
            m_pointer.transform.position = m_ControllBall_R.transform.position;
            Debug.Log(m_ControllBall_R.transform.position);
            //m_pointer.transform.position = GMS.toVec3(hand.Fingers[1].bones[3].NextJoint);
            m_pointer.transform.rotation = Quaternion.FromToRotation(Vector3.forward, m_ControllBall_R.direc.normalized);
            //m_pointer.transform.rotation = UnityQuaternionExtension.ToQuaternion(hand.Fingers[1].bones[3].Rotation);
            break;

        case IFuncType.Close:
            if (m_pointer != null)
            {
                m_pointer.SetActive(false);
                m_pointer_comp.DisableTeleport();
                // move current camera position
                Vector3 cur_pos = m_camera.transform.position;
                m_camera.transform.position = m_pointer_comp.hit_out.point;
                m_camera.transform.position.Set(m_camera.transform.position.x, cur_pos.y, m_camera.transform.position.z);
            }
            break;

        default:
            break;
        }
    }
예제 #2
0
    //--------------------CameraTransition interaction operations---------------------


    //---------------------Manipulation interaction operations------------------------
    void ObjRotation(Transform LMC_in, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            if (m_orthBall == null)
            {
                m_orthBall = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //m_orthBall.AddComponent<Rigidbody>();
                // set the name
                m_orthBall.name = "Rotation Ball";
                // ToDo: set suitable material
                // set the position
                m_orthBall.transform.SetParent(LMC_in);
                m_orthBall.transform.localPosition = new Vector3(0, 0.8f, 0);
                m_orthBall.transform.localScale    = new Vector3(0.5f, 0.5f, 0.5f);
            }
            m_orthBall.SetActive(true);
            break;

        case IFuncType.Update:
            if (m_object != null && m_orthBall != null)
            {
                // get the Quaternion-rotation
                Quaternion rotate_get = Quaternion.Euler(0, 10, 0);
                m_object.transform.rotation   *= rotate_get;
                m_orthBall.transform.rotation *= rotate_get;
            }
            break;

        case IFuncType.Close:
            if (m_orthBall != null)
            {
                m_orthBall.SetActive(false);
            }
            break;

        default:
            break;
        }
    }
예제 #3
0
    //--------------------CameraTransition interaction operations---------------------
    void CameraTransition(float angles_in, Vector3 trans_in, Vector3 referAxsis, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            m_camera  = GameObject.Find("FPSController_Standard");
            pre_speed = 0;
            break;

        case IFuncType.Update:
            if (m_camera != null)
            {
                // never change position in height
                trans_in.y = 0;
                // calculate mean changing speed
                float speed_get = calcSpeed(angles_in);
                speed_get /= 1000;
                //int speed_cap_num = 20;
                //float mean_s = (speed_get - pre_speed) / speed_cap_num;
                //// uniform acceleration on speed
                //for (int i = 0; i < speed_cap_num; i++)
                //{
                //    updateRotation(trans_in, referAxsis);
                //    m_camera.transform.position += (pre_speed + i * mean_s) * trans_in;

                //}
                //StartCoroutine();
                updateCamera(speed_get, trans_in, referAxsis);
                pre_speed = speed_get;
            }
            break;

        case IFuncType.Close:
            m_camera = null;
            break;

        default:
            break;
        }
    }
예제 #4
0
    //---------------------Manipulation interaction operations------------------------
    void RotateObject(Hand hand, HitBall m_ControllBall_L, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            originDirec = m_ControllBall_L.direc;
            originQ.SetFromToRotation(originDirec, originDirec);
            break;

        case IFuncType.Update:


            // check is too close to center
            if (m_ControllBall_L.radius < 0.05)
            {
                originDirec = m_ControllBall_L.direc;
                originQ.SetFromToRotation(originDirec, originDirec);
                return;
            }

            nextDirec = m_ControllBall_L.direc;
            nextQ.SetFromToRotation(originDirec, nextDirec);

            //Debug.Log(Vector3.Dot(originDirec.normalized, nextDirec.normalized));

            // check if two vector is very similar
            if (Vector3.Dot(originDirec.normalized, nextDirec.normalized) > 0.999)
            {
                return;
            }

            GameObject a = GameObject.Find("CubeTest");
            Quaternion q = Quaternion.Slerp(originQ, nextQ, Time.deltaTime * 10);

            LineRender lr = a.GetComponent <LineRender>();
            if (Mathf.Abs(q.x) > Mathf.Abs(q.y) && Mathf.Abs(q.x) > Mathf.Abs(q.z))
            {
                q.y = 0f; q.z = 0f;
                lr.DrawXCycline();
            }
            else if (Mathf.Abs(q.y) > Mathf.Abs(q.z))
            {
                q.x = 0f; q.z = 0f;
                lr.DrawYCycline();
            }
            else
            {
                q.x = 0f; q.y = 0f;
                lr.DrawZCycline();
            }

            //if (orginRotationAxis != CurrentRotationAxis)
            //{
            //    orginRotationAxis = CurrentRotationAxis;
            //    originDirec = nextDirecl
            //}
            a.transform.rotation = q * a.transform.rotation;

            originDirec = nextDirec;
            originQ     = nextQ;
            break;

        case IFuncType.Close:
            break;

        default:
            break;
        }
    }
예제 #5
0
    //------------------------HitRay interaction operations---------------------------


    void RayHit_Selection(Hand hand, HitBall m_ControllBall_R, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            if (m_pointer != null)
            {
                m_pointer.SetActive(true);
                m_pointer_comp.EnableTeleport();
                // initialize selection
                GameObject m_camera = GameObject.Find("Main Camera");
                m_camera.AddComponent <HighlightingEffect>();
                objSelected  = new List <GameObject>();
                multiMode    = true;
                pre_selected = null;
            }
            else
            {
                m_pointer = new GameObject("MyPointer");
                m_pointer.transform.SetParent(transform);
                m_pointer.transform.localPosition = Vector3.zero;
                m_pointer.transform.localRotation = Quaternion.identity;
                // initialize the pointer component
                m_pointer_comp = m_pointer.AddComponent <Pointer>();
                UnityEngine.Object obj     = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrows.mat");
                Material           goodmat = obj as Material;
                m_pointer_comp.goodTeleMat = goodmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrowsBad.mat");
                Material badmat = obj as Material;
                m_pointer_comp.badTeleMat = badmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/TeleportHighlight.prefab");
                GameObject telhigh = obj as GameObject;
                m_pointer_comp.teleportHighlight = telhigh;
                m_pointer_comp.pointerType       = Pointer.PointerType.Line;
            }
            break;

        case IFuncType.Update:
            m_pointer.transform.position = m_ControllBall_R.transform.position;
            //m_pointer.transform.position = GMS.toVec3(hand.Fingers[1].bones[3].NextJoint);
            m_pointer.transform.rotation = Quaternion.FromToRotation(Vector3.forward, m_ControllBall_R.direc);
            //m_pointer.transform.rotation = UnityQuaternionExtension.ToQuaternion(hand.Fingers[1].bones[3].Rotation);
            // selection
            // #1: add or change object(s) selected
            if (m_pointer_comp.hit_out.collider != null)
            {
                GameObject cur_hit_obj = m_pointer_comp.hit_out.collider.gameObject;

                if (cur_hit_obj == pre_selected)
                {
                    return;
                }

                if (cur_hit_obj.GetComponent <SpectrumController>() == null)
                {
                    // if hit object is not selected before
                    if (!multiMode)
                    {
                        removeAllHighlighting();
                        objSelected.Clear();
                    }
                    objSelected.Add(cur_hit_obj);
                    cur_hit_obj.AddComponent <SpectrumController>();
                }
                else
                {
                    // if hit object is selected before, then we cancel the selection on it
                    // ToDo: it should compared with the last obj. Since in continue-selection, one object can be hit constantly.
                    if (objSelected.Count > 1)
                    {
                        if (cur_hit_obj != pre_selected)
                        {
                            removeHighlighting(cur_hit_obj);
                            objSelected.Remove(cur_hit_obj);
                        }
                    }
                }
                pre_selected = cur_hit_obj;
            }
            else
            {
                pre_selected = null;
            }

            break;

        case IFuncType.Close:
            if (m_pointer != null)
            {
                m_pointer.SetActive(false);
                m_pointer_comp.DisableTeleport();
                removeAllHighlighting();
                objSelected.Clear();
                objSelected = null;
                Destroy(Camera.main.GetComponent <HighlightingEffect>());
            }
            break;

        default:
            break;
        }
    }