예제 #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;
        }
    }
    public void GetTouchedObject()
    {
        //Convert Convert IntPtr To byte[] to String
        //string myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());//PluginImport.GetTouchedObjectName() - To be deprecated
        string myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1));

        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();
        }
    }
예제 #3
0
    void ActivatingGrabbedObjectPropperties()
    {
        GameObject grabbedObject;
        string     myObjStringName;

        if (!previousButtonState && PluginImport.GetButtonState(1, 1))
        {
            //If the object is grabbed, the gravity is deactivated and kinematic is enabled
            //myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());//GetTouchedObjectName() - To be deprecated
            myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1));

            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.GetButtonState(1, 1))
        {
            //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;
        }
    }
예제 #4
0
    void Update()
    {
        /***************************************************************/
        //Update Workspace as function of camera
        /***************************************************************/
        //PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);//To be deprecated

        //Update the Workspace as function of camera
        for (int i = 0; i < workspaceUpdateValue.Length; i++)
        {
            workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y;
        }

        PluginImport.UpdateHapticWorkspace(ConverterClass.ConvertFloatArrayToIntPtr(workspaceUpdateValue));

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

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

        //Associate the cursor object with the haptic proxy value
        myGenericFunctionsClassScript.GetProxyValues();

        //myGenericFunctionsClassScript.GetTouchedObject();

        //Reset the writing on the board
        //if(ConverterClass.ConvertIntPtrToByteToString( PluginImport.GetTouchedObjectName()) == "reset") // GetTouchedObjectName - To be deprecated
        if (ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1)) == "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];
        }
    }
예제 #5
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();
        }
    }
예제 #6
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];
        }
    }