void CalibratePointer() { HapticPointer hp = GameObject.Find(selectedPointer).GetComponent <HapticPointer>(); hp.Calibrate(); Invoke("CatchObject", 0.1f); }
void UpdateCameraPan() { Vector3 pos = transform.position; pos.x = radius * Mathf.Cos(angle); pos.z = radius * Mathf.Sin(angle); transform.position = pos; transform.rotation = Quaternion.LookRotation(Vector3.zero - pos); Quaternion rot = Quaternion.Inverse(Quaternion.AngleAxis((angle - Mathf.PI / 2) * Mathf.Rad2Deg, Vector3.up)); HapticPointer hp = GetHapticPointer("HapticPointerL"); if (hp) { hp.PositionOffset = rot * pointerOffsetL; hp.RotationOffset = rot; } hp = GetHapticPointer("HapticPointerR"); if (hp) { hp.PositionOffset = rot * pointerOffsetR; hp.RotationOffset = rot; } }
void ClearTransform() { Vector3 pos; pos.x = 0; pos.y = 0.7f; pos.z = -0.7f; transform.position = pos; transform.rotation = Quaternion.LookRotation(Vector3.zero - pos); angle = Mathf.PI / 2; height = 0.7f; HapticPointer hp = GetHapticPointer("HapticPointerL"); if (hp) { hp.ReleaseObject(); hp.PositionOffset = pointerOffsetL; hp.RotationOffset = Quaternion.identity; } hp = GetHapticPointer("HapticPointerR"); if (hp) { hp.ReleaseObject(); hp.PositionOffset = pointerOffsetR; hp.RotationOffset = Quaternion.identity; } }
void CatchObject() { HapticPointer hp = GameObject.Find(selectedPointer).GetComponent <HapticPointer>(); hp.HoldObject(); hp.ReleaseObject(); hp.HoldObject(); }
void Awake() { _pointers = GameObject.FindObjectsOfType(typeof(HapticPointer)) as HapticPointer[]; SortedList sl = new SortedList(); for (int i = 0; i < _pointers.Length; ++i) { sl[_pointers[i].name] = _pointers[i]; } if (sl.Count == _pointers.Length) { HapticPointer[] pointers = new HapticPointer[_pointers.Length]; for (int i = 0; i < _pointers.Length; ++i) { pointers[i] = sl.GetByIndex(i) as HapticPointer; } _pointers = pointers; } _parameters = new PointerParameter[_pointers.Length]; for (int i = 0; i < _parameters.Length; ++i) { _parameters[i] = new PointerParameter(_pointers[i]); _parameters[i].record(); _parameters[i].deserialize(); } _settingTexture = (Texture)Resources.Load("setting", typeof(Texture2D)); _closeTexture = (Texture)Resources.Load("close", typeof(Texture2D)); GUIStyleState state = new GUIStyleState(); state.textColor = Color.white; _captionStyle = new GUIStyle(); _captionStyle.fontSize = 20; _captionStyle.normal = state; state = new GUIStyleState(); state.textColor = Color.yellow; _deviceNameStyle = new GUIStyle(); _deviceNameStyle.fontSize = 20; _deviceNameStyle.alignment = TextAnchor.MiddleLeft; _deviceNameStyle.normal = state; }
void OnGUI() { if (!showInformation) { return; } GameObject obj; if (selected) { obj = GameObject.Find("HapticPointerL"); } else { obj = GameObject.Find("HapticPointerR"); } HapticPointer hp = null; int[] encoderCount = new int[8]; if (obj) { hp = obj.GetComponent <HapticPointer>(); } if (!obj || !hp) { //GUILayout.Label(selectedPointer.ToString() + " is null", style); return; } GUILayout.Label(hp.ToString(), style); GUILayout.Label("Device serial number: " + hp.SerialNumber, style); GUILayout.Label("Device Delta Time: " + (hp.DeviceDeltaTime * 1000).ToString("f3") + "[ms]", style); GUILayout.Label("Device Type: " + hp.DeviceType, style); GUILayout.Label("Haptics: " + hp.Haptics + ", Gravity: " + hp.Gravity + ", Cascade Control: " + hp.CascadeControl, style); if (!DebugMode) { return; } GUILayout.Label("GPIO: " + hp.GpioValue, style); GUILayout.Label("", style); hp.GetEncoderCount(ref encoderCount); GUILayout.Label("encder counts", style); for (int i = 0; i < 8; ++i) { GUILayout.Label("motor " + (i + 1) + ": " + encoderCount[i], style); } GUILayout.Label("", style); GUILayout.Label("PointerPosition:" + hp.gameObject.transform.position, style); GUILayout.Label("", style); GUILayout.Label("", style); GUILayout.Label("", style); if (hpL.HoldingObject) { GUILayout.Label("Haptic Pointer L Holding", style); } if (hpR.HoldingObject) { GUILayout.Label("Haptic Pointer R Holding", style); } //if (hp.HoldingObject) //{ // HoldState hs = hp.HoldingObject.GetComponent<HoldState>(); // GUILayout.Label(hp.HoldingObject.ToString(), style); // GUILayout.Label(hs.ToString(), style); // GUILayout.Label("Collision state: " + hs.Collision, style); // GUILayout.Label("mass: " + hp.HoldingObject.mass, style); // GUILayout.Label("center of mass: " + hp.HoldingObject.centerOfMass.ToString("f4"), style); // GUILayout.Label("inertiaTensor: " + hp.HoldingObject.inertiaTensor.ToString("f4"), style); // GUILayout.Label("inertiaTensorRotation: " + hp.HoldingObject.inertiaTensorRotation.ToString("f4"), style); // GUILayout.Label("", style); //} }
void OnGUI() { if (!showInformation || _pointers.Length == 0 || (_pointerSetting != null && _pointerSetting.isOpened)) { return; } int left = PointerSetting.SettingButtonLeft; int top = Margin + (_pointerSetting == null ? PointerSetting.SettingButtonTop : PointerSetting.SettingButtonTop + PointerSetting.SettingButtonHeight); int width = Screen.width - left; int height = Screen.height - top; GUILayout.BeginArea(new Rect(left, top, width, height)); GUILayout.Label("Key configuration: ", _style); GUILayout.Label(" [ i ] - show/hide this information", _style); GUILayout.Label(" [ ] - hold/release object", _style); GUILayout.Label(" [v ] - clutch on/off", _style); GUILayout.Label(" [c ] - execute calibration", _style); GUILayout.Label(" [m] - select haptic pointer", _style); GUILayout.Space(20); HapticPointer hp = _pointers[_currentPointer]; GUILayout.Label("Selected Haptic Pointer: " + hp.name, _style); if (hp.Activated) { GUILayout.Label(" Device serial number: " + hp.SerialNumber, _style); GUILayout.Label(" Device Delta Time: " + (hp.DeviceDeltaTime * 1000).ToString("f3") + "[ms]", _style); GUILayout.Label(" Haptics: " + hp.Haptics + ", Gravity: " + hp.Gravity + ", Cascade Control: " + hp.CascadeControl, _style); if (hp.DebugMode) { GUILayout.Label(" GPIO: " + hp.GpioValue, _style); int[] encoderCount = new int[8]; hp.GetEncoderCount(ref encoderCount); GUILayout.Label(" Encoder counts", _style); for (int i = 0; i < 8; ++i) { GUILayout.Label(" Motor " + (i + 1) + ": " + encoderCount[i], _style); } if (hp.HoldingObject) { GUILayout.Space(10); HoldState hs = hp.HoldingObject.GetComponent <HoldState>(); GUILayout.Label(hp.HoldingObject.ToString(), _style); GUILayout.Label(hs.ToString(), _style); GUILayout.Label(" Collision state: " + hs.Collision, _style); GUILayout.Label(" Mass: " + hp.HoldingObject.mass, _style); GUILayout.Label(" Center of mass: " + hp.HoldingObject.centerOfMass.ToString("f4"), _style); GUILayout.Label(" InertiaTensor: " + hp.HoldingObject.inertiaTensor.ToString("f4"), _style); GUILayout.Label(" InertiaTensorRotation: " + hp.HoldingObject.inertiaTensorRotation.ToString("f4"), _style); } } } else { GUILayout.Label(" ... not activated", _style2); } GUILayout.Space(20); GUILayout.Label("Unity delta time: " + (Time.deltaTime * 1000).ToString("f3") + "[ms], Fixed delta time: " + (Time.fixedDeltaTime * 1000).ToString("f3") + "[ms]", _style); GUILayout.EndArea(); }
void Update() { if (Input.GetKeyDown(KeyCode.I)) { showInformation = !showInformation; } else if (Input.GetKeyDown(KeyCode.M)) { _currentPointer++; if (_currentPointer >= _pointers.Length) { _currentPointer = 0; } _currentPointerName = _pointers.Length > 0 ? _pointers[_currentPointer].name : ""; } if (_pointers.Length == 0) { return; } HapticPointer hp = _pointers[_currentPointer]; if (hp.ToggleHold) { if (Input.GetKeyDown(KeyCode.Space)) { if (!hp.ReleaseObject()) { hp.HoldObject(); } } } else { if (Input.GetKeyDown(KeyCode.Space)) { hp.HoldObject(); } if (Input.GetKeyUp(KeyCode.Space)) { hp.ReleaseObject(); } } if (hp.ToggleClutch) { if (Input.GetKeyDown(KeyCode.V)) { if (!hp.ReleaseClutch()) { hp.EngageClutch(); } } } else { if (Input.GetKeyDown(KeyCode.V)) { hp.EngageClutch(); } if (Input.GetKeyUp(KeyCode.V)) { hp.ReleaseClutch(); } } if (Input.GetKeyDown(KeyCode.C)) { hp.Calibrate(); } }
public PointerParameter(HapticPointer hapticPointer) { _hapticPointer = hapticPointer; }
void OnGUI() { if (!showInformation) { return; } //GUILayout.Label("Information (i), " + "Restart (r), " + "Quit (q)", style); //GUILayout.Label("Hold (space), " + "Calibration (c), " + "Clutch (v)", style); //GUILayout.Label("Select Haptic Pointer (m)", style); //GUILayout.Label("Unity deltaTime: " + (Time.deltaTime * 1000).ToString("f3") + "[ms], fixedDeltaTime: " // + (Time.fixedDeltaTime * 1000).ToString("f3") + "[ms]", style); //GUILayout.Label("", style); GameObject obj = GameObject.Find("HapticPointer"); HapticPointer hp = null; int[] encoderCount = new int[8]; if (obj) { hp = obj.GetComponent <HapticPointer>(); } if (!obj || !hp) { //GUILayout.Label(selectedPointer.ToString() + " is null", style); return; } GUILayout.Label(hp.ToString(), style); GUILayout.Label("Device serial number: " + hp.SerialNumber, style); GUILayout.Label("Device Delta Time: " + (hp.DeviceDeltaTime * 1000).ToString("f3") + "[ms]", style); GUILayout.Label("Device Type: " + hp.DeviceType, style); GUILayout.Label("Haptics: " + hp.Haptics + ", Gravity: " + hp.Gravity + ", Cascade Control: " + hp.CascadeControl, style); if (!DebugMode) { return; } GUILayout.Label("GPIO: " + hp.GpioValue, style); GUILayout.Label("", style); hp.GetEncoderCount(ref encoderCount); GUILayout.Label("encder counts", style); for (int i = 0; i < 8; ++i) { GUILayout.Label("motor " + (i + 1) + ": " + encoderCount[i], style); } GUILayout.Label("", style); if (hp.HoldingObject) { HoldState hs = hp.HoldingObject.GetComponent <HoldState>(); GUILayout.Label(hp.HoldingObject.ToString(), style); GUILayout.Label(hs.ToString(), style); GUILayout.Label("Collision state: " + hs.Collision, style); GUILayout.Label("mass: " + hp.HoldingObject.mass, style); GUILayout.Label("center of mass: " + hp.HoldingObject.centerOfMass.ToString("f4"), style); GUILayout.Label("inertiaTensor: " + hp.HoldingObject.inertiaTensor.ToString("f4"), style); GUILayout.Label("inertiaTensorRotation: " + hp.HoldingObject.inertiaTensorRotation.ToString("f4"), style); GUILayout.Label("", style); } }