public static void RemoveObjFromSelected(ObjSelected obj) { if (GameObject.ReferenceEquals(manager.objSelected, obj)) { manager.objSelected = null; } }
Quaternion CalcRotation(ObjSelected objSelected, List <Hand> interactingHands) { Quaternion q = Quaternion.identity; if (interactingHands.Count == 1) // grabbing with one hand { q = interactingHands[0].GetComponent <TransformStep>().rotationStep; } else if (interactingHands.Count == 2) // grabbing with both hands, bimanual rotation { float rotX = interactingHands[0].transform.rotation.eulerAngles.x + interactingHands[1].transform.rotation.eulerAngles.x; //calculate the rot difference between the controllers in the X axis. Vector3 direction1 = oldPointsForRotation[0] - oldPointsForRotation[1]; Vector3 direction2 = interactingHands[0].transform.position - interactingHands[1].transform.position; var difRotX = rotX - rotXOld; Vector3 cross = Vector3.Cross(direction1, direction2); float amountToRot = Vector3.Angle(direction1, direction2); q = Quaternion.AngleAxis(amountToRot, cross.normalized); //calculate the rotation with 2 hands q = q * Quaternion.Euler(difRotX, 0f, 0f); rotXOld = rotX; oldPointsForRotation[0] = interactingHands[0].transform.position; oldPointsForRotation[1] = interactingHands[1].transform.position; } return(q); }
// THE COMMENTED FUNCTIONS ARE FOR MULTIPLE OBJECT SELECTION (THEY ARE STORED IN A LIST) //public static ObjSelected FindObject(GameObject obj) //{ // foreach (ObjSelected selected in manager.objsSelected) // { // if (GameObject.ReferenceEquals(selected.obj, obj)) // return selected; // } // return null; //} //public static void AddToSelectedList(GameObject obj, Hand h) //{ // var index = DetermineIndexSelected(obj); // ObjSelected objS = new ObjSelected(); // objS.index = index; // objS.obj = obj; // objS.hands = new List<Hand>(); // objS.hands.Add(h); // manager.objsSelected.Add(objS); //} //public static void SetSelected(GameObject obj, Hand h) //{ // var found = FindObject(obj); // if (found == null) // if it is not selected, add to list // { // AddToSelectedList(obj,h); // add the object and the hand whitch is selecting it // } // else // it is already selected, we need to verify if the hand that is selecting is other hand // { // if(!found.hands.Contains(h)) // if is not the same hand, add this hand to the obj // found.hands.Add(h); // } //} //public static void RemoveObjFromSelectedList(ObjSelected obj) //{ // if (manager.objsSelected.Contains(obj)) // manager.objsSelected.Remove(obj); //} //public static List<ObjSelected> GetAllSelected() //{ // if (manager.objsSelected != null) // return manager.objsSelected; // return null; //} //public static ObjSelected GetSelected(int index) //{ // if (index < manager.objsSelected.Count && index >= 0) // return manager.objsSelected[index]; // return null; //} //public static void DetachObjectFromHand(GameObject obj, Hand h) //{ // var found = FindObject(obj); // if (found == null) return; // if it is not selected, nothing to do, return // if (found.hands.Contains(h)) // if the object is being selected by this hand // found.hands.Remove(h); // if (found.hands.Count == 0) // there is no hand selecting the object, remove object from the selected list // RemoveObjFromSelectedList(found); //} // Use this for initialization void Start() { allObjects = GameObject.Find("InteractableObjects"); for (int i = 0; i < allObjects.transform.childCount; i++) { list.Add(allObjects.transform.GetChild(i).gameObject); } objSelected = null; manager = this; }
Vector3 CalcTranslation(ObjSelected objSelected, List <Hand> interactingHands) { Vector3 averagePoint = new Vector3(); foreach (Hand h in interactingHands) { averagePoint += h.gameObject.GetComponent <TransformStep>().positionStep; } averagePoint /= interactingHands.Count; return(averagePoint); }
public static void AddToSelected(GameObject obj, Hand h) { var index = DetermineIndexSelected(obj); ObjSelected objS = new ObjSelected(); objS.index = index; objS.gameobject = obj; //objS.hands = new List<Hand>(); //objS.hands.Add(h); //if(h.otherHand != null) // objS.hands.Add(h.otherHand); // add the other hand manager.objSelected = objS; }
float CalcScale(ObjSelected objSelected, List <Hand> interactingHands) { //if (interactingHands.Count == 1) //{ // RESERVED FOR ONE HAND SCALE //} float scaleStep = 0f; if (interactingHands.Count == 2) { float avgScaleMag = 0f; avgScaleMag += (buttonSync.leftHand.transform.position - buttonSync.rightHand.transform.position).magnitude; avgScaleMag += (buttonSync.rightHand.transform.position - buttonSync.leftHand.transform.position).magnitude; avgScaleMag /= interactingHands.Count; // to scale the object in between both hands scaleStep = avgScaleMag - oldScaleMag; oldScaleMag = avgScaleMag; } return(scaleStep); }