public void UpdateHapticObjectMatrixTransform()
    {
        //Get array of all object with tag "Touchable"
        GameObject[] myObjects = GameObject.FindGameObjectsWithTag("Touchable") as GameObject[];

        for (int ObjId = 0; ObjId < myObjects.Length; ObjId++)
        {
            /***************************************************************/
            //Set the Transformation Matric of the Object
            /***************************************************************/
            //Get the Transformation matrix from object
            Matrix4x4 m = new Matrix4x4();
            //Build a transform Matrix from the translation/rotation and Scale parameters fo the object
            m.SetTRS(myObjects[ObjId].transform.position, myObjects[ObjId].transform.rotation, myObjects[ObjId].transform.localScale);

            //Convert Matrix4x4 to double16
            double[] matrix = ConverterClass.ConvertMatrix4x4ToDouble16(m);
            //Convert Double16 To IntPtr
            IntPtr dstDoublePtr = ConverterClass.ConvertDouble16ToIntPtr(matrix);

            //Convert String to Byte[] (char* in C++) and Byte[] to IntPtr
            IntPtr dstCharPtr = ConverterClass.ConvertStringToByteToIntPtr(myObjects[ObjId].name);

            //Send the transformation Matrix of the object
            PluginImport.SetObjectTransform(ObjId, dstCharPtr, dstDoublePtr);

            /***************************************************************/
        }
    }
示例#2
0
    //Haptic Properties generic function
    private void ReadHapticProperties(int ObjId, GameObject obj)
    {
        myHapticPropertiesScript = obj.transform.GetComponent <HapticProperties>();

        if (myHapticPropertiesScript == null)        //Set default Values
        {
            PluginImport.SetStiffness(ObjId, 1.0f);
            PluginImport.SetDamping(ObjId, 0.0f);
            PluginImport.SetStaticFriction(ObjId, 0.0f);
            PluginImport.SetDynamicFriction(ObjId, 0.0f);
            PluginImport.SetTangentialStiffness(ObjId, 0.0f);
            PluginImport.SetTangentialDamping(ObjId, 0.0f);
            PluginImport.SetPopThrough(ObjId, 0.0f);
            PluginImport.SetPuncturedStaticFriction(ObjId, 0.0f);
            PluginImport.SetPuncturedDynamicFriction(ObjId, 0.0f);
            PluginImport.SetMass(ObjId, 0.0f);
            PluginImport.SetFixed(ObjId, true);
            Debug.Log("Haptic Characteristics not set for " + obj.name);
        }
        else
        {
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("stiffness"), myHapticPropertiesScript.stiffness);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("damping"), myHapticPropertiesScript.damping);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("staticFriction"), myHapticPropertiesScript.staticFriction);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("dynamicFriction"), myHapticPropertiesScript.dynamicFriction);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("tangentialStiffness"), myHapticPropertiesScript.tangentialStiffness);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("tangentialDamping"), myHapticPropertiesScript.tangentialDamping);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("popThrough"), myHapticPropertiesScript.popThrough);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("puncturedStaticFriction"), myHapticPropertiesScript.puncturedStaticFriction);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("puncturedDynamicFriction"), myHapticPropertiesScript.puncturedDynamicFriction);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("mass"), myHapticPropertiesScript.mass);
            PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("fixed"), System.Convert.ToInt32(myHapticPropertiesScript.fixedObj));
        }
    }
