Exemplo n.º 1
0
    // Called at the end of the program initialization
    void Start()
    {
        // Set initial state to open
        state = VirtualHandState.Open;

        // Ensure hand interactive is properly configured
        hand.type = AffectType.Virtual;
    }
Exemplo n.º 2
0
    // Called at the end of the program initialization
    void Start()
    {
        // Set initial state to open
        state = VirtualHandState.Open;

        // Ensure hand interactive is properly configured
        hand.type = AffectType.Virtual;

        pageNumber = 0;
        planets    = GameObject.FindGameObjectsWithTag("Planet");
    }
Exemplo n.º 3
0
    public void returnObject( )
    {
        Debug.Log("Destroy grasp.");

        // Get rigidbody of grasped target
        Rigidbody target = grasp.GetComponent <Rigidbody>();

        // Break grasp
        DestroyImmediate(grasp);

        state = VirtualHandState.Closed;
    }
    // Called at the end of the program initialization
    void Start()
    {
        initial_drone_position = drone_transform.position;
        initial_drone_rotation = drone_transform.rotation;

        // Set initial state to open
        state = VirtualHandState.Open;

        // Ensure hand interactive is properly configured
        leftHand.type  = AffectType.Virtual;
        rightHand.type = AffectType.Virtual;
    }
Exemplo n.º 5
0
    // Called at the end of the program initialization
    void Start()
    {
        // Set initial state to open
        state = VirtualHandState.Open;
        // Ensure hand interactive is properly configured
        hand.type = AffectType.Virtual;
        GameObject car = GameObject.Find("Classic_car_1955_style1");

        contact             = Vector3.zero;
        steeringWheelNormal = steeringWheel.transform.forward;
        deltaRotation       = new Quaternion();
        set = false;
    }
