Example #1
0
    private void SetFrictionForce(string touchedObjectName)
    {
        //Get Touched Object initial position
        Vector3 initialPosition;

        try{
            initialPosition = dict[touchedObjectName];
        }
        catch (KeyNotFoundException e) {
            return;
        }
        //Get current cursor position
        Vector3 cursorPosition = GameObject.Find("Cursor").transform.position;

        //Get forces direction
        Vector3 forward = initialPosition - cursorPosition;

        //Set friction anchor point and direction effect
        float[] position  = new float[] { initialPosition.x, initialPosition.y, initialPosition.z };
        float[] direction = new float[] { forward.x, forward.y, forward.z };

        //Constant gain and magnitude
        float gain      = 0.2f;
        float magnitude = GetFrictionMagnitude(initialPosition, cursorPosition);

        Debug.Log("Friccion: " + magnitude);

        //Start friction force
        ForceManager.SetEnvironmentForce(ForceManager.FRICTION, FRICTION_INDEX, position, direction, gain, magnitude, 0, 0);
    }
Example #2
0
    //Collision detection
    void OnCollisionEnter(Collision collision)
    {
        //Haptic properties of the object we are colliding with
        HapticProperties props = collision.gameObject.GetComponentInChildren <HapticProperties>();

        //Get Stiffness
        float stiffness = props.stiffness;

        //Set friction or viscosity effect
        string type;

        if (stiffness >= maxStiffness)
        {
            type = ForceManager.FRICTION;
        }
        else
        {
            type = ForceManager.VISCOSITY;
        }

        //Get current cursor position
        Vector3 cursorPosition = GameObject.Find("Cursor").transform.position;

        //Set friction anchor point and direction effect
        float[] position  = new float[] { cursorPosition.x, cursorPosition.y, cursorPosition.z };
        float[] direction = new float[] { -cursorPosition.x, -cursorPosition.y, -cursorPosition.z };

        //Constant gain and magnitude
        float gain = 0.2f;

        ForceManager.SetEnvironmentForce(type, forceIndex, position, direction, gain, stiffness, 0, 0);
        Debug.Log("Force started with index " + forceIndex);
    }
Example #3
0
    private void SetSpringForce(string touchedObjectName)
    {
        //Get Touched Object initial position
        Vector3 initialPosition;

        try{
            initialPosition = dict[touchedObjectName];
        }
        catch (KeyNotFoundException e) {
            return;
        }
        //Scale position to workspace relative position and mm dimensions
        float   multiplier      = 333f;
        Vector3 touchedPosition = initialPosition * multiplier;

        //Get current cursor position
        Vector3 cursorPosition = GameObject.Find("Cursor").transform.position;

        //Get forces direction
        Vector3 forward = initialPosition - cursorPosition;

        //Set spring anchor point and direction effect
        float[] position  = new float[] { touchedPosition.x, touchedPosition.y, touchedPosition.z };
        float[] direction = new float[] { forward.x, forward.y, forward.z };

        //Constant gain and variable magnitude
        float gain      = 0.2f;
        float magnitude = GetSpringMagnitude(initialPosition, cursorPosition);

        Debug.Log("Resorte: " + magnitude);

        //Start spring force
        ForceManager.SetEnvironmentForce(ForceManager.SPRING, SPRING_INDEX, position, direction, gain, magnitude, 0, 0);
    }