示例#3
0
    void Start()
    {
        if (PluginImport.InitTwoHapticDevices(ConverterClass.ConvertStringToByteToIntPtr(device1Name), ConverterClass.ConvertStringToByteToIntPtr(device2Name)))
        {
            Debug.Log("OpenGL Context Launched");
            Debug.Log("Haptic Device Launched");


            myGenericFunctionsClassScript.SetTwoHapticWorkSpaces();
            myGenericFunctionsClassScript.GetTwoHapticWorkSpaces();

            //Update the Workspace as function of camera - Note that two different reference can be used to update each workspace
            for (int i = 0; i < workspaceUpdateValue.Length; i++)
            {
                workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y;
            }

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


            //Set Mode of Interaction

            /*
             * Mode = 0 Contact
             * Mode = 1 Manipulation - So objects will have a mass when handling them
             * Mode = 2 Custom Effect - So the haptic device simulate vibration and tangential forces as power tools
             * Mode = 3 Puncture - So the haptic device is a needle that puncture inside a geometry
             */
            PluginImport.SetMode(ModeIndex);
            //Show a text descrition of the mode
            myGenericFunctionsClassScript.IndicateMode();
        }
        else
        {
            Debug.Log("Haptic Device cannot be launched");
        }


        /***************************************************************/
        //Set Environmental Haptic Effect
        /***************************************************************/
        // Constant Force Example - We use this environmental force effect to simulate the weight of the cursor
        myGenericFunctionsClassScript.SetEnvironmentConstantForce();


        /***************************************************************/
        //Setup the Haptic Geometry in the OpenGL context
        //And read haptic characteristics
        /***************************************************************/
        myGenericFunctionsClassScript.SetHapticGeometry();

        //Get the Number of Haptic Object
        Debug.Log("Total Number of Haptic Objects: " + PluginImport.GetHapticObjectCount());

        /***************************************************************/
        //Launch the Haptic Event for all different haptic objects
        /***************************************************************/
        PluginImport.LaunchHapticEvent();
    }
示例#4
0
    void Start()
    {
        if (PluginImport.InitHapticDevice())
        {
            Debug.Log("OpenGL Context Launched");
            Debug.Log("Haptic Device Launched");

            getInitialParameters();

            myGenericFunctionsClassScript.SetHapticWorkSpace();
            myGenericFunctionsClassScript.GetHapticWorkSpace();

            //Update Workspace as function of camera
            PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);

            //Set Mode of Interaction

            /*
             * Mode = 0 Contact
             * Mode = 1 Manipulation - So objects will have a mass when handling them
             * Mode = 2 Custom Effect - So the haptic device simulate vibration and tangential forces as power tools
             * Mode = 3 Puncture - So the haptic device is a needle that puncture inside a geometry
             */
            PluginImport.SetMode(1);
            //Show a text descrition of the mode
            myGenericFunctionsClassScript.IndicateMode();


            //Set the touchable face(s)
            PluginImport.SetTouchableFace(ConverterClass.ConvertStringToByteToIntPtr(TouchableFace));
        }
        else
        {
            Debug.Log("Haptic Device cannot be launched");
        }


        /***************************************************************/
        //Set Environmental Haptic Effect
        /***************************************************************/

        // Constant Force Example - We use this environmental force effect to simulate the weight of the cursor
        //myGenericFunctionsClassScript.SetEnvironmentConstantForce();

        /***************************************************************/
        //Setup the Haptic Geometry in the OpenGL context
        /***************************************************************/

        myGenericFunctionsClassScript.SetHapticGeometry();


        //Get the Number of Haptic Object
        //Debug.Log ("Total Number of Haptic Objects: " + PluginImport.GetHapticObjectCount());

        /***************************************************************/
        //Launch the Haptic Event for all different haptic objects
        /***************************************************************/
        PluginImport.LaunchHapticEvent();
    }
示例#5
0
 void setIntPtr()
 {
     //convert String to IntPtr
     _type = ConverterClass.ConvertStringToByteToIntPtr(Type);
     //Convert float[3] to intptr
     _position = ConverterClass.ConvertFloat3ToIntPtr(positionEffect);
     //Convert float[3] to intptr
     _direction = ConverterClass.ConvertFloat3ToIntPtr(directionEffect);
 }
示例#6
0
    void SetPunctureStack(int nbLayer, string[] name, float[] array)
    {
        IntPtr[] objname = new IntPtr[nbLayer];
        //Assign object encounter along puncture vector to the Object array
        for (int i = 0; i < nbLayer; i++)
        {
            objname[i] = ConverterClass.ConvertStringToByteToIntPtr(name[i]);
        }

        PluginImport.SetPunctureLayers(nbLayer, objname, ConverterClass.ConvertFloatArrayToIntPtr(array));
    }