Exemplo n.º 6
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        Debug.Log(state);

        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            else if (button.GetPress())
            {
                // Allows the virtual hand to become physical
                hand.type = AffectType.Physical;

                // Change state to closed
                state = VirtualHandState.Closed;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is closed
        else if (state == VirtualHandState.Closed)
        {
            // If the user has released the button
            if (!button.GetPress())
            {
                // Allows the virtual hand to become virtual
                hand.type = AffectType.Virtual;

                // Change state to open
                state = VirtualHandState.Open;
            }

            // Process current closed state
            else
            {
                // Nothing to do for closed
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            else if (hand.triggerOngoing && zoombutton.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to zooming
                state = VirtualHandState.Zooming;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // If state is zooming
        else if (state == VirtualHandState.Zooming)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!zoombutton.GetPress() && grasp != null)
            {
                DestroyImmediate(grasp);
                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current zooming state
            else
            {
                // Get transform of grasped target
                Transform target = grasp.GetComponent <Transform> ();

                // Apply size scaling to target
                target.localScale = svm.scaling;
            }
        }
    }
Exemplo n.º 7
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];

                // If a particle is to be removed from the structure
                if (target.gameObject.name.Contains("Electron") || target.gameObject.name.Contains("Proton") || target.gameObject.name.Contains("Neutron"))
                {
                    GameObject.Find("RemoveParticles").GetComponent <RemoveParticles>().interaction(target.gameObject);
                    state = VirtualHandState.Closed;
                }

                /*
                 *  else if (target.gameObject.name.Contains("CircularProgressBar")) {
                 *  Debug.Log("sgdyugd");
                 *  state = VirtualHandState.Closed;
                 *  }
                 */

                // If the button is pressed for the quiz to begin
                else if (target.gameObject.name.Contains("Start Quiz Button"))
                {
                    GameObject.Find("ClickSound").GetComponent <ClickSound>().playClick();
                    GameObject.Find("QuizScript").GetComponent <Quiz>().startQuiz();
                    state = VirtualHandState.Closed;
                }

                // If the submit button is pressed to answer a question
                else if (target.gameObject.name.Contains("Submit Answer Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().submitAnswer();
                    state = VirtualHandState.Closed;
                }

                // If the see solution button is pressed
                else if (target.gameObject.name.Contains("See Solution Button"))
                {
                    GameObject.Find("ClickSound").GetComponent <ClickSound>().playClick();
                    GameObject.Find("QuizScript").GetComponent <Quiz>().showSolution();
                    state = VirtualHandState.Closed;
                }

                // If answer choice 1 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 1 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(1);
                    state = VirtualHandState.Closed;
                }

                // If answer choice 2 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 2 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(2);
                    state = VirtualHandState.Closed;
                }

                // If answer choice 3 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 3 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(3);
                    state = VirtualHandState.Closed;
                }

                // If answer choice 4 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 4 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(4);
                    state = VirtualHandState.Closed;
                }

                // Checks if the user has selected one of the selectable elements on the Periodic Table.
                // It then adjusts the Highlighting value and model's value accordingly.
                // It will NOT create a joint and will keep the element stationary (except highlighting feature which is called).

                // Check for Hydrogen
                else if (target.gameObject == hydrogen)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 1)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Hydrogen
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(1);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Hellium
                else if (target.gameObject == hellium)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 2)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Hellium
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(2);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Lithium
                else if (target.gameObject == lithium)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 3)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Lithium
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(3);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Beryllium
                else if (target.gameObject == beryllium)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 4)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Beryllium
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(4);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Boron
                else if (target.gameObject == boron)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 5)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Boron
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(5);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Carbon
                else if (target.gameObject == carbon)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 6)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Carbon
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(6);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Nitrogen
                else if (target.gameObject == nitrogen)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 7)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Nitrogen
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(7);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Oxygen
                else if (target.gameObject == oxygen)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 8)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Oxygen
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(8);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Flourine
                else if (target.gameObject == fluorine)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 9)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Flourine
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(9);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Neon
                else if (target.gameObject == neon)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 10)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Neon
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(10);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // If user has selected an interactable object NOT on the Periodic Table.
                else
                {
                    // Create a fixed joint between the hand and the target
                    grasp = target.gameObject.AddComponent <FixedJoint>();
                    // Set the connection
                    grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                    // Change state to holding
                    state = VirtualHandState.Holding;
                }
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is closed
        else if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                state = VirtualHandState.Open;
            }
            else
            {
                //do nothing
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            /*
             * else if (returnObjectHome == true)
             * {
             *  Debug.Log("Destroy grasp.");
             *
             *  // Get rigidbody of grasped target
             *  Rigidbody target = grasp.GetComponent<Rigidbody>();
             *  // Break grasp
             *  DestroyImmediate(grasp);
             *
             *  returnObjectHome = false;
             *  state = VirtualHandState.Closed;
             * }
             */

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // If the hand is closed
            else if (button.GetPress())
            {
                // Change state to closed
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }
            else
            {
                // do nothing
            }
        }

        //If state is closed
        if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                //change state to open
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }
            else
            {
                //do nothing
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // If displace button is pressed along with grasp and trigger button
            else if (button1.GetPress() && grasp != null && button.GetPress())
            {
                //update state to delete
                state = VirtualHandState.Displace;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // if state is displacing
        else if (state == VirtualHandState.Displace)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }


            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp

                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            //If displace button has been released
            else if (button.GetPress() && !button1.GetPress())
            {
                state = VirtualHandState.Holding;
            }


            else
            {
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                DestroyImmediate(grasp);

                if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
                }

                else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
                }

                else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
                }

                else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
                }

                grasp = target.gameObject.AddComponent <FixedJoint>();

                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is Open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            else if (button.GetPress())
            {
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }

            // Process current Open state
            else
            {
                // Nothing to do for Open
            }
        }
        else if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }
            else
            {
                //do nothing
            }
        }
        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to Open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }



        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (button.GetPress() && button2.GetPress() && grasp != null && joystick.GetAxis().y != 0)
            {
                //grasp.gameObject.GetComponent<Rigidbody>().transform.localScale += new Vector3(25,25,25) ;
                state = VirtualHandState.ScaleUpDown;
            }
            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);
                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (button.GetPress() && button2.GetPress() && joystick.GetAxis().x != 0)
            {
                state = VirtualHandState.RotationLR;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        else if (state == VirtualHandState.RotationLR)
        {
            if (button2.GetPress() && grasp != null)
            {
                if (joystick.GetAxis().x < 0.2f && joystick.GetAxis().x > 0f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 30f, 0);
                }
                else if (joystick.GetAxis().x < 0.6f && joystick.GetAxis().x >= 0.2f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 60f, 0);
                }
                else if (joystick.GetAxis().x <= 1f && joystick.GetAxis().x >= 0.6f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 90f, 0);
                }

                else if (joystick.GetAxis().x > -0.2f && joystick.GetAxis().x < 0f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, -30f, 0);
                }
                else if (joystick.GetAxis().x > -0.6f && joystick.GetAxis().x < -0.2f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, -60f, 0);
                }
                else if (joystick.GetAxis().x >= -1f && joystick.GetAxis().x < -0.6f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, -90f, 0);
                }
            }

            else if (!button.GetPress() && grasp != null && !button2.GetPress())
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 0f, 0);
                DestroyImmediate(grasp);
                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (!button2.GetPress())
            {
                hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 0f, 0);
                state = VirtualHandState.Holding;
            }
            else if (!button2.GetPress() && grasp == null)
            {
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);
                state = VirtualHandState.Closed;
            }
            else
            {
            }
        }

        else if (state == VirtualHandState.ScaleUpDown)
        {
            if (grasp == null)
            {
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (button2.GetPress() && grasp != null && button.GetPress())
            {
                if (joystick.GetAxis().y < 0f)
                {
                    grasp.gameObject.GetComponent <Rigidbody>().transform.localScale -= new Vector3(0.0001f, 0.0001f, 0.0001f);
                }
                else if (joystick.GetAxis().y > 0f)
                {
                    grasp.gameObject.GetComponent <Rigidbody>().transform.localScale += new Vector3(0.0001f, 0.0001f, 0.0001f);
                }
            }


            else if (!button.GetPress() && grasp != null && !button2.GetPress())
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);

                DestroyImmediate(grasp);
                // Apply physics to target in the event of attempting to throw it

                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;
                // Update state to Open
                state = VirtualHandState.Open;
            }

            else if (!button2.GetPress())
            {
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);
                state = VirtualHandState.Holding;
            }

            else if (!button2.GetPress() && grasp == null)
            {
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);
                state = VirtualHandState.Closed;
            }


            else
            {
                // Nothing to do for holding
            }
        }
        //else if(state ==)
    }
