// Update is called once per frame internal void Update() { // Do a raycast into the world based on the user's // head position and orientation. var headPosition = Camera.main.transform.position; var gazeDirection = Camera.main.transform.forward; Vector3 point; bool hit = false; bool getDistance = true; RaycastHit hitInfo; oldCube = cube; Vector3 normal = Camera.main.transform.position.normalized; if (!TwoHandedGesturesManager.resizing && !TwoHandedGesturesManager.rotating) { if (Physics.Raycast(headPosition, gazeDirection, out hitInfo, MaxGazeDistance)) { hit = true; } onHologram = true; if (hit) { normal = hitInfo.normal; point = hitInfo.point; cube = hitInfo.transform.gameObject; rotateCursors(Quaternion.FromToRotation(Vector3.forward, normal)); //if we hit an object if (boundingCubesInverse.ContainsKey(cube)) { hologram = cube; boundingCubesInverse.TryGetValue(cube, out cube); getDistance = false; } else if (boundingCubes.TryGetValue(cube, out hologram)) { getDistance = false; } else { cube = null; hologram = null; } } else { point = headPosition + (gazeDirection * MaxGazeDistance); cube = null; hologram = null; } if (TwoHandedGesturesManager.TECHNIQUE_SELECTED == TwoHandedGesturesManager.TECHNIQUE_5) { moveCursors(point); GameObject boxCube, sphere; bool hitCube = false; bool hitSphere = false; float distanceToPoint = .5f; for (int i = 0; i < 8; i++) { boxCube = BoundBoxes_BoundBox.cubes [i]; sphere = BoundBoxes_BoundBox.spheres [i]; // we hit a cube if (hit && ((hitInfo.transform.gameObject == boxCube) || Vector3.Distance(point, boxCube.transform.position) <= BoundBoxes_BoundBox.currentCubeSize * distanceToPoint)) { objectUnderCursorTranslation = point - boxCube.transform.position; originalOjectLocalScale = boxCube.transform.localScale; objectUnderCursor = boxCube; handsManager.ColorObject(boxCube, highlightedCubeColor); onCube = true; hitCube = true; handsManager.resizeCursor.SetActive(true); handsManager.normalCursor.SetActive(false); handsManager.yawCursor.SetActive(false); handsManager.pitchCursor.SetActive(false); handsManager.rollCursor.SetActive(false); } else { handsManager.ColorObject(boxCube, regularCubeColor); } // we hit a sphere if (hit && ((hitInfo.transform.gameObject == sphere) || Vector3.Distance(point, sphere.transform.position) <= BoundBoxes_BoundBox.currentCubeSize * distanceToPoint)) { objectUnderCursorTranslation = point - sphere.transform.position; originalOjectLocalScale = sphere.transform.localScale; objectUnderCursor = sphere; handsManager.ColorObject(sphere, highlightedCubeColor); onSphere = true; sphereIndexUnderCursor = i; hitSphere = true; if (sphereIndexUnderCursor < 4) { handsManager.yawCursor.SetActive(true); handsManager.pitchCursor.SetActive(false); handsManager.rollCursor.SetActive(false); } else if (sphereIndexUnderCursor < 6) { handsManager.pitchCursor.SetActive(true); handsManager.rollCursor.SetActive(false); handsManager.yawCursor.SetActive(false); } else { handsManager.rollCursor.SetActive(true); handsManager.yawCursor.SetActive(false); handsManager.pitchCursor.SetActive(false); } handsManager.normalCursor.SetActive(false); handsManager.resizeCursor.SetActive(false); } else { handsManager.ColorObject(sphere, regularCubeColor); } } if (!hitCube) { onCube = false; } if (!hitSphere) { onSphere = false; } if (!hitCube && !hitSphere) { handsManager.yawCursor.SetActive(false); handsManager.pitchCursor.SetActive(false); handsManager.rollCursor.SetActive(false); handsManager.resizeCursor.SetActive(false); handsManager.normalCursor.SetActive(true); } } else { GameObject menu = GameObject.Find("Menu"); float dist = Vector3.Distance(point, handsManager.menu.transform.position); if ((menu && hit && hitInfo.transform.IsChildOf(menu.transform)) || (dist < 0.75f)) { moveCursors(point); handsManager.normalCursor.SetActive(true); } else { handsManager.normalCursor.SetActive(false); //moveCursors (headPosition + (gazeDirection * MaxGazeDistance)); } handsManager.resizeCursor.SetActive(false); handsManager.yawCursor.SetActive(false); handsManager.pitchCursor.SetActive(false); handsManager.rollCursor.SetActive(false); } if (getDistance) { //find closest object float smallest_distance = 100000; float distance; GameObject closest_cube = cube; foreach (KeyValuePair <GameObject, GameObject> entry in boundingCubes) { distance = Vector3.Distance(entry.Key.transform.position, point); if ((distance < smallest_distance) && entry.Value.activeSelf) { smallest_distance = distance; closest_cube = entry.Key; } } //if(smallest_distance < min_distance) { if (closest_cube != null) { cube = closest_cube; boundingCubes.TryGetValue(cube, out hologram); } else { onHologram = false; } } //if we change targets if (hologram != lastHologram) { BoundBoxes_BoundBox.initialized = false; } lastHologram = hologram; position = point; if (SHOW_BOUNDING_BOX) { if (oldCube != null && oldCube != cube) { oldCube.GetComponent <Renderer> ().enabled = false; } if (onHologram) { cube.GetComponent <Renderer> ().enabled = true; } } else { if (onHologram) { cube.GetComponent <Renderer>().enabled = false; } } } else { if ((TwoHandedGesturesManager.TECHNIQUE_SELECTED == TwoHandedGesturesManager.TECHNIQUE_5)) { moveCursors(objectUnderCursor.transform.position + objectUnderCursorTranslation * objectUnderCursor.transform.localScale.x / originalOjectLocalScale.x); } } }