示例#7
0
    public static void SetEnvironmentForce(string nType, int index, float[] positionEffect, float[] directionEffect, float gain, float magnitude, float duration, float frequency)
    {
        //convert String to IntPtr
        IntPtr type = ConverterClass.ConvertStringToByteToIntPtr(nType);
        //Convert float[3] to intptr
        IntPtr position = ConverterClass.ConvertFloat3ToIntPtr(positionEffect);
        //Convert float[3] to intptr
        IntPtr direction = ConverterClass.ConvertFloat3ToIntPtr(directionEffect);

        //Set the effect
        PluginImport.SetEffect(type, index, gain, magnitude, duration, frequency, position, direction);
        PluginImport.StartEffect(index);
    }
    public void SetTangentialForce()
    {
        myTangentialForceScript = transform.GetComponent <TangentialForce>();

        /*****************************
        * Tangential Force Example
        *****************************/
        //convert String to IntPtr
        IntPtr type = ConverterClass.ConvertStringToByteToIntPtr(myTangentialForceScript.Type);
        //Convert float[3] to intptr
        IntPtr position = ConverterClass.ConvertFloat3ToIntPtr(myTangentialForceScript.positionEffect);
        //Convert float[3] to intptr
        IntPtr direction = ConverterClass.ConvertFloat3ToIntPtr(myTangentialForceScript.directionEffect);

        //Set the effect
        PluginImport.SetEffect(type, myTangentialForceScript.effect_index, myTangentialForceScript.gain, myTangentialForceScript.magnitude, myTangentialForceScript.duration, myTangentialForceScript.frequency, position, direction);
        PluginImport.StartEffect(myTangentialForceScript.effect_index);
    }
    /******************************************************************************************************************************************************************/

    //Haptic Effects generic functions
    public void SetEnvironmentViscosity()
    {
        //Get data from script
        myViscosityScript = transform.GetComponent <ViscosityEffect>();


        /*****************************
        * Viscous Force Example
        *****************************/
        //convert String to IntPtr
        IntPtr type = ConverterClass.ConvertStringToByteToIntPtr(myViscosityScript.Type);
        //Convert float[3] to intptr
        IntPtr position = ConverterClass.ConvertFloat3ToIntPtr(myViscosityScript.positionEffect);
        //Convert float[3] to intptr
        IntPtr direction = ConverterClass.ConvertFloat3ToIntPtr(myViscosityScript.directionEffect);

        //Set the effect
        PluginImport.SetEffect(type, myViscosityScript.effect_index, myViscosityScript.gain, myViscosityScript.magnitude, myViscosityScript.duration, myViscosityScript.frequency, position, direction);
        PluginImport.StartEffect(myViscosityScript.effect_index);
    }
示例#10
0
    void Start()
    {
        blocks = new GameObject[height * 3];
        makeJengaBlocks();

        if (PluginImport.InitHapticDevice())
        {
            Debug.Log("OpenGL Context Launched");
            Debug.Log("Haptic Device Launched");

            myGenericFunctionsClassScript.SetHapticWorkSpace();
            myGenericFunctionsClassScript.GetHapticWorkSpace();

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

            //Set Mode of Interaction

            /*
             * Mode = 0 Contact
             * Mode = 1 Manipulation - So objects will have a mass when handling them
             * Mode = 2 Custom Effect - So the haptic device simulate vibration and tangential forces as power tools
             * Mode = 3 Puncture - So the haptic device is a needle that puncture inside a geometry
             */
            PluginImport.SetMode(ModeIndex);
            //Show a text descrition of the mode
            myGenericFunctionsClassScript.IndicateMode();

            //Set the touchable face(s)
            PluginImport.SetTouchableFace(ConverterClass.ConvertStringToByteToIntPtr(TouchableFace));
        }
        else
        {
            Debug.Log("Haptic Device cannot be launched");
        }

        /***************************************************************/
        //Set Environmental Haptic Effect
        /***************************************************************/
        // Viscous Force Example
        myGenericFunctionsClassScript.SetEnvironmentViscosity();

        // Constant Force Example - We use this environmental force effect to simulate the weight of the cursor
        myGenericFunctionsClassScript.SetEnvironmentConstantForce();

        // Friction Force Example
        //myGenericFunctionsClassScript.SetEnvironmentFriction();

        // Spring Force Example
        //myGenericFunctionsClassScript.SetEnvironmentSpring();


        /***************************************************************/
        //Setup the Haptic Geometry in the OpenGL context
        //And read haptic characteristics
        /***************************************************************/
        myGenericFunctionsClassScript.SetHapticGeometry();

        //Get the Number of Haptic Object
        //Debug.Log ("Total Number of Haptic Objects: " + PluginImport.GetHapticObjectCount());

        /***************************************************************/
        //Launch the Haptic Event for all different haptic objects
        /***************************************************************/
        PluginImport.LaunchHapticEvent();
    }
