// Update is called once per frame void Update() { RUISSelectable target = (RUISSelectable)this.GetComponent(typeof(RUISSelectable)); GameObject wand1 = GameObject.Find("MouseWand"); RUISMouseWand mouseWand1Scripts = (RUISMouseWand)wand1.GetComponent(typeof(RUISMouseWand)); GameObject wand2 = GameObject.Find("MouseWand"); if (mouseWand1Scripts.SelectionButtonWasPressed()) //TODO mahdollisesti kaks nappia pohjassa { Vector3 controller1StartLoc = wand1.transform.position; controller2StartLoc = wand2.transform.position; controller2StartLoc = controller2StartLoc + new Vector3(1, 1, 1); startDistance = controller1StartLoc - controller2StartLoc; initialScaling = this.transform.localScale; } else if (target.isSelected && mouseWand1Scripts.SelectionButtonIsDown()) //TODO mahdollisesti kaks nappia pohjassa { Vector3 endDistance = wand1.transform.position - controller2StartLoc; scaleUpdate(startDistance, endDistance); } else if (target.isSelected && mouseWand1Scripts.SelectionButtonWasReleased()) //TODO mahdollisesti kaks nappia pohjassa { //Vector3 endDistance = wand1.transform.position - wand2.transform.position; Vector3 endDistance = wand1.transform.position - controller2StartLoc; scaleUpdate(startDistance, endDistance); } }
void Update() { if (!wandSelector.Selection && selection) { selection.clampToCertainDistance = wasClampedToCertainDistance; selection.distanceToClampTo = distanceClampedTo; } if (!wandSelector.Selection || wandSelector.positionSelectionGrabType != RUISWandSelector.SelectionGrabType.AlongSelectionRay) { selection = null; return; } if (!selection) { selection = wandSelector.Selection; wasClampedToCertainDistance = selection.clampToCertainDistance; selection.clampToCertainDistance = true; distanceClampedTo = selection.distanceToClampTo; currentDistance = 1; } float currentDistanceChange = ((1 - psMoveController.triggerValue) - currentDistance) * Time.deltaTime * reelSpeed; currentDistance += currentDistanceChange; selection.distanceToClampTo = currentDistance * selection.DistanceFromSelectionRayOrigin; }
void Update() { if (!wandSelector.Selection && selection) { selection.clampToCertainDistance = wasClampedToCertainDistance; selection.distanceToClampTo = distanceClampedTo; } if (!wandSelector.Selection || wandSelector.positionSelectionGrabType != RUISWandSelector.SelectionGrabType.AlongSelectionRay) { selection = null; return; } if(!selection){ selection = wandSelector.Selection; wasClampedToCertainDistance = selection.clampToCertainDistance; selection.clampToCertainDistance = true; distanceClampedTo = selection.distanceToClampTo; currentDistance = 1; } float currentDistanceChange = ((1 - psMoveController.triggerValue) - currentDistance) * Time.deltaTime * reelSpeed; currentDistance += currentDistanceChange; selection.distanceToClampTo = currentDistance * selection.DistanceFromSelectionRayOrigin; }
private void EndSelection() { selection.OnSelectionEnd(); RevertLayersRecursively(selection.gameObject); originalSelectedGameObjectLayer = -1; selection = null; }
public void Update() { if (!isTracking && skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking) { PlayerFound(); } else if (isTracking && !skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking) { PlayerLost(); } else if (!skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking) { return; } if (!highlightStartObject && wandSelector.HighlightedObject) { highlightStartObject = wandSelector.HighlightedObject; gestureRecognizer.EnableGesture(); } else if (!wandSelector.HighlightedObject) { highlightStartObject = null; if (!wandSelector.Selection) { gestureRecognizer.DisableGesture(); } } visualizerThreshold = Mathf.Clamp01(visualizerThreshold); RUISSkeletonManager.JointData startData = skeletonManager.GetJointData(wandStart, playerId, bodyTrackingDeviceID); RUISSkeletonManager.JointData endData = skeletonManager.GetJointData(wandEnd, playerId, bodyTrackingDeviceID); if (endData.positionConfidence >= 0.5f) { // TUUKKA: Original code // transform.localPosition = endData.position; // // if (startData != null && startData.positionConfidence >= 0.5f) // { // transform.localRotation = Quaternion.LookRotation(endData.position - startData.position); // } // else if (endData.rotationConfidence >= 0.5f) // { // transform.localRotation = endData.rotation; // } // First calculate local rotation if (startData != null && startData.positionConfidence >= 0.5f) { tempVector = endData.position - startData.position; if (Vector3.Angle(startData.rotation * Vector3.up, tempVector) > 5) { tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.up); } else { tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.right); } filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime); // HACK with kinect2 filtering is done in SkeletonManager } // else if (endData.rotationConfidence >= 0.5f) // { // tempRotation = endData.rotation; // filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime); // } if (rigidbody) { // TUUKKA: if (transform.parent) { // If the wand has a parent, we need to apply its transformation first rigidbody.MovePosition(transform.parent.TransformPoint(endData.position)); rigidbody.MoveRotation(transform.parent.rotation * filteredRotation); } else { rigidbody.MovePosition(endData.position); rigidbody.MoveRotation(filteredRotation); } } else { // If there is no rigidBody, then just change localPosition & localRotation transform.localPosition = endData.position; transform.localRotation = filteredRotation; } } }
public void Update() { GameObject selectionGameObject = CheckForSelection(); if (!selection) { if (selectionGameObject) { RUISSelectable selectableObject = selectionGameObject.GetComponent <RUISSelectable>(); //also search in parents if we didn't find RUISSelectable on this gameobject to allow for multi-piece collider hierarchies while (!selectableObject && selectionGameObject.transform.parent != null) { selectionGameObject = selectionGameObject.transform.parent.gameObject; selectableObject = selectionGameObject.GetComponent <RUISSelectable>(); } if (selectableObject && !selectableObject.isSelected) { if (selectableObject != highlightedObject) { if (highlightedObject != null) { highlightedObject.OnSelectionHighlightEnd(); } selectableObject.OnSelectionHighlight(); highlightedObject = selectableObject; } if ((!grabWhileButtonDown && wand.SelectionButtonWasPressed()) || (grabWhileButtonDown && wand.SelectionButtonIsDown())) { selection = selectableObject; if (highlightedObject != null) { highlightedObject.OnSelectionHighlightEnd(); highlightedObject = null; } BeginSelection(); selectionButtonReleasedAfterSelection = false; } } } if (!selectionGameObject || !selectionGameObject.GetComponent <RUISSelectable>()) { if (highlightedObject != null) { highlightedObject.OnSelectionHighlightEnd(); highlightedObject = null; } } } else if (wand.SelectionButtonWasReleased()) { if (!toggleSelection || (toggleSelection && selectionButtonReleasedAfterSelection) || !wand.IsSelectionButtonStandard()) { EndSelection(); } else { selectionButtonReleasedAfterSelection = true; } } }
public void Update() { if (!isTracking && skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking) { PlayerFound(); } else if (isTracking && !skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking) { PlayerLost(); } else if (!skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking) { return; } if (!highlightStartObject && wandSelector.HighlightedObject) { highlightStartObject = wandSelector.HighlightedObject; gestureRecognizer.EnableGesture(); } else if (!wandSelector.HighlightedObject) { highlightStartObject = null; if (!wandSelector.Selection) { gestureRecognizer.DisableGesture(); } } visualizerThreshold = Mathf.Clamp01(visualizerThreshold); RUISSkeletonManager.JointData startData = skeletonManager.GetJointData(wandStart, playerId, bodyTrackingDeviceID); RUISSkeletonManager.JointData endData = skeletonManager.GetJointData(wandEnd, playerId, bodyTrackingDeviceID); if (endData.positionConfidence >= 0.5f) { // TUUKKA: Original code // transform.localPosition = endData.position; // // if (startData != null && startData.positionConfidence >= 0.5f) // { // transform.localRotation = Quaternion.LookRotation(endData.position - startData.position); // } // else if (endData.rotationConfidence >= 0.5f) // { // transform.localRotation = endData.rotation; // } // First calculate local rotation if ( startData != null && startData.positionConfidence >= 0.5f ) { tempVector = endData.position - startData.position; if(Vector3.Angle(startData.rotation * Vector3.up, tempVector) > 5) tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.up); else tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.right); filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime); // HACK with kinect2 filtering is done in SkeletonManager } // else if (endData.rotationConfidence >= 0.5f) // { // tempRotation = endData.rotation; // filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime); // } if (GetComponent<Rigidbody>()) { // TUUKKA: if (transform.parent) { // If the wand has a parent, we need to apply its transformation first GetComponent<Rigidbody>().MovePosition(transform.parent.TransformPoint(endData.position)); GetComponent<Rigidbody>().MoveRotation(transform.parent.rotation * filteredRotation); } else { GetComponent<Rigidbody>().MovePosition(endData.position); GetComponent<Rigidbody>().MoveRotation(filteredRotation); } } else { // If there is no rigidBody, then just change localPosition & localRotation transform.localPosition = endData.position; transform.localRotation = filteredRotation; } } }
// Use this for initialization void Start() { selectable = GetComponent<RUISSelectable>(); audio = GetComponent<AudioSource>(); }
public void Update() { if (!isTracking && skeletonManager.skeletons[playerId].isTracking) { PlayerFound(); } else if (isTracking && !skeletonManager.skeletons[playerId].isTracking) { PlayerLost(); } else if (!skeletonManager.skeletons[playerId].isTracking) { return; } if (!highlightStartObject && wandSelector.HighlightedObject) { highlightStartObject = wandSelector.HighlightedObject; gestureRecognizer.EnableGesture(); } else if (!wandSelector.HighlightedObject) { highlightStartObject = null; if (!wandSelector.Selection) { gestureRecognizer.DisableGesture(); } } visualizerThreshold = Mathf.Clamp01(visualizerThreshold); RUISSkeletonManager.JointData startData = skeletonManager.GetJointData(wandStart, playerId); RUISSkeletonManager.JointData endData = skeletonManager.GetJointData(wandEnd, playerId); if (endData.positionConfidence >= 0.5f) { // TUUKKA: Original code // transform.localPosition = endData.position; // // if (startData != null && startData.positionConfidence >= 0.5f) // { // transform.localRotation = Quaternion.LookRotation(endData.position - startData.position); // } // else if (endData.rotationConfidence >= 0.5f) // { // transform.localRotation = endData.rotation; // } // First calculate local rotation if (startData != null && startData.positionConfidence >= 0.5f) { tempRotation = Quaternion.LookRotation(endData.position - startData.position); } else if (endData.rotationConfidence >= 0.5f) { tempRotation = endData.rotation; } if (rigidbody) { // TUUKKA: if (transform.parent) { // If the wand has a parent, we need to apply its transformation first rigidbody.MovePosition(transform.parent.TransformPoint(endData.position)); rigidbody.MoveRotation(transform.parent.rotation * tempRotation); } else { rigidbody.MovePosition(endData.position); rigidbody.MoveRotation(tempRotation); } } else { // If there is no rigidBody, then just change localPosition & localRotation transform.localPosition = endData.position; transform.localRotation = tempRotation; } } }
public void Update() { GameObject selectionGameObject = CheckForSelection(); if (!selection) { if (selectionGameObject) { RUISSelectable selectableObject = selectionGameObject.GetComponent<RUISSelectable>(); //also search in parents if we didn't find RUISSelectable on this gameobject to allow for multi-piece collider hierarchies while (!selectableObject && selectionGameObject.transform.parent != null) { selectionGameObject = selectionGameObject.transform.parent.gameObject; selectableObject = selectionGameObject.GetComponent<RUISSelectable>(); } if (selectableObject && !selectableObject.isSelected) { if (selectableObject != highlightedObject) { if (highlightedObject != null) highlightedObject.OnSelectionHighlightEnd(); selectableObject.OnSelectionHighlight(); highlightedObject = selectableObject; } if ((!grabWhileButtonDown && wand.SelectionButtonWasPressed()) || (grabWhileButtonDown && wand.SelectionButtonIsDown())) { selection = selectableObject; if (highlightedObject != null) { highlightedObject.OnSelectionHighlightEnd(); highlightedObject = null; } BeginSelection(); selectionButtonReleasedAfterSelection = false; } } } if (!selectionGameObject || !selectionGameObject.GetComponent<RUISSelectable>()) { if (highlightedObject != null) { highlightedObject.OnSelectionHighlightEnd(); highlightedObject = null; } } } else if (wand.SelectionButtonWasReleased()){ if (!toggleSelection || (toggleSelection && selectionButtonReleasedAfterSelection) || !wand.IsSelectionButtonStandard()) { EndSelection(); } else { selectionButtonReleasedAfterSelection = true; } } }
// Use this for initialization void Start() { selectable = GetComponent <RUISSelectable>(); audio = GetComponent <AudioSource>(); }