コード例 #1
0
ファイル: TPS.cs プロジェクト: uni-bayreuth-HCI/ultrahaptics
        public static void Render()
        {
            Stop = false;
            // Create a timepoint streaming emitter
            // Note that this automatically attempts to connect to the device, if present
            _emitter = new TimePointStreamingEmitter();
            // Inform the SDK how many control points you intend to use
            // This also calculates the resulting sample rate in Hz, which is returned to the user
            uint  sample_rate       = _emitter.setMaximumControlPointCount(1);
            float desired_frequency = 200.0f;

            // From here, we can establish how many timepoints there are in a single "iteration" of the cosine wave
            _timepoint_count = (uint)(sample_rate / desired_frequency);

            _positions   = Utility.CSVtoVector();
            _intensities = new float[_positions.Length];

            // Populate the positions and intensities ahead of time, so that the callback is as fast as possible later
            // Modulate the intensity to be a complete cosine waveform over the full set of points.
            for (int i = 0; i < _positions.Length; i++)
            {
                float intensity = 0.5f * (1.0f - (float)Math.Cos(2.0f * Math.PI * i / _positions.Length));
                // Set a constant position of 20cm above the array
                //_positions[i] = new Vector3(0.0f, 0.0f, 0.2f);
                _intensities[i] = (1.0f);
            }

            // Set our callback to be called each time the device is ready for new points
            _emitter.setEmissionCallback(Callback, null);
            // Instruct the device to call our callback and begin emitting
            _emitter.start();
        }
コード例 #2
0
 private void OnDestroy()
 {
     // Dispose/destroy the emitter
     _emitter.stop();
     _emitter.Dispose();
     _emitter = null;
 }
コード例 #3
0
    public void Start()
    {
        Circles = new HapticCircle[HandPositions.Length];

        for (int i = 0; i < Circles.Length; i++)
        {
            Circles[i] = new HapticCircle()
            {
                Position = new Vector3(0, 0, 0),
                Radius   = _circleRadius,
            };
        }

        // Create a timepoint streaming emitter
        // Note that this automatically attempts to connect to the device, if present
        _emitter = new TimePointStreamingEmitter();

        // Inform the SDK how many control points you intend to use
        // This also calculates the resulting sample rate in Hz, which is returned to the user
        uint sample_rate = _emitter.setMaximumControlPointCount((uint)HandPositions.Length);

        _emitter.setExtendedOption("setFilterCutoffFrequencies", "0 0 0 0");

        // Set our callback to be called each time the device is ready for new points
        _emitter.setEmissionCallback(Callback, null);

        // Instruct the device to call our callback and begin emitting
        bool started = _emitter.start();

        if (!started)
        {
            // We couldn't use the emitter, so exit immediately
            Console.WriteLine("Could not start emitter.");
        }
    }
コード例 #4
0
ファイル: TPS.cs プロジェクト: uni-bayreuth-HCI/ultrahaptics
 public static void Stop_Emitter()
 {
     if (_emitter != null)
     {
         _emitter.stop();
         _emitter.Dispose();
         _emitter = null;
     }
 }
コード例 #5
0
ファイル: TPS.cs プロジェクト: uni-bayreuth-HCI/ultrahaptics
 static void Callback(TimePointStreamingEmitter emitter, OutputInterval interval, TimePoint deadline, object user_obj)
 {
     foreach (var tpoint in interval)
     {
         // For each control point available at this time point...
         for (int i = 0; i < tpoint.count(); ++i)
         {
             // Set the relevant data for this control point
             var point = tpoint.persistentControlPoint(i);
             point.setPosition(_positions[_current]);
             point.setIntensity(_intensities[_current]);
             point.enable();
         }
         // Increment the counter so that we get the next "step" next time
         _current = (_current + 1) % (uint)_positions.Length;
     }
 }
コード例 #6
0
    void OnEnable()
    {
        // Create a timepoint streaming emitter
        // Note that this automatically attempts to connect to the device, if present
        _emitter = new TimePointStreamingEmitter();



        //Remove Cap
        _emitter.setExtendedOption("solverCappingConstant", "3000");

        // Inform the SDK how many control points you intend to use
        // This also calculates the resulting sample rate in Hz, which is returned to the user
        sample_rate      = _emitter.setMaximumControlPointCount(1);
        _timepoint_count = (uint)(sample_rate / desired_frequency);

        //Initalize Positions and Intensities
        _positions   = new Ultrahaptics.Vector3[_timepoint_count];
        _intensities = new float[_timepoint_count];
    }
コード例 #7
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);
            }
        }
    }