示例#11
0
    void Start()
    {
        if (PluginImport.InitHapticDevice())
        {
            Debug.Log("OpenGL Context Launched");
            Debug.Log("Haptic Device Launched");

            myGenericFunctionsClassScript.SetHapticWorkSpace();
            myGenericFunctionsClassScript.GetHapticWorkSpace();

            //Update Workspace as function of camera
            PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);

            //Set Mode of Interaction

            /*
             * Mode = 0 Contact
             * Mode = 1 Manipulation - So objects will have a mass when handling them
             * Mode = 2 Custom Effect - So the haptic device simulate vibration and tangential forces as power tools
             * Mode = 3 Puncture - So the haptic device is a needle that puncture inside a geometry
             */
            PluginImport.SetMode(ModeIndex);
            //Show a text descrition of the mode
            myGenericFunctionsClassScript.IndicateMode();

            //Set the touchable face(s)
            PluginImport.SetTouchableFace(ConverterClass.ConvertStringToByteToIntPtr(TouchableFace));
        }
        else
        {
            Debug.Log("Haptic Device cannot be launched");
        }

        /***************************************************************/
        //Set Environmental Haptic Effect
        /***************************************************************/
        // Viscous Force Example
        // myGenericFunctionsClassScript.SetEnvironmentViscosity();

        // Constant Force Example - We use this environmental force effect to simulate the weight of the cursor
        // myGenericFunctionsClassScript.SetEnvironmentConstantForce();

        //Custom Force Effect Vibration Motor
        // myGenericFunctionsClassScript.SetVibrationMotor();

        //Custom Force Effect Vibration at Contact//Good for p1ulsation
        // myGenericFunctionsClassScript.SetVibrationContact();

        //Custom Tangential Force corresponding to that of a rotating power tool (e.g. Drill, Polisher, Grinder)
        // if tool is angled set direction to 0,1,0 otherwise it does not matter (Tool will be straight)
        //  myGenericFunctionsClassScript.SetTangentialForce();


        /***************************************************************/
        //Setup the Haptic Geometry in the OpenGL context
        /***************************************************************/
        myGenericFunctionsClassScript.SetHapticGeometry();

        //Get the Number of Haptic Object
        //Debug.Log ("Total Number of Haptic Objects: " + PluginImport.GetHapticObjectCount());

        /***************************************************************/
        //Launch the Haptic Event for all different haptic objects
        /***************************************************************/
        PluginImport.LaunchHapticEvent();
    }
    /******************************************************************************************************************************************************************/

    public void SetHapticGeometry()
    {
        //Get array of all object with tag "Touchable"
        GameObject[] myObjects = GameObject.FindGameObjectsWithTag("Touchable") as GameObject[];

        for (int ObjId = 0; ObjId < myObjects.Length; ObjId++)
        {
            /***************************************************************/
            //Set the Transformation Matric of the Object
            /***************************************************************/
            //Get the Transformation matrix from object
            Matrix4x4 m = new Matrix4x4();

            //Build a transform Matrix from the translation/rotation and Scale parameters fo the object - Local Matrix
            //m.SetTRS(myObjects[ObjId].transform.position,myObjects[ObjId].transform.rotation,myObjects[ObjId].transform.localScale);

            //Build a transform Matrix from the translation/rotation and Scale parameters fo the object - Glabal Matrix
            m = myObjects[ObjId].transform.localToWorldMatrix;

            //Convert Matrix4x4 to double16
            double[] matrix = ConverterClass.ConvertMatrix4x4ToDouble16(m);
            //Convert Double16 To IntPtr
            IntPtr dstDoublePtr = ConverterClass.ConvertDouble16ToIntPtr(matrix);

            //Convert String to Byte[] (char* in C++) and Byte[] to IntPtr
            IntPtr dstCharPtr = ConverterClass.ConvertStringToByteToIntPtr(myObjects[ObjId].name);

            //Send the transformation Matrix of the object
            PluginImport.SetObjectTransform(ObjId, dstCharPtr, dstDoublePtr);

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

            /***************************************************************/
            //Set the Mesh of the Object
            /***************************************************************/
            //Get Mesh of Object
            Mesh      mesh     = myObjects[ObjId].GetComponent <MeshFilter>().mesh;
            Vector3[] vertices = mesh.vertices;

            int[] triangles = mesh.triangles;

            //Reorganize the Array
            float[] verticesToSend = ConverterClass.ConvertVector3ArrayToFloatArray(vertices);
            //Allocate Memory according to needed space for float* (3*4)
            IntPtr dstVerticesArrayPtr = Marshal.AllocCoTaskMem(vertices.Length * 3 * Marshal.SizeOf(typeof(float)));
            //Copy to dstPtr
            Marshal.Copy(verticesToSend, 0, dstVerticesArrayPtr, vertices.Length * 3);

            //Convert Int[] to IntPtr
            IntPtr dstTrianglesArrayPtr = ConverterClass.ConvertIntArrayToIntPtr(triangles);

            //Send the Raw Mesh of the object - transformation are not applied on the Mesh vertices
            PluginImport.SetObjectMesh(ObjId, dstVerticesArrayPtr, dstTrianglesArrayPtr, vertices.Length, triangles.Length);
            /***************************************************************/

            /***************************************************************/
            //Get the haptic parameter configuration
            /***************************************************************/
            ReadHapticProperties(ObjId, myObjects[ObjId]);
            /***************************************************************/
        }
    }
