private void SaveLogIfLogging() { if (HapticNativePlugin.is_logging() != HapticNativePlugin.SUCCESS) { return; } // Create the file name string LogName; do { LogName = GenLogName(); LogNumber += 1; }while (File.Exists(LogName)); if (HapticNativePlugin.StopLoggingAndSave(LogName)) { if (Verbosity > 0) { Debug.Log(LogName); } } else { // TODO: get error message and print Debug.LogError("Could not save log!"); } }
void UpdateProperties() { if (HapticManager.isHapticAvail) { HapticNativePlugin.setObjectProperties(objectId, stiffness, friction_static, friction_dynamic, 0.0f, double.PositiveInfinity); } }
public static int SetObjectScale(int ObjectId, Vector3 scale) { double[] vect = { scale.x, scale.y, scale.z }; Debug.LogWarning("Changing object scale is currently not working"); return(HapticNativePlugin.set_object_scale(ObjectId, vect)); }
// Update is called once per frame private void Update() { //Debug.Log(UnityHaptics.GetToolVelocity()); LoopNumber += 1; if (LoopNumber % 100 == 0) { LoopFrequencyHz = HapticNativePlugin.get_loop_frequency(); if (Verbosity > 1) { Debug.Log(LoopFrequencyHz); } } if (EnableTick == Tick.Update) { HapticNativePlugin.tick(); } if (!Started || !Running) { int res = HapticNativePlugin.start(); UnityHaptics.LogMessage(res, true); Started = res == HapticNativePlugin.SUCCESS; Running = Started; UpdateToolPositionAndRotation(); } }
public void OnValidate() { if (!Application.isPlaying || !HapticNativePlugin.IsRunning()) { return; } for (int i = 0; i < Instances.Count; ++i) { Instances[i].UpdateMaterial(); } }
public static int SetToolPosition(Vector3 position) { double [] pos = new double [3] { position.x, position.y, position.z }; return(HapticNativePlugin.SetToolPosition(pos)); }
private void OnDestroy() { if (isHapticAvail) { HapticNativePlugin.stopHaptics(); } }
// Use this for initialization void Start() { string options = GameObject.FindWithTag("God").GetComponent <ReaderWriter>().ReadString("Options.conf"); XmlDocument doc = new XmlDocument(); doc.LoadXml(options); //AsignarValores(doc); damping = 0; var devicePosition = GameObject.Find("Haptic Origin"); Mesh mesh = this.GetComponent <MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector3[] normals = mesh.normals; int[,] triangles = new int[(mesh.triangles.Length / 3), 3]; for (int i = 0; i < mesh.triangles.Length / 3; i++) { triangles[i, 0] = mesh.triangles[3 * i]; triangles[i, 1] = mesh.triangles[3 * i + 1]; triangles[i, 2] = mesh.triangles[3 * i + 2]; } //objectId = HapticNativePlugin.AddObject(this.transform.position - devicePosition.transform.position, this.transform.localScale, this.transform.localRotation.eulerAngles, vertices, normals, mesh.vertices.Length, triangles, mesh.triangles.Length / 3); //objectId = HapticNativePlugin.AddObject(this.transform.localPosition - devicePosition.transform.localPosition, this.transform.localScale, this.transform.localRotation.eulerAngles, vertices, normals, mesh.vertices.Length, triangles, mesh.triangles.Length / 3); //objectId = HapticNativePlugin.AddModificableObject(this.transform.localPosition - devicePosition.transform.localPosition, this.transform.localScale, this.transform.localRotation.eulerAngles, vertices, normals, mesh.vertices.Length, triangles, mesh.triangles.Length / 3, stiffness, staticFriction, dynamicFriction, damping, viscosity); objectId = HapticNativePlugin.AddSimpleObject(this.transform.localPosition - devicePosition.transform.localPosition, this.transform.localScale, this.transform.localRotation.eulerAngles, vertices, normals, mesh.vertices.Length, triangles, mesh.triangles.Length / 3, stiffness / 10, staticFriction / 10, dynamicFriction / 10); }
int SetObjectPosition(int ObjectId, Vector3 position) { double[] pos = new double[] { position.x, position.y, position.z }; return(HapticNativePlugin.set_object_position(ObjectId, pos)); }
public void ScanDevices() { int devices = HapticNativePlugin.count_devices(); // Get all devices names and print them here if (devices < 0) { Debug.LogError(HapticNativePlugin.GetLastErrorMsg()); return; } else if (devices == 0) { Debug.LogError("No devices found!"); return; } else if (devices == 1) { Debug.LogWarning("Only one device found (Probably no real devices attached!)"); } for (int device = -1; device < devices - 1; ++device) { Debug.Log("Found device #" + device + " (" + HapticNativePlugin.GetDeviceName(device) + ")"); CheckCompatibility(); } }
// Use this for initialization void Start() { if (!HapticManager.isHapticAvail) { gameObject.SetActive(false); return; } Vector3 totalScale = this.transform.localScale; // get global scale by looping through parenting system Transform nextParent = transform.parent; while (nextParent != null) { totalScale.Scale(nextParent.localScale); nextParent = nextParent.parent; } objectId = HapticNativePlugin.AddBoxObject( this.transform.position - HapticManager.hapticOrigin.position, totalScale, this.transform.rotation.eulerAngles ); }
/// <summary> /// This function takes as its only parameter (Hook) another function, and add it as an hook on each haptic loop. /// The 'Hook' parameter must take exactly 2 arguments, the actual position and the actual velocity, /// both as UNITY Vector3, and must return the force as a Vector3. /// public float GravityForceIntensity = 1.5f; /// A simple example: public Vector3 MyGravity(Vector3 pos, Vector3 vel) { return new Vector3(0.0f, 0.0f, -GravityForceIntensity); } /// /// You can change GravityForceIntensity and the rendered force will automatically update :) /// </summary> /// <param name="Hook"></param> public static void SetHook(System.Func <Vector3, Vector3, Vector3> Hook) { System.Action <System.IntPtr, System.IntPtr, System.IntPtr> real_hook = (p, v, f) => { // Prepare data double[] ManagedPosition = new double[3]; Marshal.Copy(p, ManagedPosition, 0, 3); double[] ManagedVelocity = new double[3]; Marshal.Copy(v, ManagedVelocity, 0, 3); var pos = new Vector3((float)ManagedPosition[0], (float)ManagedPosition[1], (float)ManagedPosition[2]); var vel = new Vector3((float)ManagedVelocity[0], (float)ManagedVelocity[1], (float)ManagedVelocity[2]); // Actual invocation Vector3 force = Hook(pos, vel); // Store output double[] o = new double[3]; o[1] = force.x; o[2] = force.y; o[0] = -force.z; Marshal.Copy(o, 0, f, o.Length); }; HapticNativePlugin.SetHook(real_hook); }
public void UpdateConstraint() { double currentGain = gain; Vector3 pivotPos = transform.localPosition; //position - origin.position; if (constraintEnabled) { HapticNativePlugin.SetHapticEntryPoint(pivotPos, transform.forward); } else { currentGain = 0.0; } HapticNativePlugin.SetNeedleAxialPID(pivotPos, transform.forward, maxForce, kp, ki, kd, currentGain); //Set rotation! if (constraintEnabled) { Vector3 constraintToSlaveVec = (constraintSlave.position) - transform.position; // point target postion ahead to avoid errors trying to get direction of a zero vector constraintToSlaveVec = constraintToSlaveVec + transform.forward * orientationWeight; constraintSlave.rotation = Quaternion.LookRotation(constraintToSlaveVec); } else { constraintSlave.localRotation = transform.localRotation; } }
void Update() { if (!HapticManager.isHapticAvail) { gameObject.SetActive(false); return; } if (HapticNativePlugin.isButtonPressed((int)FalconButton.LEFT)) { transform.Rotate(Vector3.up, manualControlRotationSpeed * Time.deltaTime); } if (HapticNativePlugin.isButtonPressed((int)FalconButton.RIGHT)) { transform.Rotate(Vector3.up, -manualControlRotationSpeed * Time.deltaTime); } if (HapticNativePlugin.isButtonPressed((int)FalconButton.FRONT)) { transform.Rotate(Vector3.right, manualControlRotationSpeed * Time.deltaTime); } if (HapticNativePlugin.isButtonPressed((int)FalconButton.BACK)) { transform.Rotate(Vector3.right, -manualControlRotationSpeed * Time.deltaTime); } UpdateConstraint(); }
private void Update() { if (isHapticAvail) { this.transform.localPosition = HapticNativePlugin.GetProxyPosition(); } }
private void Start() { if (isHapticAvail) { HapticNativePlugin.startHaptics(); } }
/// <summary> /// Enable object haptic rendering /// </summary> public void Enable() { HapticNativePlugin.enable_object(ObjectId); if (Verbosity > 2) { Debug.Log("Enabling object: " + name); } }
private void UpdateHapticRotation() { if (previousRotation != this.transform.rotation.eulerAngles) { HapticNativePlugin.SetHapticRotation(this.transform.rotation.eulerAngles); } previousPosition = this.transform.rotation.eulerAngles; }
// Update is called once per frame void Update() { if (HapticManager.isHapticAvail) { float dist = Vector3.Distance(HapticNativePlugin.GetDevicePosition(), HapticNativePlugin.GetProxyPosition()); float interpVal = Mathf.InverseLerp(maxDist, 0.0f, dist); constraint.orientationWeight = Mathf.Clamp(interpVal, minVal, maxVal); } }
// Use this for initialization private void Awake() { if (!useHaptic) { isHapticAvail = false; } isHapticAvail = HapticNativePlugin.prepareHaptics(0.3d); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Salgo"); } HapticNativePlugin.stopHaptics(); //Application.Quit(); }
public static void SetUnityWorldCoordinates() { int res = HapticNativePlugin.set_world_mirror(2, 3, -1); LogMessage(res, true); // Adjust world for unity. This is required, because it calls the wrapper // which is adjusting this ones to tens, the right scale for unity // SetWorldScale(new Vector3(1.0f, 1.0f, 1.0f)); // FIXME: re enable }
private void Start() { if (isHapticAvail) { HapticNativePlugin.startHaptics(); HapticNativePlugin.moveTo(0.03, 0.0, 0.0, false); } //0,0,7 coordenadas de inicio }
public static int SetTexture(int ObjectId, Texture2D texture, bool reversed) { float[] pixels = texture.GetPixels().Select (t => reversed ? 1 - t.grayscale : t.grayscale).ToArray(); return(HapticNativePlugin.SetObjectTexture (ObjectId, (uint)texture.width, (uint)texture.height, pixels, false)); }
public void SetEnabled(bool enabled) { // gameObject.SetActive(enabled); if (enabled) { HapticNativePlugin.resetAxialConstraintPID(); } constraintEnabled = enabled; }
// Use this for initialization void Start() { CreateObject(); AddToWorld(); if (positionInterpolation) { HapticNativePlugin.enable_position_interpolation(ObjectId); HapticNativePlugin.set_interpolation_period(ObjectId, InterpolationPeriod, 1.0); } SetObjectProperties(); }
// Update is called once per frame void Update() { HapticNativePlugin.setNeedlePID(kp, ki, kd, gain); Vector3 dir = transform.forward; //transform.TransformDirection(Vector3.forward); float len = needleLength; // + castAheadLength; Ray newRay = new Ray(transform.position - dir * needleLength, dir); RaycastLayers(newRay, len); }
public static void SetWorldScale(Vector3 s) { // Unity's workspace is by default 10 times bigger if ((s.x != s.y) || (s.y != s.z)) { Debug.LogWarning("The scale you are setting is different along axis. " + "This is not supported. Using X only"); } HapticNativePlugin.set_world_scale(s.x * 10.0, s.y * 10.0, s.z * 10.0); }
void FixedUpdate() { if (!Running) { return; } UpdateToolPositionAndRotation(); if (EnableTick == Tick.FixedUpdate) { HapticNativePlugin.tick(); } }
private void UpdateHapticPosition() { if (chalkRef == null) { return; } if (previousPosition != chalkRef.position) { HapticNativePlugin.SetHapticPosition((chalkRef.position - originalPosition) / 0.1f); } previousPosition = chalkRef.position; }