Exemplo n.º 10
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                Debug.Log("Touching");
                state = VirtualHandState.Touching;
            }

            // If the hand is closed
            else if (button.GetPress())
            {
                // Change state to closed
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }
            else
            {
                // do nothing
            }
        }

        //If state is closed
        if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                //change state to open
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }

            else
            {
                //do nothing
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            else if (hand.triggerOngoing && grip.GetPressDown())
            {
                Debug.Log("Apply");
                Collider target = hand.ongoingTriggers[0];

                if (target.GetComponent <Status>())
                {
                    status = target.GetComponent <Status>().isOn;
                    if (status == true)
                    {
                        Debug.Log("TurnOff");
                        status = false;
                        target.GetComponent <Status>().isOn = status;
                    }
                    else if (status == false)
                    {
                        Debug.Log("TurnOn");
                        status = true;
                        target.GetComponent <Status>().isOn = status;
                    }
                }
                else if (target.GetComponent <GoggleScript>())
                {
                    status = target.GetComponent <GoggleScript>().isOn;
                    if (status == true)
                    {
                        Debug.Log("TurnOff");
                        status = false;
                        target.GetComponent <GoggleScript>().isOn = status;
                    }
                    else if (status == false)
                    {
                        Debug.Log("TurnOn");
                        status = true;
                        target.GetComponent <GoggleScript>().isOn = status;
                    }
                }

                state = VirtualHandState.Apply;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }


            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // if state is displacing
        else if (state == VirtualHandState.Apply)
        {
            if (grasp == null && !grip.GetPressDown() && !hand.triggerOngoing)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }
            else if (grasp == null && !grip.GetPressDown() && hand.triggerOngoing)
            {
                state = VirtualHandState.Touching;
            }


            else
            {
            }
        }
    }
