コード例 #1
0
    /******************************************************************************************************************************************************************/

    //Get Proxy Position and Orientation generic function
    public void GetProxyValues()

    {
        /*Proxy Position*/

        //Convert IntPtr to Double3Array
        myProxyPosition = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition());
        Debug.Log(myProxyPosition);

        //Attach the Cursor Node
        Vector3 positionCursor = new Vector3();

        positionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyPosition);

        //Assign Haptic Values to Cursor
        myHapticClassScript.hapticCursor.transform.position = positionCursor;


        //Proxy Right - Not use in that case
        //Convert IntPtr to Double3Array
        myProxyRight = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyRight());
        //Attach the Cursor Node
        Vector3 rightCursor = new Vector3();

        rightCursor = ConverterClass.ConvertDouble3ToVector3(myProxyRight);

        //Proxy Direction
        //Convert IntPtr to Double3Array
        myProxyDirection = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyDirection());
        //Attach the Cursor Node
        Vector3 directionCursor = new Vector3();

        directionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyDirection);

        //Proxy Torque
        myProxyTorque = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyTorque());
        //Attach the Cursor Node
        Vector3 torqueCursor = new Vector3();

        torqueCursor = ConverterClass.ConvertDouble3ToVector3(myProxyTorque);

        //Set Orientation
        myHapticClassScript.hapticCursor.transform.rotation = Quaternion.LookRotation(directionCursor, torqueCursor);

        //Proxy Orientation
        //Convert IntPtr to Double4Array

        /*myProxyOrientation = ConverterClass.ConvertIntPtrToDouble4(PluginImport.GetProxyOrientation());
         *
         *      //Attach the Cursor Node
         *      Vector4 OrientationCursor = new Vector4();
         *      OrientationCursor = ConverterClass.ConvertDouble4ToVector4(myProxyOrientation);
         *
         *      //Assign Haptic Values to Cursor
         *      myHapticClassScript.hapticCursor.transform.rotation =  new Quaternion(OrientationCursor.x,OrientationCursor.y,OrientationCursor.z,OrientationCursor.w);
         * Debug.Log(OrientationCursor.x + "  " + OrientationCursor.y + "  " + OrientationCursor.z + "  " + OrientationCursor.w);*/
    }
    //Get Proxy Position and Orientation generic function for two haptic devices
    public void GetTwoProxyValues()
    {
        /*Two Proxy Position*/

        //Convert IntPtr to Double3Array
        //myTwoProxyPosition = ConverterClass.ConvertIntPtrToDouble6(PluginImport.GetDevicePosition());
        myTwoProxyPosition = ConverterClass.ConvertIntPtrToDouble6(PluginImport.GetProxyPosition());

        //Attach the Cursor Node
        Vector3 positionCursor1 = new Vector3();
        Vector3 positionCursor2 = new Vector3();

        //Assign value to position vector
        positionCursor1 = ConverterClass.ConvertDouble3ToVector3(ConverterClass.SelectHalfdouble6toDouble3(myTwoProxyPosition, 1));
        positionCursor2 = ConverterClass.ConvertDouble3ToVector3(ConverterClass.SelectHalfdouble6toDouble3(myTwoProxyPosition, 2));

        //Assign Haptic Values to Cursor
        myHapticClassScript.hapticCursor.transform.position = positionCursor1;

        //Assign Haptic Values to Cursor
        myHapticClassScript.secondHapticCursor.transform.position = positionCursor2;



        //Proxy Orientation
        //Convert IntPtr to Double4Array
        myTwoProxyOrientation = ConverterClass.ConvertIntPtrToDouble8(PluginImport.GetProxyOrientation());

        //Attach the Cursor Node
        Vector4 OrientationCursor1 = new Vector4();
        Vector4 OrientationCursor2 = new Vector4();

        //Assign value to orientation vector
        OrientationCursor1 = ConverterClass.ConvertDouble4ToVector4(ConverterClass.SelectHalfdouble8toDouble4(myTwoProxyOrientation, 1));
        OrientationCursor2 = ConverterClass.ConvertDouble4ToVector4(ConverterClass.SelectHalfdouble8toDouble4(myTwoProxyOrientation, 2));

        //Assign Haptic Values to Cursor
        myHapticClassScript.hapticCursor.transform.rotation = new Quaternion(OrientationCursor1.x, OrientationCursor1.y, OrientationCursor1.z, OrientationCursor1.w);

        //Assign Haptic Values to Cursor
        myHapticClassScript.secondHapticCursor.transform.rotation = new Quaternion(OrientationCursor2.x, OrientationCursor2.y, OrientationCursor2.z, OrientationCursor2.w);
    }
