void Update()
    {
        /***************************************************************/
        //Act on the rigid body of the Manipulated object
        // if Mode = Manipulation Mode
        /***************************************************************/
        if (PluginImport.GetMode() == 1)
        {
            ActivatingGrabbedObjectPropperties();
        }

        /***************************************************************/
        //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());
    }
    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();
        }
    }
    void Update()
    {
        /***************************************************************/
        //Act on the rigid body of the Manipulated object
        // if Mode = Manipulation Mode
        /***************************************************************/
        if (PluginImport.GetMode() == 1)
        {
            ActivatingGrabbedObjectPropperties();
        }

        /***************************************************************/
        //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());

        if (PluginImport.GetButton2State())
        {
            makeJengaBlocks();
        }

        const float rotSpeed = 1.0f;

        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), rotSpeed);
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), -rotSpeed);
        }
    }
Esempio n. 4
0
    void Update()
    {
        /***************************************************************/
        //Act on the rigid body of the Manipulated object
        // if Mode = Manipulation Mode
        /***************************************************************/
        if (PluginImport.GetMode() == 1)
        {
            ActivatingGrabbedObjectPropperties();
        }

        /***************************************************************/
        //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();

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

        //Debug.Log("Device 1: Button 1: " + PluginImport.GetButtonState(1, 1));
        //Debug.Log("Device 1: Button 2: " + PluginImport.GetButtonState(1, 2));
    }
    /******************************************************************************************************************************************************************/

    /*************************************************************/
    // Generic functionnalities
    /*************************************************************/

    /******************************************************************************************************************************************************************/
    //generic function that returns the current mode
    public void IndicateMode()
    {
        if (PluginImport.GetMode() == 0)
        {
            myHapticClassScript.HapticMode = "Simple contact";
        }
        else if (PluginImport.GetMode() == 1)
        {
            myHapticClassScript.HapticMode = "Object Manipulation";
        }
        else if (PluginImport.GetMode() == 2)
        {
            myHapticClassScript.HapticMode = "Custom Effect";
        }
        else if (PluginImport.GetMode() == 3)
        {
            myHapticClassScript.HapticMode = "Puncture";
        }
    }
Esempio n. 6
0
    void Update()
    {
        /***************************************************************/
        //Act on the rigid body of the Manipulated object
        // if Mode = Manipulation Mode
        /***************************************************************/
        if (PluginImport.GetMode() == 1)
        {
            ActivatingGrabbedObjectPropperties();
        }

        /***************************************************************/
        //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();

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

        Debug.Log("Device 1: Button 1: " + PluginImport.GetButtonState(1, 1));
        Debug.Log("Device 1: Button 2: " + PluginImport.GetButtonState(1, 2));

        //      if (PluginImport.GetButtonState(1, 2))
        //{
        //	makeJengaBlocks();
        //}

        if (PluginImport.GetButtonState(1, 1))
        {
            Debug.Log("Device 1 : Button Up Pressed");
        }
        else if (PluginImport.GetButtonState(1, 2))
        {
            Debug.Log("Device 1 : Button Down Pressed");
        }
        if (PluginImport.GetButtonState(2, 1))
        {
            Debug.Log("Device 2 : Button Up Pressed");
        }
        else if (PluginImport.GetButtonState(2, 2))
        {
            Debug.Log("Device 2 : Button Down Pressed");
        }


        const float rotSpeed = 1.0f;

        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), rotSpeed);
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), -rotSpeed);
        }
    }
Esempio n. 7
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();

        //For the Puncture Mode effect
        if (PluginImport.GetMode() == 3)
        {
            //Debug.Log ("Contact state is set to " + PluginImport.GetContact());
            //Debug.Log ("Penetration State " + PluginImport.GetPenetrationRatio());

            double[] myScp = new double[3];
            myScp = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetFirstScpPt());
            //Debug.Log (" SCP " + myScp[0] + " " + myScp[1] + " " + myScp[2]);

            Vector3 posInjectionHole;
            posInjectionHole = ConverterClass.ConvertDouble3ToVector3(myScp);
            GameObject.Find("InjectionMarker").transform.position = posInjectionHole;

            /*double[] myProx = new double[3];
             * myProx = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition());
             *
             * Vector3 posProx;
             * posProx = ConverterClass.ConvertDouble3ToVector3(myProx);
             * GameObject.Find ("ProxyTipMarker").transform.position = posProx;*/

            /*double[] myDev = new double[3];
             * myDev = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetDevicePosition());
             *
             * Vector3 posDevice;
             * posDevice = ConverterClass.ConvertDouble3ToVector3(myDev);
             * GameObject.Find ("DeviceTipMarker").transform.position = posDevice;*/

            double[] myPinch = new double[3];
            myPinch = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetPunctureDirection());

            Vector3 start = new Vector3();
            start = ConverterClass.ConvertDouble3ToVector3(myScp);
            Vector3 end = new Vector3();
            end = ConverterClass.ConvertDouble3ToVector3(myPinch);
            end.Normalize();

            Debug.DrawLine(start, start + end * maxPenetration, Color.green);

            //Ray Cast so we can determine the limitation of the puncture
            RaycastHit[] hits;
            hits = Physics.RaycastAll(start, end, maxPenetration);

            if (hits.Length != 0)
            {
                //Declare a float array to store the tissue layer
                float[] tissueLayers = new float[hits.Length];
                //Declare a string array to store the name of the tissue layer
                string[] punctObjects = new string[hits.Length];
                int      nbLayer      = 0;

                for (int i = 0; i < hits.Length; i++)
                {
                    RaycastHit hit = hits[i];

                    //Only if the object is declared as touchable
                    if (hit.collider.gameObject.tag == "Touchable")
                    {
                        tissueLayers[nbLayer] = hit.distance;
                        punctObjects[nbLayer] = hit.collider.name;
                        nbLayer++;
                    }
                }

                /*Declaration of the Puncture Stack
                 * Additionally, on the basis of the puncture stack components, the plugin setup a penetration restriction
                 * - due to the fact that Proxy Method along such constraint line is not accurate - most probably due to the fact
                 * that device position and proxy position differ because the constraint applies forces onto the device.
                 * So, the plugin impedes the proxy to penetrate in underlying layer when their popthrough values is null
                 */
                SetPunctureStack(nbLayer, punctObjects, tissueLayers);
            }
        }
    }