Esempio n. 1
0
    //Updating user interface
    private void UpdateUI()
    {
        string myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());

        if (!myObjStringName.Equals("null"))
        {
            //Get Touched Object initial position
            Vector3 initialPosition;
            try{
                initialPosition = dict[myObjStringName];
            }
            catch (KeyNotFoundException e) {
                return;
            }

            //Get current cursor position
            Vector3 cursorPosition = GameObject.Find("Cursor").transform.position;

            //Get position and angle differences
            float posDiff   = Vector3.Distance(initialPosition, cursorPosition);
            float angleDiff = Vector3.Angle(initialPosition, cursorPosition);

            //Update UI text panel
            GUIText panel = GameObject.Find("Panel").GetComponent <GUIText>();
            panel.text = "Diferencia posicion: " + posDiff + "\nDiferencia angular: " + angleDiff;
        }
    }
Esempio n. 2
0
    public void GetTouchedObject()
    {
        //Convert Convert IntPtr To byte[] to String
        string myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());

        //Debug.Log ("The touched object is " + myObjStringName.ToString());

        //If in Manipulation Mode enable the manipulation of the selected object
        if (PluginImport.GetMode() == 1)
        {
            if (PluginImport.GetButton1State())
            {
                if (clickCount == 0)
                {
                    //Set the manipulated object at first click
                    manipObj = GameObject.Find(myObjStringName);

                    //Setup Manipulated object Hierarchy as a child of haptic cursor - Only if object is declared as Manipulable object
                    if (manipObj != null && !PluginImport.IsFixed(PluginImport.GetManipulatedObjectId()))
                    {
                        //Store the Previous parent object
                        prevParent = manipObj.transform.parent;

                        //Asign New Parent - the tip of the manipulation object device
                        manipObj.transform.parent = myHapticClassScript.hapticCursor.transform;
                    }
                }
                clickCount++;
            }
            else
            {
                //Reset Click counter
                clickCount = 0;

                //Reset Manipulated Object Hierarchy
                if (manipObj != null)
                {
                    manipObj.transform.parent = prevParent;
                }

                //Reset Manipulated Object
                manipObj = null;

                //Reset prevParent
                prevParent = null;
            }

            //Only in Manipulation otherwise object are not moving so there is no need to proceed
            UpdateHapticObjectMatrixTransform();
        }
    }
    void ActivatingGrabbedObjectPropperties()
    {
        GameObject grabbedObject;
        string     myObjStringName;

        if (!previousButtonState && PluginImport.GetButton1State())
        {
            //If the object is grabbed, the gravity is deactivated and kinematic is enabled
            myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());

            if (!myObjStringName.Equals("null"))
            {
                grabbedObject = GameObject.Find(myObjStringName);

                //If there is a rigid body
                if (grabbedObject.GetComponent <Rigidbody>() != null)
                {
                    grabbedObject.GetComponent <Rigidbody>().isKinematic = true;
                    grabbedObject.GetComponent <Rigidbody>().useGravity  = false;
                }
                grabbedObjectName = myObjStringName;
            }
            previousButtonState = true;
        }

        else if (previousButtonState && !PluginImport.GetButton1State())
        {
            //If the object is dropped, the grabity is enabled again and kinematic is deactivated
            if (!grabbedObjectName.Equals(""))
            {
                grabbedObject = GameObject.Find(grabbedObjectName);

                //If there is a rigid body
                if (grabbedObject.GetComponent <Rigidbody>() != null)
                {
                    grabbedObject.GetComponent <Rigidbody>().isKinematic = false;
                    grabbedObject.GetComponent <Rigidbody>().useGravity  = true;
                }
                grabbedObjectName = "";
            }
            previousButtonState = false;
        }
    }
Esempio n. 4
0
    private void UpdateForces()
    {
        if (!previousButtonState && PluginImport.GetButton1State())
        {
            myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());

            if (!myObjStringName.Equals("null"))
            {
                previousButtonState = true;
                StartBoundingForces(myObjStringName);
            }
        }
        else if (previousButtonState && !PluginImport.GetButton1State())
        {
            myObjStringName     = "null";
            previousButtonState = false;
            StopForces();
        }
    }
Esempio n. 5
0
    void Update()
    {
        /***************************************************************/
        //Update Workspace as function of camera
        /***************************************************************/
        PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);

        /***************************************************************/
        //Update cube workspace
        /***************************************************************/
        myGenericFunctionsClassScript.UpdateGraphicalWorkspace();

        /***************************************************************/
        //Haptic Rendering Loop
        /***************************************************************/
        PluginImport.RenderHaptic();

        myGenericFunctionsClassScript.GetProxyValues();

        myGenericFunctionsClassScript.GetTouchedObject();

        //Debug.Log ("Button 1: " + PluginImport.GetButton1State());
        //Debug.Log ("Button 2: " + PluginImport.GetButton2State());

        //Reset the writing on the board
        if (ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName()) == "reset")
        {
            myWritingScript.cleanBoard();

            //Change the Color of the button material
            myResetButton.GetComponent <Renderer>().material.color = buttonResetColors[1];
        }
        else
        {
            myResetButton.GetComponent <Renderer>().material.color = buttonResetColors[0];
        }
    }