Exemplo n.º 11
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (solarSystem.transform.localScale.x >= .0021f)
        {
            foreach (GameObject p in planets)
            {
                p.GetComponent <Planet>().DisableMotionControl();
            }
        }
        else
        {
            foreach (GameObject p in planets)
            {
                p.GetComponent <Planet>().EnableMotionControl();
            }
        }

        // If state is open
        if (state == VirtualHandState.Open)
        {
            Debug.Log("Hand is open");
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                if (exitButton.GetPress())
                {
                    solarSystem.transform.localScale = new Vector3(0.002f, 0.002f, .002f);
                    solarSystem.transform.position   = new Vector3(0, 1.2f, 0.5f);
                }
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            Debug.Log("Hand is touching");
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                Collider t = hand.ongoingTriggers[0];
                planet = t.gameObject;
                Vector3 planetLocation = planet.transform.position;
                Vector3 locationDiff;
                if (touchPadButton.GetPress())
                {
                    Vector3 curScale = solarSystem.transform.localScale;
                    if (joystick.GetAxis().y > 0 && curScale.x < .03f)
                    {
                        solarSystem.transform.localScale = new Vector3(curScale.x, curScale.y, curScale.z) + new Vector3(scaleRate, scaleRate, scaleRate);
                        locationDiff = planetLocation - planet.transform.position;
                        solarSystem.transform.Translate(locationDiff);
                        Debug.Log(solarSystem.transform.localScale.x * 1.0f);
                    }
                    else if (joystick.GetAxis().y < 0 && curScale.x > .0021f)
                    {
                        solarSystem.transform.localScale = new Vector3(curScale.x, curScale.y, curScale.z) - new Vector3(scaleRate, scaleRate, scaleRate);
                        locationDiff = planetLocation - planet.transform.position;
                        solarSystem.transform.Translate(locationDiff);
                        Debug.Log(solarSystem.transform.localScale.x * 1.0f);
                    }
                }
                if (exitButton.GetPress())
                {
                    solarSystem.transform.localScale = new Vector3(0.002f, 0.002f, .002f);
                    solarSystem.transform.position   = new Vector3(0, 1.2f, 0.5f);
                }
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            Debug.Log("Hand is holding");
            Collider t = hand.ongoingTriggers[0];
            planet = t.gameObject;
            GameObject zc = GameObject.Find("ZoomControl");
            zc.GetComponent <ZoomControl>().ZoomToPlanet(planet);
            state = VirtualHandState.Zoomed;
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                //state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                //state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
        else if (state == VirtualHandState.Zoomed)
        {
            GameObject ac = GameObject.Find("AudioController");
            previousPageNumber = pageNumber;
            touchButtonPress   = touchPadButton.GetPress();
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }
            //Navigate right page
            if (pageNumber < 3 && joystick.GetAxis().x > 0.0f && !touchButtonPress && prevTouchButtonPress)
            {
                pageNumber++;
            }
            //Navigate left page
            else if (pageNumber > 1 && joystick.GetAxis().x < 0.0f && !touchButtonPress && prevTouchButtonPress)
            {
                pageNumber--;
            }

            if (pageNumber != previousPageNumber)
            {
                Debug.Log("Setting audio");
                //Set audio
                ac.GetComponent <AudioController>().SetAudio(pageNumber, planet);
                //Set text on panel
            }

            //UI control starts

            GameObject PlanetUI = planet.transform.Find(planet.name + "Info").gameObject;

            //Rotate panel to face user
            if (previousPageNumber == 0)
            {
                GameObject hmd   = GameObject.Find("Vive HMD");
                float      angle = getPanelRotation(hmd.transform.position.x, hmd.transform.position.z);
                PlanetUI.transform.rotation = Quaternion.Euler(0, angle, 0);
            }

            PlanetUI.gameObject.SetActive(true);
            for (int i = 1; i < 4; i++)
            {
                if (i == pageNumber)
                {
                    PlanetUI.transform.GetChild(i - 1).gameObject.SetActive(true);
                }
                else
                {
                    PlanetUI.transform.GetChild(i - 1).gameObject.SetActive(false);
                }
            }

            //UI contro ends

            if (exitButton.GetPress())
            {
                PlanetUI.gameObject.SetActive(false);

                GameObject zc = GameObject.Find("ZoomControl");
                zc.GetComponent <ZoomControl>().ZoomOut();
                pageNumber = 0;
                state      = VirtualHandState.Open;
                ac.GetComponent <AudioController>().StopAudio();
            }


            prevTouchButtonPress = touchButtonPress;
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the btnTouchpad is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If btnTouchpad has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
    }
