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();
        }
    }
Esempio n. 2
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;
        }
    }
Esempio n. 3
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];
        }
    }