コード例 #1
0
 // Update on every frame
 void Update()
 {
     if (_leap.IsConnected)
     {
         var frame = _leap.Frame();
         if (frame.Hands.Count > 0)
         {
             // The Leap Motion can see a hand, so get its palm position
             Leap.Vector leapPalmPosition = frame.Hands[0].PalmPosition;
             // Convert to our vector class, and then convert to our coordinate space
             Ultrahaptics.Vector3 uhPalmPosition = _alignment.fromTrackingPositionToDevicePosition(LeapToUHVector(leapPalmPosition));
             // Create a control point object using this position, with full intensity, at 200Hz
             AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(uhPalmPosition, 1.0f, 200.0f);
             // Output this point
             _emitter.update(new List <AmplitudeModulationControlPoint> {
                 point
             });
         }
         else
         {
             Debug.LogWarning("No hands detected");
             _emitter.stop();
         }
     }
     else
     {
         Debug.LogWarning("No Leap connected");
         _emitter.stop();
     }
 }
コード例 #2
0
    /// <summary>
    /// Converts the given direction vector from world space to device space.
    /// </summary>
    /// <param name="vector">The direction vector in world space.</param>
    /// <returns>The equivalent direction vector in device space.</returns>
    public Ultrahaptics.Vector3 WorldToDeviceDirection(UnityEngine.Vector3 vector)
    {
        // Transform the world direction to the local space of the array
        var localDirection = _arrayOrigin.InverseTransformDirection(vector);
        // Construct an Ultrahaptics Vector3
        // Note that the y and z coordinates are swapped as Ultrahaptics uses a coordinate system where the positive Y-axis is up
        var ultrahapticsDirection = new Ultrahaptics.Vector3(localDirection.x, localDirection.z, localDirection.y);

        return(ultrahapticsDirection);
    }
コード例 #3
0
    // Update on every frame
    void Update()
    {
        // Set the position to be 20cm above the centre of the array
        Ultrahaptics.Vector3 position = new Ultrahaptics.Vector3(0.0f, 0.0f, 0.2f);
        // Create a control point object using this position, with full intensity, at 200Hz
        AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, 1.0f, 200.0f);

        // Output this point; technically we don't need to do this every update since nothing is changing.
        _emitter.update(new List <AmplitudeModulationControlPoint> {
            point
        });
    }
コード例 #4
0
    // This callback is called every time the device is ready to accept new control point information
    private static void Callback(TimePointStreamingEmitter emitter, OutputInterval interval, TimePoint deadline, object userObj)
    {
        // For each time point in this interval...
        foreach (TimePointOnOutputInterval tPoint in interval)
        {
            if (_firstTime)
            {
                _startTime = tPoint.seconds();
                _firstTime = false;
            }
            double t = tPoint.seconds() - _startTime;

            for (int i = 0; i < Circles.Length; i++)
            {
                Vector3 pos = Circles[i].EvaluateAt(t);
                tPoint.persistentControlPoint(i).setPosition(pos);
                tPoint.persistentControlPoint(i).setIntensity(Circles[i].Intensity);
            }
        }
    }
コード例 #5
0
    // Update on every frame
    public void Update()
    {
        // The Leap Motion can see a hand, so get its palm position
        // Convert to our vector class, and then convert to our coordinate space

        //Vive Tracker Position
        Ultrahaptics.Vector3 uhPalmPosition = new Ultrahaptics.Vector3(ViveHand.transform.position.x, ViveHand.transform.position.y, ViveHand.transform.position.z);

        // Leap Motion hand position


        // From here, we can establish how many timepoints there are in a single "iteration" of the cosine wave
        for (int i = 0; i < _timepoint_count; i++)
        {
            float intensity = VM.intensity * (1.0f - (float)Math.Cos(2.0f * Math.PI * i / _timepoint_count));
            // Set a constant position of 20cm above the array
            _positions[i]   = new Ultrahaptics.Vector3(0.0f, 0.0f, 0.2f);
            _intensities[i] = (intensity);
        }

        _emitter.setEmissionCallback(callback, null);
    }