// 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(); } }
/// <summary> /// this function is to update the live rendering points which comes from ultraleap live rendering feature /// </summary> /// <param name="updated_x"> the new x coordinate</param> /// <param name="updated_y"> the new y coordinate</param> public static void updateLiveRenderPoint(float updated_x, float updated_y) { if (emitter != null) { Vector3 position = new Vector3((float)(updated_x * Ultrahaptics.Units.metres), (float)(updated_y * Ultrahaptics.Units.metres), (float)(0.20 * Ultrahaptics.Units.metres)); AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; emitter.update(points); Console.WriteLine(updated_x + " " + updated_y); } if (Stop) { try { emitter.update(new List <AmplitudeModulationControlPoint> { }); emitter.Dispose(); emitter = null; } catch (Exception e) { Console.WriteLine(e.Message); } Stop = false; return; } }
public static void Main(string[] args) { // Create an emitter, which connects to the first connected device AmplitudeModulationEmitter emitter = new AmplitudeModulationEmitter(); // Set the position of the new control point Vector3 position = new Vector3(0.0f, 0.0f, 0.2f); // Set how intense the feeling at the new control point will be float intensity = 1.0f; // Set the frequency of the control point, which can change the feeling of the sensation float frequency = 200.0f; // Define the control point AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; // Instruct the device to stop any existing actions and start producing this control point bool isOK = emitter.update(points); // The emitter will continue producing this point until instructed to stop // Wait until the program is ready to stop Console.ReadKey(); // Stop the emitter emitter.stop(); // Dispose/destroy the emitter emitter.Dispose(); emitter = null; }
// Update is called once per frame private void FixedUpdate() { UpdateIntensity(); // Get the current contact points from all the haptic receivers contactPoints.Clear(); for (var i = 0; i < _hapticReceivers.Length; i++) { if (_hapticReceivers[i].gameObject.activeInHierarchy) { var contactHits = _hapticReceivers[i].GetCurrentContactPoint(); if (contactHits != null) { contactPoints.AddRange(contactHits.Select(hit => hit.point + hit.normal * contactPointBackwardAdjust)); } } } if (contactPoints.Count <= 0) { _amEmitter.stop(); return; } // Choose which points to emit if there are too many var pointsToEmit = ChoosePointsToEmit(contactPoints); // Store a reference to these points so they can be rendered for debugging _debugPoints = pointsToEmit; // Create a list to hold all the control points we want to emit this frame var amControlPoints = new List <AmplitudeModulationControlPoint>(); // Construct control points for each of the points we want to emit foreach (var pointToEmit in pointsToEmit) { // The positions are in world space so convert them to device space var deviceSpacePosition = _coordinateSpaceConverter.WorldToDevicePosition(pointToEmit); // Construct a control point with the position and intensity of the point var amControlPoint = new AmplitudeModulationControlPoint(deviceSpacePosition, hapticStrength); amControlPoint.setFrequency(currentFrequency * (float)Units.hertz); amControlPoints.Add(amControlPoint); } // Give the list of control points to the emitter if (contactPoints.Count > 0) { _amEmitter.update(amControlPoints); } }
/// <summary> /// Starts the live ultrahaptics rendering /// Note: live ultrahaptics rendering of a point always happrns in AM and is never implemented in TPS /// </summary> public static void RenderLive() { Stop = false; emitter = new AmplitudeModulationEmitter(); Vector3 position = new Vector3((float)(0 * Ultrahaptics.Units.metres), (float)(0 * Ultrahaptics.Units.metres), (float)(0.20 * Ultrahaptics.Units.metres)); AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; emitter.update(points); }
public static void Render() { Stop = false; string file_name = Path.Combine(Environment.CurrentDirectory, "list.csv"); emitter = new AmplitudeModulationEmitter(); for (; ;) { using (TextFieldParser parser = new TextFieldParser(file_name)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { double x = 1000, y = 1000; //Processing row string[] fields = parser.ReadFields(); foreach (string field in fields) { //TODO: Process field if (x == 1000) { x = double.Parse(field); } else if (y == 1000) { y = double.Parse(field); } } Vector3 position = new Vector3((float)(x * Ultrahaptics.Units.metres), (float)(y * Ultrahaptics.Units.metres), (float)(0.20 * Ultrahaptics.Units.metres)); AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; emitter.update(points); //this condition will stop emitter from processing further if (Stop) { emitter.update(new List <AmplitudeModulationControlPoint> { }); emitter.Dispose(); emitter = null; Stop = false; return; } } } } }
// 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 }); }
public List <AmplitudeModulationControlPoint> GetPoints(float z) { AmplitudeModulationControlPoint point1 = new AmplitudeModulationControlPoint(x1, y1, z, i, f); AmplitudeModulationControlPoint point2 = new AmplitudeModulationControlPoint(2 * x1 / 3 + 1 * x2 / 3, 2 * y1 / 3 + 1 * y2 / 3, z, i, f); AmplitudeModulationControlPoint point3 = new AmplitudeModulationControlPoint(1 * x1 / 3 + 2 * x2 / 3, 1 * y1 / 3 + 2 * y2 / 3, z, i, f); AmplitudeModulationControlPoint point4 = new AmplitudeModulationControlPoint(x2, y2, z, i, f); var points = new List <AmplitudeModulationControlPoint> { point1, point2, point3, point4 }; return(points); }
public static void Main(string[] args) { // Width of the kit, refer to the User Guide of your device float width = 0.210f; // meters // affine transformation matrix placing the device half its width to the left in the global space Transform left_tr = new Transform(); left_tr.setOrigin(new Vector3(-width / 2, 0.0f, 0.0f)); // affine transformation matrix placing the device half its width to the right in the global space Transform right_tr = new Transform(); right_tr.setOrigin(new Vector3(width / 2, 0.0f, 0.0f)); // Create an emitter, which connects to the first connected device // Please make sure to use the correct identifiers for your devices AmplitudeModulationEmitter emitter = new AmplitudeModulationEmitter("USX:USX-00000000", left_tr); emitter.addDevice("USX:USX-00000001", right_tr); // Set the position of the new control point Vector3 position1 = new Vector3(-0.05f, 0.0f, 0.2f); Vector3 position2 = new Vector3(0.05f, 0.0f, 0.2f); // Set how intense the feeling at the new control point will be float intensity = 1.0f; // Set the frequency of the control point, which can change the feeling of the sensation float frequency = 200.0f; // Define the control point AmplitudeModulationControlPoint point1 = new AmplitudeModulationControlPoint(position1, intensity, frequency); AmplitudeModulationControlPoint point2 = new AmplitudeModulationControlPoint(position2, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point1, point2 }; // Instruct the device to stop any existing actions and start producing this control point bool isOK = emitter.update(points); // The emitter will continue producing this point until instructed to stop // Wait until the program is ready to stop Console.ReadKey(); // Stop the emitter emitter.stop(); // Dispose/destroy the emitter emitter.Dispose(); emitter = null; }
[Fact] public void AquireTarget() { Data_Generator dg = new Data_Generator(); Hand_Generator hg = new Hand_Generator(dg); Joints inp_joint = hg.newJoints(); float org_UH_INTENSITY = GBL.UH_INTENSITY; float org_UH_FREQUENCY = GBL.UH_FREQUENCY; float exp_UH_INTENSITY = dg.newFloat(100); float exp_UH_FREQUENCY = dg.newFloat(200); AmplitudeModulationControlPoint exp = new AmplitudeModulationControlPoint( inp_joint.palm.x, inp_joint.palm.z * -1, inp_joint.palm.y, exp_UH_INTENSITY, exp_UH_FREQUENCY ); Haptic h = new Haptic(new JointsHelper(new VectorHelper()), new AmplitudeModulationEmitter()); var act = h.AquireTarget(inp_joint); Assert.Equal(exp.getPosition().x, act.getPosition().x); Assert.Equal(exp.getPosition().y, act.getPosition().y); Assert.Equal(exp.getPosition().z, act.getPosition().z); }
public static void Main(string[] args) { // Create an emitter, which connects to the first connected device AmplitudeModulationEmitter emitter = new AmplitudeModulationEmitter(); // Create an aligment object which relates the tracking and device spaces Alignment alignment = emitter.getDeviceInfo().getDefaultAlignment(); // Create a Leap Contoller Controller controller = new Controller(); ButtonWidget button = new ButtonWidget(); // Set the position of the new control point Vector3 position = new Vector3(0.0f, 0.0f, 0.2f); // Set how intense the feeling at the new control point will be float intensity = 1.0f; // Set the frequency of the control point, which can change the feeling of the sensation float frequency = 200.0f; // Define the control point AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; // Wait for leap if (!controller.IsConnected) { Console.WriteLine("Waiting for Leap"); while (!controller.IsConnected) { System.Threading.Thread.Sleep(1000); Console.WriteLine("."); } Console.WriteLine("\n"); } controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP); if (controller.Config.SetFloat("Gesture.Swipe.MinDistance", 30) && controller.Config.SetFloat("Gesture.Swipe.MinDownVelocity", 30) && controller.Config.SetFloat("Gesture.Swipe.MinSeconds", 0.01f)) { controller.Config.Save(); } bool button_on = true; new Stopwatch(); for (;;) { Frame frame = controller.Frame(); HandList hands = frame.Hands; if (!hands.IsEmpty && button_on) { Hand hand = hands[0]; for (int i = 0; i < frame.Gestures().Count; i++) { Gesture gesture = frame.Gestures()[i]; if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) { button_on = false; emitter.stop(); break; } } position = new Vector3(hand.PalmPosition.x, hand.PalmPosition.y, hand.PalmPosition.z); Vector3 normal = new Vector3(-hand.PalmNormal.x, -hand.PalmNormal.y, -hand.PalmNormal.z); Vector3 direction = new Vector3(hand.Direction.x, hand.Direction.y, hand.Direction.z); Vector3 device_position = alignment.fromTrackingPositionToDevicePosition(position); Vector3 device_normal = alignment.fromTrackingDirectionToDeviceDirection(normal).normalize(); Vector3 device_direction = alignment.fromTrackingDirectionToDeviceDirection(direction).normalize(); Vector3 device_palm_x = device_direction.cross(device_normal).normalize(); device_position += (device_direction * MathF.Cos(button.angle) + device_palm_x * MathF.Sin(button.angle)) * button.radius; points[0].setPosition(device_position); // Instruct the device to stop any existing actions and start producing this control point emitter.update(points); // The emitter will continue producing this point until instructed to stop button.angle += 0.05f; button.angle = button.angle % (2.0f * PI); } else if (!hands.IsEmpty && !button_on) { emitter.stop(); for (int i = 0; i < frame.Gestures().Count; i++) { Gesture gesture = frame.Gestures()[i]; if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) { button_on = true; emitter.stop(); break; } } } else { emitter.stop(); } System.Threading.Thread.Sleep(10); } // Dispose/destroy the emitter emitter.Dispose(); emitter = null; controller.Dispose(); }