示例#13
0
    void Start()
    {
        if (PluginImport.InitHapticDevice())
        {
            Debug.Log("OpenGL Context Launched");
            Debug.Log("Haptic Device Launched");

            myGenericFunctionsClassScript.SetHapticWorkSpace();
            myGenericFunctionsClassScript.GetHapticWorkSpace();

            //Update Workspace as function of camera
            PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);

            //Set Mode of Interaction

            /*
             * Mode = 0 Contact
             * Mode = 1 Manipulation - So objects will have a mass when handling them
             * Mode = 2 Custom Effect - So the haptic device simulate vibration and tangential forces as power tools
             * Mode = 3 Puncture - So the haptic device is a needle that puncture inside a geometry
             */
            PluginImport.SetMode(3);
            //Show a text descrition of the mode
            myGenericFunctionsClassScript.IndicateMode();

            //Define a Penetration direction Vector - useful for brain biopsy for instance.
            //For realism, the orientation of the needle will need to be detached from that of the haptic device
            //The new orientation on local Z of the needle will be that indicated by the vector set below.

            /*double[] injectionDir = new double[3]{0.0f,0.0f,1.0f};
             * PluginImport.SetPunctureDirection(ConverterClass.ConvertDouble3ToIntPtr(injectionDir));*/

            //Set the lenght of the syringue needle to penetrate inside the tissue
            PluginImport.SetMaximumPunctureLenght(maxPenetration);

            //Set the touchable face(s)
            PluginImport.SetTouchableFace(ConverterClass.ConvertStringToByteToIntPtr(TouchableFace));
        }
        else
        {
            Debug.Log("Haptic Device cannot be launched");
        }


        /***************************************************************/
        //Set Environmental Haptic Effect
        /***************************************************************/

        // Constant Force Example - We use this environmental force effect to simulate the weight of the cursor
        //myGenericFunctionsClassScript.SetEnvironmentConstantForce();

        /***************************************************************/
        //Setup the Haptic Geometry in the OpenGL context
        /***************************************************************/
        myGenericFunctionsClassScript.SetHapticGeometry();

        //Get the Number of Haptic Object
        //Debug.Log ("Total Number of Haptic Objects: " + PluginImport.GetHapticObjectCount());

        /***************************************************************/
        //Launch the Haptic Event for all different haptic objects
        /***************************************************************/
        PluginImport.LaunchHapticEvent();
    }