예제 #1
0
    public bool addDevice(string deviceName, VRPNDeviceType type)
    {
        Debug.Log(deviceName);
        VRPNDevice device = new VRPNDevice(deviceName, type);

        if (true || (availableDevices.Contains(deviceName) && !devices.ContainsKey(deviceName)))
        {
            devices.Add(deviceName, device);
            switch (type)
            {
            case VRPNDeviceType.Phantom:
                Debug.Log("Instanciating VRPNPicker");
                GameObject go = (GameObject)GameObject.Instantiate(Resources.Load("VRPN/VRPNPicker", typeof(GameObject)), Vector3.zero, Quaternion.identity);
                Debug.Log("Configuring VRPNPickerController");
                VRPNPickerController s1 = go.GetComponent <VRPNPickerController>();
                if (s1)
                {
                    s1.setManager(this);
                    s1.setDeviceName(deviceName);
                }

                Debug.Log("After pickercontroller");

                VRPNButtonController s2 = go.GetComponent <VRPNButtonController>();
                if (s2)
                {
                    s2.setManager(this);
                    s2.setDeviceName(deviceName);
                }

                VRPNForceFeedback s3 = go.GetComponent <VRPNForceFeedback>();
                if (s3)
                {
                    s3.setManager(this);
                    s3.setDeviceName(deviceName);
                    if (!s3.startDeviceInLib())
                    {
                        Debug.Log(":: VRPNManager :: Can't activate Force Feedback");
                    }
                }

                break;

            case VRPNDeviceType.Mouse3DConnexion:
                VRPNAnalogController s = GameObject.FindGameObjectWithTag("LoadBox").GetComponent <VRPNAnalogController>();
                s.setManager(this);
                break;

            default:
                break;
            }
            return(true);
        }
        return(false);
    }
예제 #2
0
    // Magnetic force
    public void setForceForAtomPosition(Vector3 atomPosition)
    {
        if (!initialized)
        {
            return;
        }

        // Debug.Log ("setForceForAtomPosition");

        // Compute the distance between the atom and the picker for each axis
        Vector3 forceFactor = (atomPosition - transform.position);

        // Compute the absolute distance between the atom and the picker
        float distance = Mathf.Sqrt(Mathf.Pow(forceFactor.x, 2) + Mathf.Pow(forceFactor.y, 2) + Mathf.Pow(forceFactor.z, 2));

        // Compute a gaussian factor
        float gaussian = Gaussian(distance, gaussianMean, gaussianDeviation);

        VRPNPickerController pickerScript = (VRPNPickerController)gameObject.GetComponent <VRPNPickerController>();
        Vector3 trackerVelocity           = new Vector3(1.0f, 1.0f, 1.0f);

        if (pickerScript != null)
        {
            trackerVelocity = pickerScript.getTrackerVelocity();
        }

        forceFactor /= distance;
        forceFactor *= gaussian * magnetFeedbackScale;

        Vector3 feedbackForce = GameObject.FindGameObjectWithTag("LoadBox").transform.worldToLocalMatrix *forceFactor;

        feedbackForce.x -= trackerVelocity.x;
        feedbackForce.y -= trackerVelocity.y;
        feedbackForce.z -= trackerVelocity.z;

        // Send the desired feedback to server
        // z axis is inverted
        VRPNForceFeedbackSetForce(feedbackForce.x, feedbackForce.y, -feedbackForce.z);
    }