public void RotateAndScale(Vector3 origin, float amountRot, float amountScale) { #region scale constraints if (GlobalVar.inverseHologramScale > GlobalVar.worldRadius * GlobalVar.maxZoomCutoff && amountScale > 1.0f) { amountScale = 1.0f; } else if (GlobalVar.inverseHologramScale < GlobalVar.worldRadius * GlobalVar.minZoomCutoff && amountScale < 1.0f) { amountScale = 1.0f; } #endregion Vector3 scaleVec = new Vector3(amountScale, amountScale, amountScale); Helperfunctions.scaleFromPivot(transformCandidate.transform, origin, scaleVec); transformCandidate.transform.RotateAround(origin, Vector3.up, amountRot); #region Update due to scale change GlobalVar.inverseHologramScale = transformCandidate.transform.localScale.x; mainLight.range = originalLightRange * GlobalVar.inverseHologramScale; effectiveDrag = drag * 1.0f / GlobalVar.inverseHologramScale; effectiveTranslationSpeedCutoff = translationSpeedCutoff * GlobalVar.inverseHologramScale; effectivePivotTransferCutoff = pivotTransferCutoff * GlobalVar.inverseHologramScale; #endregion #region Correct Y Position of ServiceSlices foreach (ServiceSlice slice in serviceSlices) { Vector3 correctedPosition = slice.transform.position; //correctedPosition.y = Mathf.Max(slice.height, slice.height * GlobalVar.inverseHologramScale); correctedPosition.y = GlobalVar.hologramTableHeight + (slice.height - GlobalVar.hologramTableHeight) * GlobalVar.inverseHologramScale; slice.transform.position = correctedPosition; } #endregion #region Correct Height of downward Connections Vector3 oldDClocalScale = downwardConnectionContainer.transform.localScale; Vector3 oldDCposition = downwardConnectionContainer.transform.position; oldDClocalScale.y = GlobalVar.inverseHologramScale; oldDCposition.y = -(GlobalVar.inverseHologramScale * GlobalVar.hologramTableHeight) + GlobalVar.hologramTableHeight; downwardConnectionContainer.transform.localScale = oldDClocalScale; downwardConnectionContainer.transform.position = oldDCposition; #endregion }
// Update is called once per frame void Update() { //Identify which controllers are using the object from the touching list usingControllerList.Clear(); if (touchingControllerList.Count > 0) { foreach (GameObject go in touchingControllerList) { Hand h = go.GetComponent <Hand>(); if (h != null) { if (h.GetStandardInteractionButton()) { usingControllerList.Add(h); } } } } //Handle Movement if (usingControllerList.Count == 1) { Vector3 controllerVelocity = usingControllerList[0].GetTrackedObjectVelocity(); currentTranslationVelocity = controllerVelocity; currentTranslationVelocity.y = 0f; updateTranslation(false); } else if (usingControllerList.Count == 2) { //current pivot Vector3 origin1 = usingControllerList[0].gameObject.transform.GetChild(0).position; Vector3 origin2 = usingControllerList[1].gameObject.transform.GetChild(0).position; Vector3 currentPivot = (origin1 + origin2) / 2f; //next pivot Vector3 controllerVelocity1 = usingControllerList[0].GetTrackedObjectVelocity(); Vector3 controllerVelocity2 = usingControllerList[1].GetTrackedObjectVelocity(); Vector3 nextOrigin1 = controllerVelocity1 * Time.deltaTime + origin1; Vector3 nextOrigin2 = controllerVelocity2 * Time.deltaTime + origin2; Vector3 nextPivot = (nextOrigin1 + nextOrigin2) / 2f; //For an ideal scale/rotate gesture the pivot would stay the same. For real world applications //the pivotTransferCutoff allows for some sloppiness in the gesture if (Vector3.Distance(currentPivot, nextPivot) < pivotTransferCutoff) { //Scale Vector3 diffCurrent = origin1 - origin2; Vector3 diffNext = nextOrigin1 - nextOrigin2; float scalingFactor = diffNext.magnitude / diffCurrent.magnitude; //scalePivot = currentPivot except, scalingPivot should not vary with the y component Vector3 scalePivot = new Vector3(currentPivot.x, transformCandidate.transform.position.y, currentPivot.z); Vector3 scaleVec = new Vector3(scalingFactor, scalingFactor, scalingFactor); Helperfunctions.scaleFromPivot(transformCandidate.transform, scalePivot, scaleVec); Helperfunctions.scaleFromPivot(mainSliceContainer.transform, scalePivot, scaleVec); scaleVec.y = 1f; Helperfunctions.scaleFromPivot(downwardConnectionContainer.transform, scalePivot, scaleVec); //Rotation //float norm = (Mathf.PI / 4.0f); //float radCurrent = Helperfunctions.DiamondAngle(diffCurrent.x, diffCurrent.z) * norm; //float radNext = Helperfunctions.DiamondAngle(diffNext.x, diffNext.z) * norm; float radCurrent = Mathf.Atan2(diffCurrent.x, diffCurrent.z); float radNext = Mathf.Atan2(diffNext.x, diffNext.z); float rotationAngle = Mathf.Rad2Deg * (radNext - radCurrent); transformCandidate.transform.RotateAround(currentPivot, Vector3.up, rotationAngle * rotationMult); mainSliceContainer.transform.RotateAround(currentPivot, Vector3.up, rotationAngle * rotationMult); downwardConnectionContainer.transform.RotateAround(currentPivot, Vector3.up, rotationAngle * rotationMult); //Correct Y Position of ServiceSlices foreach (ServiceSlice slice in serviceSlices) { Vector3 correctedPosition = slice.transform.position; correctedPosition.y = slice.height; slice.transform.position = correctedPosition; } } } else { updateTranslation(true); } }