Exemplo n.º 13
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                Debug.Log("Touching");
                state = VirtualHandState.Touching;
            }

            // If the hand is closed
            else if (button.GetPress() && !menu.GetPressDown())
            {
                // Change state to closed
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }

            else if (menu.GetPressDown())
            {
                if (button.GetPressDown())
                {
                    Debug.Log("HandleTriggerClicked");
                    if (EventSystem.current.currentSelectedGameObject != null)
                    {
                        ExecuteEvents.Execute(EventSystem.current.currentSelectedGameObject, new PointerEventData(EventSystem.current), ExecuteEvents.submitHandler);
                        return;
                    }
                }

                GameObject menuUIObj;
                GameObject menuBeamObj;
                menuUIObj = GameObject.Find("MainMenuObjectHelper");

                menustatus = menuUIObj.GetComponent <MenuUI>().isOn;
                //menustatus = menuUIObj.activeInHierarchy;

                menuBeamObj    = GameObject.Find("MenuBeamHelper");
                menuBeamStatus = menuBeamObj.GetComponent <MenuBeam>().isOn;

                if (menustatus == true)
                {
                    Debug.Log("TurnOff");
                    menustatus = false;
                    menuUIObj.GetComponent <MenuUI>().isOn     = menustatus;
                    menuBeamObj.GetComponent <MenuBeam>().isOn = menustatus;
                }
                else if (menustatus == false)
                {
                    Debug.Log("TurnOn");
                    menustatus = true;
                    menuUIObj.GetComponent <MenuUI>().isOn     = menustatus;
                    menuBeamObj.GetComponent <MenuBeam>().isOn = menustatus;
                }

                // Change state to Select
                state = VirtualHandState.Select;
            }

            else
            {
                // do nothing
            }
        }

        //If state is closed
        if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                //change state to open
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }

            else
            {
                //do nothing
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];

                if (target.GetComponent <Status>())
                {
                    status = target.GetComponent <Status>().isOn;
                    if (status == true)
                    {
                        Debug.Log("TurnOff");
                        status = false;
                        target.GetComponent <Status>().isOn = status;
                    }
                    else
                    {
                        Debug.Log("TurnOn");
                        status = true;
                        target.GetComponent <Status>().isOn = status;
                    }
                }

                if (target.GetComponent <Vision>())
                {
                    status = target.GetComponent <Vision>().isOn;
                    if (status == true)
                    {
                        status = false;
                        target.GetComponent <Vision>().isOn = status;
                        //grasp = target.GetComponent<Vision>().goggle.gameObject.AddComponent<FixedJoint>();
                        //grasp.connectedBody = hand.gameObject.GetComponent<Rigidbody>();
                    }
                }


                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                if (target.gameObject.tag == "goggle")
                {
                    hand.gameObject.tag = "goggle";
                }


                // Change state to holding
                state = VirtualHandState.Holding;
            }

            //else if (hand.triggerOngoing && grip.GetPressDown())
            //{
            //    Debug.Log("Apply");
            //    Collider target = hand.ongoingTriggers[0];

            //    if (target.GetComponent<Status>())
            //    {
            //        status = target.GetComponent<Status>().isOn;
            //        if (status == true)
            //        {
            //            Debug.Log("TurnOff");
            //            status = false;
            //            target.GetComponent<Status>().isOn = status;

            //        }
            //        else if (status == false)
            //        {
            //            Debug.Log("TurnOn");
            //            status = true;
            //            target.GetComponent<Status>().isOn = status;
            //        }
            //    }

            //    if (target.GetComponent<Goggles>())
            //    {
            //        status = target.GetComponent<Goggles>().isOn;
            //        if (status == true)
            //        {
            //            Debug.Log("TurnOff");
            //            status = false;
            //            target.GetComponent<Goggles>().isOn = status;

            //        }
            //        else if (status == false)
            //        {
            //            Debug.Log("TurnOn");
            //            status = true;
            //            target.GetComponent<Goggles>().isOn = status;
            //        }
            //    }

            //    if (target.GetComponent<Vision>())
            //    {
            //        status = target.GetComponent<Vision>().isOn;
            //        if (status == true)
            //        {
            //            Debug.Log("TurnOff");
            //            status = false;
            //            target.GetComponent<Vision>().isOn = status;

            //        }
            //        else if (status == false)
            //        {
            //            Debug.Log("TurnOn");
            //            status = true;
            //            target.GetComponent<Vision>().isOn = status;
            //        }
            //    }

            //    state = VirtualHandState.Apply;

            //}

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                hand.gameObject.tag = "hands";

                // Update state to open
                state = VirtualHandState.Open;
            }


            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // if state is displacing
        //else if (state == VirtualHandState.Apply)
        //{

        //    if (grasp == null && !grip.GetPressDown() && !hand.triggerOngoing)
        //    {
        //        // Update state to open
        //        state = VirtualHandState.Open;
        //    }
        //    else if (grasp == null && !grip.GetPressDown() && hand.triggerOngoing)
        //    {
        //        state = VirtualHandState.Touching;
        //    }

        //    else
        //    {

        //    }

        //}

        else if (state == VirtualHandState.Select)
        {
            if (!menu.GetPressDown())
            {
                state = VirtualHandState.Open;
            }
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (leftGrip.GetPress() && rightGrip.GetPress())
        {
            // Reset the game
            drone_transform.position = initial_drone_position + reset_position_offset;
            drone_transform.rotation = initial_drone_rotation;
            drone_transform.gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
        }

        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (rightHand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!rightHand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (rightHand.triggerOngoing && rightTrigger.GetPress() && leftTrigger.GetPress())
            {
                // Fetch touched target
                Collider target = rightHand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = rightHand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!rightTrigger.GetPress() && !leftTrigger.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = rightHand.velocity * speed;
                target.angularVelocity = rightHand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
    }
Exemplo n.º 15
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                initialVector = hand.gameObject.transform.position - steeringWheel.transform.position;

                initialVector = Vector3.ProjectOnPlane(initialVector, steeringWheelNormal);

                origSteeringWheelRotation = steeringWheel.transform.rotation;

                // Change state to LeftTurn
                state = VirtualHandState.Grabbing;
            }

            // Process current touching state
            else
            {
                //initialPosition = hand.gameObject.transform.position;



                // Nothing to do for touching
            }
        }

        // If state is LeftTurn
        else if (state == VirtualHandState.Grabbing)
        {
            // If button has been released and grasp still exists
            if (!button.GetPress())
            {
                state = VirtualHandState.Open;
            }

            // Process current LeftTurn state
            else
            {
                currentVector = hand.gameObject.transform.position - steeringWheel.transform.position;
                currentVector = Vector3.ProjectOnPlane(currentVector, steeringWheelNormal);

                Quaternion deltaRotation = new Quaternion();
                deltaRotation.SetFromToRotation(initialVector, currentVector);
                steeringWheel.transform.rotation = deltaRotation * origSteeringWheelRotation;
            }
        }
    }
