public void BeginInteraction(ControllerFunctions wand) { attachedWand = wand; currentlyInteracting = true; if (materials.Length > 0) { renderer.sharedMaterial = materials[1]; } }
public void EndInteraction(ControllerFunctions wand) { if (wand == attachedWand) { attachedWand = null; currentlyInteracting = false; rigidbody.useGravity = origGravitySetting; rigidbody.isKinematic = origIsKinematicSetting; if (materials.Length > 0) { renderer.sharedMaterial = materials[0]; } } }
public void startScaling(ControllerFunctions interactingWand, InteractableItem collidedItem) { Transform interactingPoint = interactingWand.transform; float currentDistance = (controllerTransform.position - interactingWand.transform.position).magnitude; float scalingFactor = (currentDistance / oldDistance); Vector3 itemScale = collidedItem.transform.localScale; Vector3 controllerToCube = collidedItem.transform.position - controllerTransform.position; if (scalingFactor - 1 > .1F || scalingFactor - 1 > -.1F) { collidedItem.transform.localScale = new Vector3(itemScale.x * scalingFactor, itemScale.y * scalingFactor, itemScale.z * scalingFactor); } oldDistance = currentDistance; }
public void startRotating(ControllerFunctions interactingWand, InteractableItem collidedItem) { //Create GameObject for center point, use Matrix math to find offset of object from centerpoint centerPoint.transform.position = newCenterPosition; Matrix4x4 newCenterTransformMatrix = centerPoint.transform.localToWorldMatrix; Matrix4x4 newObjectMatrix = newCenterTransformMatrix * objectOffsetMatrix; collidedItem.transform.position = extractPosition(newObjectMatrix); //Calculate Rotation newRotationVector = this.transform.position - collidedItem.GetInteractingController().transform.position; Vector3 axisRotationVector = Vector3.Cross(oldRotationVector, newRotationVector); float angle = Vector3.Angle(oldRotationVector, newRotationVector); Quaternion differentialRotation = Quaternion.AngleAxis(angle, axisRotationVector); collidedItem.transform.rotation = differentialRotation * collidedItem.transform.rotation; oldRotationVector = newRotationVector; }
// Use this for initialization void Start() { tracked_obj = GetComponent <SteamVR_TrackedObject>(); drag_script = GetComponent <ControllerFunctions>(); wand = GameObject.Find("Wand"); pointer = GameObject.Find("Pointer"); current_cursor = GameObject.Find("Cursor"); brush = GameObject.Find("Brush"); Text = GameObject.Find("Text"); //laser_default_length = pointer.GetComponent<Renderer>().bounds.size.z; //print("default length = " + laser_default_length); if (wand != null && pointer != null && brush != null && Text != null) { // hide the wand wand.SetActive(false); pointer.SetActive(false); brush.SetActive(false); Text.SetActive(false); } else { Debug.Log("No wand object assigned!"); } init_brush(); }