public void MoveCameraCenterToObject() { moving = true; ModelingObject currentObj = selection.currentSelection.GetComponent <ModelingObject> (); currentObj.handles.HideRotationHandlesExcept(null); currentObj.handles.HideScalingHandlesExcept(null); currentObj.connectingLinesHandles.ClearLines(); // get desired distance based on objet size? //desiredDistance = 5f; LeanTween.move(target.gameObject, currentObj.GetBoundingBoxCenter(), 0.8f).setEase(LeanTweenType.easeInOutExpo).setOnComplete(ReachGoal); // maybe also implement move closer }
public void DuplicateObject(ModelingObject original, Group group, Vector3 objectPosition) { //Debug.Log ("before: " + objectPosition); //Debug.Log ("after inverse transform point: " + original.transform.InverseTransformPoint (objectPosition)); if (original.complexObject.transform.childCount == 0) { createNewObject(original.typeOfObject, null, original, objectPosition, true, group, original.currentColor, null); } else { createNewObject(original.typeOfObject, null, original, objectPosition, true, group, original.currentColor, original.complexObject.transform.GetChild(0).gameObject); } if (group == null) { DuplicateAnimaton(original.GetBoundingBoxCenter()); } }
private void Rotate(GameObject pointOfCollision, Selection controller, bool visual) { // fix centers etc //Debug.Log ("rotate"); if (newRotation) { VisualizeAngle.Instance.Show(); connectedModelingObject.HideBoundingBox(false); // center object on raster /* * Vector3 center = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxBottomCenter()); * Vector3 correctedCenter = RasterManager.Instance.Raster(center); * * connectedModelingObject.transform.localPosition = connectedModelingObject.transform.localPosition + (correctedCenter-center); */ // define rotation axis p1Rotation = connectedModelingObject.GetBoundingBoxCenter(); p2Rotation = p1Rotation + (p1.transform.position - p2.transform.position); rotationAxis = connectedModelingObject.transform.InverseTransformDirection(p2Rotation - p1Rotation); currentPlane = new Plane((p1Rotation - p2Rotation).normalized, transform.position); currentPlaneOtherDirection = new Plane((-1f) * (p1Rotation - p2Rotation).normalized, transform.position); // get center of rotaion: Ray rayCenterToPlane = new Ray(p1Rotation, (p1Rotation - p2Rotation).normalized * (-1f)); Ray rayCenterToPlaneOtherDir = new Ray(p1Rotation, (p1Rotation - p2Rotation).normalized); float rayDistanceToCenter; if (currentPlane.Raycast(rayCenterToPlane, out rayDistanceToCenter)) { centerOfRotation = rayCenterToPlane.GetPoint(rayDistanceToCenter); } else if (currentPlaneOtherDirection.Raycast(rayCenterToPlaneOtherDir, out rayDistanceToCenter)) { centerOfRotation = rayCenterToPlaneOtherDir.GetPoint(rayDistanceToCenter); } centerOfRotation = transform.position; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float rayDistance; float newRotationAmount = 0f; if (currentPlane.Raycast(ray, out rayDistance)) { if (rayDistance < 25f) { if (newRotation) { lastIntersectionPoint = ray.GetPoint(rayDistance); // fix point rotationRelativeTo = lastIntersectionPoint; } //Vector3 intersectionPoint = Vector3.SmoothDamp (lastIntersectionPoint, ray.GetPoint (rayDistance), ref velocityRotation, smoothTimeRotation); Vector3 intersectionPoint = ray.GetPoint(rayDistance); Vector3 adjustedIntersectPoint = p1Rotation + (intersectionPoint - p1Rotation).normalized * 1.5f; float direction = Mathf.Sign(Vector3.Dot(Vector3.Cross(rotationRelativeTo - p1Rotation, adjustedIntersectPoint - p1Rotation), currentPlane.normal)); lastIntersectionPoint = intersectionPoint; // to do: check Angle to center on point of intersection newRotationAmount = Vector3.Angle(rotationRelativeTo - centerOfRotation, intersectionPoint - centerOfRotation) * direction * (-1f); } } else if (currentPlaneOtherDirection.Raycast(ray, out rayDistance)) { if (rayDistance < 25f) { if (newRotation) { lastIntersectionPoint = ray.GetPoint(rayDistance); } Vector3 intersectionPoint = Vector3.SmoothDamp(lastIntersectionPoint, ray.GetPoint(rayDistance), ref velocityRotation, smoothTimeRotation); Vector3 adjustedIntersectPoint = p1Rotation + (intersectionPoint - p1Rotation).normalized * 1.5f; float direction = Mathf.Sign(Vector3.Dot(Vector3.Cross(rotationRelativeTo - p1Rotation, adjustedIntersectPoint - p1Rotation), currentPlaneOtherDirection.normal)); lastIntersectionPoint = intersectionPoint; // to do: check Angle to center on point of intersection newRotationAmount = Vector3.Angle(rotationRelativeTo - centerOfRotation, intersectionPoint - centerOfRotation) * direction; } } if (newRotationAmount < 0) { newRotationAmount = 360f + newRotationAmount; } if (visual) { if (rotationVisual == null) { rotationVisual = Instantiate(rotationVisualPrefab); rotationVisual.transform.localScale = Vector3.one * (rotationRelativeTo - centerOfRotation).magnitude * 1.85f; rotationVisual.GetComponent <RotationVisual> ().ColorCircle(normalColor); RotationOnStartLine = Instantiate(handles.linesGO); CurrentRotationLine = Instantiate(handles.linesGO); firstIntersectionPoint = lastIntersectionPoint; } rotationVisual.transform.position = centerOfRotation; rotationVisual.transform.rotation = Quaternion.LookRotation(p2Rotation - p1Rotation); } float count = Mathf.Round(newRotationAmount / 90f); float distanceToCenter = (lastIntersectionPoint - centerOfRotation).magnitude / (rotationRelativeTo - centerOfRotation).magnitude; float disToCenter = (lastIntersectionPoint - centerOfRotation).magnitude; float maxDistance = connectedModelingObject.boundingBox.getMaxDistanceinBB(centerOfRotation); //float circleSize = (transform.position - connectedModelingObject.GetBoundingBoxCenter ()).magnitude * 2f; //Debug.Log ("distance at " + maxDistance / disToCenter); //if (maxDistance/disToCenter > 0.75f) { if (!(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { newRotationAmount = RasterManager.Instance.RasterAngle(newRotationAmount); //newRotationAmount = RasterManager.Instance.RasterAngleSmooth (newRotationAmount); } else { newRotationAmount = RasterManager.Instance.RasterAngleSmooth(newRotationAmount); } if (newRotation) { prevRotationAmount = newRotationAmount; firstRotationAmount = newRotationAmount; newRotation = false; reCheckRotationDirection = true; } float shortestRotationAmount = newRotationAmount - prevRotationAmount; if (shortestRotationAmount > 180) { shortestRotationAmount = shortestRotationAmount - 360f; } connectedModelingObject.RotateAround(rotationAxis.normalized, shortestRotationAmount, connectedModelingObject.transform.InverseTransformPoint(p1Rotation)); /* * CurrentRotationLine.GetComponent<Lines> ().DrawLinesWorldCoordinate (new Vector3[] { * centerOfRotation, * lastIntersectionPoint * }, 0); */ float showingValue = newRotationAmount - firstRotationAmount; if (showingValue == 360f) { showingValue = 0f; } if (showingValue <= 5f && showingValue >= -5f) { reCheckRotationDirection = true; } if (reCheckRotationDirection) { if (showingValue > 180f) { showingValue = showingValue - 360f; reCheckRotationDirection = false; } else if (showingValue < -180f) { showingValue = showingValue + 360f; reCheckRotationDirection = false; } if (showingValue < 0f) { rotationDirection = -1f; } else { rotationDirection = 1f; } } if (rotationDirection == -1f && showingValue > 0f) { showingValue = showingValue - 360f; } else if (rotationDirection == 1f && showingValue < 0f) { showingValue = showingValue + 360f; } VisualizeAngle.Instance.SetNumber(showingValue); //Debug.Log ("Distace bei " + (maxDistance / disToCenter)); if (visual) { //if (maxDistance/disToCenter > 0.75f) { if (!(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { //rotationVisual.GetComponent<RotationVisual> ().RotationVisualisation (firstIntersectionPoint, lastIntersectionPoint, true); rotationVisual.GetComponent <RotationVisual> ().RotationVisualisation(firstIntersectionPoint, lastIntersectionPoint, false, showingValue); } else { rotationVisual.GetComponent <RotationVisual> ().RotationVisualisation(firstIntersectionPoint, lastIntersectionPoint, true, showingValue); } } prevRotationAmount = newRotationAmount; }