Exemplo n.º 16
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }
            //If the hand is not touching anything but the trigger button is pressed
            else if (button.GetPress())
            {
                //change the hand interactive to physical
                hand.type = AffectType.Physical;

                //change the state to closed
                state = VirtualHandState.Closed;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                left_target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = left_target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();
                // Change state to holding
                state = VirtualHandState.Holding;
            }
            // Process current touching state
            else
            {
                //Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }
            // Process current holding state
            else
            {
                if (rightHand.triggerOngoing)
                {
                    Collider t = rightHand.ongoingTriggers[0];
                    if (GameObject.ReferenceEquals(left_target.gameObject, t.gameObject))
                    {
                        if (rightButton.GetPress())
                        {
                            state = VirtualHandState.Destroy;
                        }
                    }
                }
            }
        }

        //if the state is destroy
        else if (state == VirtualHandState.Destroy)
        {
            Collider t = rightHand.ongoingTriggers[0];
            DestroyImmediate(grasp);
            Destroy(t.gameObject);
            //Destroy(left_target.gameObject);

            //changing back to open
            state = VirtualHandState.Open;
        }

        else if (state == VirtualHandState.Closed)
        {
            //if the user is not pressing the button
            if (!button.GetPress())
            {
                //update hand interactive to virtual
                hand.type = AffectType.Virtual;

                //Update state to open
                state = VirtualHandState.Open;
            }
            //Process Current closed state
            else
            {
                //Nothing to do for closed
            }
        }
    }
