示例#1
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));
        }
    }
示例#2
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();

        //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));
    }
示例#3
0
    void Start()
    {
        rotation = Quaternion.Euler(0, 90, 0);             // rotation of 90 degrees about y axis

        int size = 10;

        target = new GameObject[size];

        visibility = GameObject.FindWithTag("Cursor");          // search object with tag cursor


        if (PluginImport.InitHapticDevice())
        {
            Debug.Log("OpenGL Context Launched");
            Debug.Log("Haptic Device Launched");
        }
        else
        {
            Debug.Log("Haptic Device cannot be launched");
        }


        /***************************************************************/
        //Launch the Haptic Event for all different haptic objects
        /***************************************************************/
        PluginImport.LaunchHapticEvent();
    }
    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 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);

            /***************************************************************/
        }
    }
    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();
    }
示例#7
0
    void Update()
    {
        /***************************************************************/
        //Update forces
        /***************************************************************/
        UpdateForces();

        /***************************************************************/
        //Update UI
        /***************************************************************/
        UpdateUI();

        /***************************************************************/
        //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();
        myGenericFunctionsClassScript.manipulateObject();
    }
示例#8
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;
        }
    }
示例#9
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();
    }
示例#10
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);//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();
        }
        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();
    }
示例#11
0
文件: Writing.cs 项目: timguoqk/FOOD
    // Update is called once per frame
    void Update()
    {
        bool button1State = PluginImport.GetButton1State();

        if (button1State && !previousButton1State)
        {
            penColorNum = (penColorNum + 1) % penColors.Length;
        }
        previousButton1State = button1State;

        //if (PluginImport.GetButton2State()) cleanBoard();
        bool eraseState = PluginImport.GetButton2State();

        if (eraseState)
        {
            changePenColor(new Color(0.25f, 0.25f, 0.25f));
        }
        else
        {
            changePenColor(penColorNum);
        }

        bool shouldDraw = PluginImport.GetContact() && (myCounter > 0);

        if (shouldDraw)
        {
            double[] pos       = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition());
            double[] dir       = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyDirection());
            Vector3  position  = new Vector3((float)pos[0], (float)pos[1], (float)pos[2]);
            Vector3  direction = new Vector3((float)dir[0], (float)dir[1], (float)dir[2]);

            double[] realPos      = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetDevicePosition());
            Vector3  realPosition = new Vector3((float)realPos[0], (float)realPos[1], (float)realPos[2]);
            float    force        = (realPosition - position).magnitude;
            if (force > 1.0f)
            {
                force = 1.0f;
            }

            RaycastHit hitInfo = new RaycastHit();
            bool       hasHit  = Physics.Raycast(position, direction, out hitInfo);

            if (previousShouldDraw)
            {
                drawBlobLine(previousCoord, hitInfo.textureCoord, blobRadius, penColors[penColorNum], force, blobSteps, eraseState);
            }
            else
            {
                drawBlob(hitInfo.textureCoord, blobRadius, penColors[penColorNum], force, eraseState);
            }
            previousCoord = hitInfo.textureCoord;

            boardTexture.SetPixels(boardPixels);
            boardTexture.Apply();
        }
        previousShouldDraw = shouldDraw;
        myCounter++;
    }
示例#12
0
    // Use this for initialization
    void Start()
    {
        Type = "constant";
        setIntPtr();
        PluginImport.SetEffect(_type, effect_index, gain, magnitude, duration, frequency, _position, _direction);
        PluginImport.StartEffect(effect_index);

        InvokeRepeating("ChangeForce", 2.0f, 0.5f);
    }
示例#13
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);*/
    }
 void OnDisable()
 {
     if (PluginImport.HapticCleanUp())
     {
         Debug.Log("Haptic Context CleanUp");
         Debug.Log("Desactivate Device");
         Debug.Log("OpenGL Context CleanUp");
     }
 }
示例#15
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));
    }
    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();
        }
    }
示例#17
0
 // Update is called once per frame
 void Update()
 {
     if (!previousButtonState && PluginImport.GetButton2State())
     {
         light.enabled       = true;
         previousButtonState = true;
     }
     else if (previousButtonState && !PluginImport.GetButton2State())
     {
         light.enabled       = false;
         previousButtonState = false;
     }
 }
示例#18
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);
    }
示例#19
0
    void ChangeForce()
    {
        Vector3 vec = transform.position - target.position;

        magnitude          = (vec.magnitude) / 1000;
        directionEffect[0] = vec[0];
        directionEffect[1] = vec[1];
        directionEffect[2] = vec[2];
        setIntPtr();
        PluginImport.StopEffect(effect_index);
        //Set the effect
        PluginImport.SetEffect(_type, effect_index, gain, magnitude, duration, frequency, _position, _direction);
        PluginImport.StartEffect(effect_index);
    }
    /******************************************************************************************************************************************************************/

    public void GetHapticWorkSpace()
    {
        //Convert IntPtr to float3Array
        myWSPosition = ConverterClass.ConvertIntPtrToFloat3(PluginImport.GetWorkspacePosition());

        //Convert IntPtr to float3Array
        myWSSize = ConverterClass.ConvertIntPtrToFloat3(PluginImport.GetWorkspaceSize());

        //Refine my workspaceSize in the Unity Editor in case it has been changed
        myHapticClassScript.myWorkSpacePosition = ConverterClass.AssignFloat3ToFloat3(myWSPosition);

        //Refine my workspaceSize in the Unity Editor in case it has been changed
        myHapticClassScript.myWorkSpaceSize = ConverterClass.AssignFloat3ToFloat3(myWSSize);
    }