コード例 #3
0
    /******************************************************************************************************************************************************************/

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


    /******************************************************************************************************************************************************************/
    //generic function that returns the current mode



    /******************************************************************************************************************************************************************/

    //Haptic workspace generic functions



    /******************************************************************************************************************************************************************/

    //Get Proxy Position and Orientation generic function
    public void GetProxyValues()
    {
        /*Proxy Position*/

        //Convert IntPtr to Double3Array
        myProxyPosition = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition());

        //Attach the Cursor Node
        Vector3 positionCursor = new Vector3();

        positionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyPosition);

        //Assign Haptic Values to Cursor
        //myHapticClassScript.hapticCursor.transform.position = positionCursor;


        //Proxy Right - Not use in that case
        //Convert IntPtr to Double3Array

        /*myProxyRight =  ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyRight());
         * //Attach the Cursor Node
         * Vector3 rightCursor = new Vector3();
         * rightCursor = ConverterClass.ConvertDouble3ToVector3(myProxyRight);
         *
         * //Proxy Direction
         * //Convert IntPtr to Double3Array
         * myProxyDirection =  ConverterClass.ConvertIntPtrToDouble3( PluginImport.GetProxyDirection());
         * //Attach the Cursor Node
         * Vector3 directionCursor = new Vector3();
         * directionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyDirection);
         *
         * //Proxy Torque
         * myProxyTorque = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyTorque());
         * //Attach the Cursor Node
         * Vector3 torqueCursor = new Vector3();
         * torqueCursor = ConverterClass.ConvertDouble3ToVector3(myProxyTorque);
         *
         * //Set Orientation
         * myHapticClassScript.hapticCursor.transform.rotation = Quaternion.LookRotation(directionCursor,torqueCursor);*/
    }
コード例 #4
0
    /******************************************************************************************************************************************************************/

    public void GetProxyValues()
    {
        //Convert IntPtr to Double3Array
        myProxyPosition = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition());

        //Attach the Cursor Node
        Vector3 positionCursor = new Vector3();

        positionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyPosition);

        positionCursor.z *= 2f;

        myHapticClassScript.hapticCursor.transform.position = positionCursor;

        myProxyOrientation = ConverterClass.ConvertIntPtrToDouble4(PluginImport.GetProxyOrientation());

        //Attach the Cursor Node
        Vector4 OrientationCursor = new Vector4();

        OrientationCursor = ConverterClass.ConvertDouble4ToVector4(myProxyOrientation);

        //Assign Haptic Values to Cursor
        myHapticClassScript.hapticCursor.transform.rotation = new Quaternion(OrientationCursor.x, OrientationCursor.y, OrientationCursor.z, OrientationCursor.w);
    }
コード例 #5
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);
            }
        }
    }
コード例 #6
0
    //Get Proxy Position and Orientation generic function
    public void GetProxyValues(bool useTransform)
    {
        /*Proxy Position*/

        //Convert IntPtr to Double3Array
        myProxyPosition = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition());

        //Attach the Cursor Node
        Vector3 positionCursor = new Vector3();

        positionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyPosition);


        positionCursor.z *= 2f;

        //Vector3 movement = positionCursor - rb.position;

        if (useTransform)
        {
            myHapticClassScript.hapticCursor.transform.position = positionCursor;
        }
        else
        {
            rb.MovePosition(positionCursor);
        }

        //myHapticClassScript.hapticCursor.transform.position = positionCursor;



        /*
         * if (movement.magnitude > 0.1)
         * {
         *  positionCursor = myHapticClassScript.hapticCursor.transform.position;//movement.normalized * 0.01f + myHapticClassScript.hapticCursor.transform.position;
         * }*/

        //rb.velocity = new Vector3(0,0,0);
        //if (movement.magnitude > 0.1)
        //rb.velocity = movement * Time.deltaTime * 500;
        //rb.AddForce(movement);

        //else rb.velocity = new Vector3(0, 0, 0);

        //rb.MovePosition(positionCursor);
        //rb.position = positionCursor;
        //rb.MovePosition(positionCursor*2);
        //myHapticClassScript.hapticCursor.gameObject.GetComponent<Rigidbody>().MovePosition(positionCursor);
        //rb.AddForce((rb.gameObject.transform.position - positionCursor) * 5, ForceMode.VelocityChange);

        //Proxy Right - Not use in that case
        //Convert IntPtr to Double3Array

        /*myProxyRight =  ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyRight());
         *      //Attach the Cursor Node
         *      Vector3 rightCursor = new Vector3();
         *      rightCursor = ConverterClass.ConvertDouble3ToVector3(myProxyRight);
         *
         *      //Proxy Direction
         *      //Convert IntPtr to Double3Array
         *      myProxyDirection =  ConverterClass.ConvertIntPtrToDouble3( PluginImport.GetProxyDirection());
         *      //Attach the Cursor Node
         *      Vector3 directionCursor = new Vector3();
         *      directionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyDirection);
         *
         *      //Proxy Torque
         *      myProxyTorque = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyTorque());
         *      //Attach the Cursor Node
         *      Vector3 torqueCursor = new Vector3();
         *      torqueCursor = ConverterClass.ConvertDouble3ToVector3(myProxyTorque);
         *
         *      //Set Orientation
         *      myHapticClassScript.hapticCursor.transform.rotation = Quaternion.LookRotation(directionCursor,torqueCursor);*/

        //Proxy Orientation
        //Convert IntPtr to Double4Array
        myProxyOrientation = ConverterClass.ConvertIntPtrToDouble4(PluginImport.GetProxyOrientation());

        //Attach the Cursor Node
        Vector4 OrientationCursor = new Vector4();

        OrientationCursor = ConverterClass.ConvertDouble4ToVector4(myProxyOrientation);

        //Assign Haptic Values to Cursor
        if (useTransform)
        {
            myHapticClassScript.hapticCursor.transform.rotation = new Quaternion(OrientationCursor.x, OrientationCursor.y, OrientationCursor.z, OrientationCursor.w);
        }
        else
        {
            rb.MoveRotation(new Quaternion(OrientationCursor.x, OrientationCursor.y, OrientationCursor.z, OrientationCursor.w));
        }
    }