Exemplo n.º 17
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            isHit = GameObject.Find("scripts/Steering").GetComponent <Steering> ().isHit;

            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }
            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }
        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing || !right_hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }
            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress() && right_hand.triggerOngoing && right_button.GetPress())
            {
                // Fetch touched target
                target = hand.ongoingTriggers [0];
                //initialVector = hand.gameObject.transform.position- steeringWheel.transform.position;

                initialVector = (hand.gameObject.transform.position - steeringWheel.transform.position) + (right_hand.gameObject.transform.position - steeringWheel.transform.position);

                initialVector             = Vector3.ProjectOnPlane(initialVector, steeringWheelNormal);
                origSteeringWheelRotation = steeringWheel.transform.rotation;

                // Change state to LeftTurn
                state = VirtualHandState.Grabbing;
            }
            // Process current touching state
            else
            {
                //initialPosition = hand.gameObject.transform.position;

                // Nothing to do for touching
            }
        }
        // If state is LeftTurn
        else if (state == VirtualHandState.Grabbing)
        {
            // If button has been released and grasp still exists
            if (!button.GetPress() || !right_button.GetPress())
            {
                state = VirtualHandState.Open;
            }

            if (isHit)
            {
                //deltaRotation.Equals (0);
                state = VirtualHandState.Open;
                initialVector.Set(0, 0, 0);
                currentVector.Set(0, 0, 0);
                deltaRotation.Set(0, 0, 0, 0);
            }
            // Process current LeftTurn state
            else
            {
                steeringWheelNormal = steeringWheel.transform.forward;

                origSteeringWheelRotation = steeringWheel.transform.rotation;

                currentVector = (hand.gameObject.transform.position - steeringWheel.transform.position) + (right_hand.gameObject.transform.position - steeringWheel.transform.position);

                initialVector = Vector3.ProjectOnPlane(initialVector, steeringWheelNormal);

                currentVector = Vector3.ProjectOnPlane(currentVector, steeringWheelNormal);

                deltaRotation.SetFromToRotation(initialVector, currentVector);

                GameObject car = GameObject.Find("Classic_car_1955_style1");

                steeringWheel.transform.rotation = deltaRotation * origSteeringWheelRotation;

                isHit = GameObject.Find("scripts/Steering").GetComponent <Steering> ().isHit;

                initialVector = currentVector;
            }
        }
    }