示例#21
0
    void Update()
    {
        if (cochlea == null)
        {
            cochlea = StatsManager.instance.GetActiveCochlea();
        }

        if (PluginImport.GetButtonState(1, 2))
        {
            if (!hasStarted) // user hasn't pressed start
            {
                DetachCochlea();
                hasStarted = true;
            }
        }

        if (PluginImport.GetButtonState(1, 1) & !hasEnded)
        {
            hasEnded = true;
            StatsManager.instance.SetFullReset(false);
            simMonitor.IncrementReset();
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }

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

    //Haptic workspace generic functions
    public void SetHapticWorkSpace()
    {
        //Convert float3Array to IntPtr
        IntPtr dstPosPtr = ConverterClass.ConvertFloat3ToIntPtr(myHapticClassScript.myWorkSpacePosition);

        //Convert float3Array to IntPtr
        IntPtr dstSizePtr = ConverterClass.ConvertFloat3ToIntPtr(myHapticClassScript.myWorkSpaceSize);

        //Set Haptic Workspace for separate update
        //PluginImport.SetWorkspacePosition(dstPosPtr);
        //PluginImport.SetWorkspaceSize(dstSizePtr);

        //Set Haptic Workspace
        PluginImport.SetWorkspace(dstPosPtr, dstSizePtr);
    }
    //Get two haptic workspaces for two haptic device
    public void GetTwoHapticWorkSpaces()
    {
        //Convert IntPtr to float6Array
        myTwoWsPosition = ConverterClass.ConvertIntPtrToFloat6(PluginImport.GetWorkspacePosition());

        //Convert IntPtr to float6Array
        myTwoWsSize = ConverterClass.ConvertIntPtrToFloat6(PluginImport.GetWorkspaceSize());

        //Refine my workspaceSize in the Unity Editor in case it has been changed
        myHapticClassScript.myWorkSpacePosition       = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsPosition, 1); //Workspace position for device1
        myHapticClassScript.mySecondWorkSpacePosition = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsPosition, 2); //Workspace position for device2

        //Refine my workspaceSize in the Unity Editor in case it has been changed
        myHapticClassScript.myWorkSpaceSize       = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsSize, 1); //Workspace size for device1
        myHapticClassScript.mySecondWorkSpaceSize = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsSize, 2); //Workspace size for device2
    }
    void Update()
    {
        /***************************************************************/
        //Update two Workspaces as function of camera for each
        /***************************************************************/
        //PluginImport.UpdateTwoWorkspace(myHapticCamera.transform.rotation.eulerAngles.y, myHapticCamera.transform.rotation.eulerAngles.y);

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

        /***************************************************************/
        //Update 2 cubes workspaces
        /***************************************************************/
        myGenericFunctionsClassScript.UpdateTwoGraphicalWorkspaces();

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

        /***************************************************************/
        //Update Haptic Object Transform
        /***************************************************************/
        myGenericFunctionsClassScript.UpdateHapticObjectMatrixTransform();

        //myGenericFunctionsClassScript.GetProxyValues();
        myGenericFunctionsClassScript.GetTwoProxyValues();

        //myGenericFunctionsClassScript.GetTouchedObject();

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

        /*if(PluginImport.GetHapticContact(1))
         *  Debug.Log("Device 1 touches: " + PluginImport.GetTouchedObjId(1) + " " + ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1)));
         * if (PluginImport.GetHapticContact(2))
         *  Debug.Log("Device 2 touches: " + PluginImport.GetTouchedObjId(2) + " " + ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(2)));*/
    }
    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);
    }
示例#27
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;
        }
    }
示例#28
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];
        }
    }
示例#29
0
    // Update is called once per frame
    void Update()
    {
        double[] pos      = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetDevicePosition());
        Vector3  position = new Vector3((float)pos [0], (float)pos [1], (float)pos [2]);


        button1 = PluginImport.GetButton1State();         // getting state of button 1 on phantom
        Debug.Log(button1 + "     " + button2);           // printing button 1 and button 2 state on console
        if (button1 && !previousbutton1state)             // routine for writing coordinate values to text file
        {
            //////////////////////////////////////////////////////////////////
            using (StreamWriter writer = new StreamWriter("G:\\log.txt", true))

                // Loop through ten numbers.
                for (int i = 0; i < 3; i++)
                {
                    //Write format string to file.
                    //writer.Write ("{0:0.0} ", position [i]);
                    writer.WriteLine(position);
                }                 // for loop

            using (StreamWriter writer =
                       new StreamWriter("G:\\log.txt", true)) {
                writer.WriteLine("\r\n");
//				//writer.WriteLine("First target coordinates");
            }             // stream
//
        }

        previousbutton1state = button1;
        /////////////////////////////////////////////////////////////////////

        button2 = PluginImport.GetButton2State();
        if (button2 && !previousbutton2state)                                      // Controlling invisibility of the pointer object
        {
            visibility.GetComponent <MeshRenderer> ().enabled = false;             // making object invisible
        } // update
        previousbutton2state = button2;

        if (Input.GetKeyDown(KeyCode.A))
        {
            visibility.GetComponent <MeshRenderer> ().enabled = true;                           // Making object visible again on pressing button 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";
        }
    }
示例#31
0
    void Start()
    {
        GameObject bc = GameObject.Find ("BehaviorController");
        eventManager = bc.GetComponent<EventManager> ();
        macros = bc.GetComponent<Macros> ();

        objSelector = GameObject.Find ("BlocksWorld").GetComponent<ObjectSelector> ();

        commBridge = GameObject.Find ("CommunicationsBridge").GetComponent<PluginImport> ();

        //inputRect = new Rect (5, 5, 50, 25);
        inputRect = new Rect (5, 5, 365, inputHeight);
    }