Exemplo n.º 18
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }
            //If hand not touching and user pressing button
            else if (button.GetPress())
            {
                hand.type = AffectType.Physical;
                state     = VirtualHandState.Closed;
            }
            // Enlarge
            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }
        // If state is closed
        else if (state == VirtualHandState.Closed)
        {
            // If the user has released the button
            if (!button.GetPress())
            {
                hand.type = AffectType.Virtual;
                state     = VirtualHandState.Open;
            }
        }


        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // If the hand is touching something and the buttonE is pressed
            else if (hand.triggerOngoing && buttonE.GetPress())
            {
                // Change state to holding
                hand.type = AffectType.Virtual;
                state     = VirtualHandState.Enlarge;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }
        // Enlarge
        if (state == VirtualHandState.Enlarge)
        {
            Collider target = hand.ongoingTriggers[0];
            target.transform.localScale += new Vector3(0.1f, 0.1f, 0.1f);
            state = VirtualHandState.Touching;
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
    }
Exemplo n.º 19
0
    void updateHand(VirtualHandInfo hi)
    {
        VirtualHandState state  = hi.state;
        Affect           hand   = hi.hand;
        CommonButton     button = hi.button;
        GameObject       target = hi.target;

        if (state == VirtualHandState.Open)
        {
            if (hand.triggerOngoing)
            {
                state = VirtualHandState.Touching;
            }
            else
            {
            }
        }
        else if (hi.state == VirtualHandState.Touching)
        {
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state  = VirtualHandState.Open;
                target = null;
            }
            else
            {
                if (button.GetPress() && target == null && !hand.ongoingTriggers [0].GetComponent <Interactive>().isHeavy)
                {
                    target = hand.ongoingTriggers [0].gameObject;

                    JackHook jackHook = target.GetComponent <JackHook> ();
                    if (jackHook == null)
                    {
                        SnapTarget snap = target.GetComponent <SnapTarget> ();

                        if (snap != null && snap.state == FAFVR.SnapTargetState.Locked)
                        {
                            state  = VirtualHandState.Open;
                            target = null;
                        }
                        else
                        {
                            if (snap != null)
                            {
                                snap.setState(FAFVR.SnapTargetState.Holding);
                            }

                            TireIron ti = target.GetComponent <TireIron> ();
                            if (ti != null)
                            {
                                ti.SetStatus(TireIronStatus.OneHandHolding);
                            }
                            Rigidbody rig = target.GetComponent <Rigidbody> ();
                            rig.isKinematic         = true;
                            rig.useGravity          = false;
                            target.transform.parent = hand.gameObject.transform;
                            state = VirtualHandState.Holding;
                        }
                    }
                    else
                    {
                        if (jackHook.state == JackHookState.Open)
                        {
                            Rigidbody rig = target.GetComponent <Rigidbody> ();
                            rig.isKinematic         = true;
                            rig.useGravity          = false;
                            target.transform.parent = hand.gameObject.transform;
                            state = VirtualHandState.Holding;
                            jackHook.SetState(JackHookState.Holding);
                            jackHook.isRotating = false;
                        }
                        else if (jackHook.state == JackHookState.Connecting)
                        {
                            jackHook.isRotating = true;
                        }
                        else
                        {
                            jackHook.isRotating = false;
                        }
                    }
                }
            }
        }
        else if (hi.state == VirtualHandState.Holding)
        {
            if (target == null)
            {
                state = VirtualHandState.Open;
            }
            else
            {
                SnapTarget snap = target.GetComponent <SnapTarget> ();
                if (snap != null && snap.state == FAFVR.SnapTargetState.Locked)
                {
                    target.transform.parent = world;
                    target = null;
                    state  = VirtualHandState.Open;
                }
                else if (!button.GetPress() && target != null)
                {
                    Rigidbody rig = target.GetComponent <Rigidbody> ();
                    rig.isKinematic         = false;
                    rig.useGravity          = true;
                    target.transform.parent = world;

                    state = VirtualHandState.Open;

                    snap = target.GetComponent <SnapTarget> ();

                    if (snap != null)
                    {
                        snap.setState(FAFVR.SnapTargetState.Open);
                    }

                    if (target.GetComponent <JackHook> () != null)
                    {
                        target.GetComponent <JackHook> ().state = JackHookState.Open;
                    }
                    target = null;
                }
            }
        }

        hi.state  = state;
        hi.target = target;
    }