private IEnumerator CameraPointTransition(CameraPoint targetCameraPoint) { float currentTime = 0f; while (currentTime < 1) { currentTime += Time.deltaTime / cameraTransitionTime; if (currentTime > 1) { currentTime = 1; } transform.position = Vector3.Slerp(currentCameraPoint.transform.position, targetCameraPoint.transform.position, currentTime); transform.LookAt(targetCameraPoint.cameraTargetTransform); yield return(new WaitForEndOfFrame()); } currentCameraPoint = targetCameraPoint; currentCameraTransitionCoroutine = null; yield return(null); }
private void CameraSetup() { currentCameraPoint = playerCameraPoints[0]; transform.position = currentCameraPoint.transform.position; transform.rotation = currentCameraPoint.transform.rotation; }
IEnumerator moveCameraFocus(CameraPoint newPoint){ customCamera = true; Vector3 oldFocus = _focusPosition; Vector3 newFocus = newPoint.gameObject.transform.position; float oldDistance = _distance; float oldAngle = _y; Quaternion oldHeading = transform.rotation; oldHeading.eulerAngles = new Vector3(0f, oldHeading.eulerAngles.y,0f); float startTime = Time.time; float travelTime = (newFocus-_focusPosition).magnitude / 10f; if (travelTime > 0.1f){ while(Time.time <= startTime + travelTime){ float factor = (Time.time - startTime)/travelTime; _focusPosition = Vector3.Lerp(oldFocus, newFocus, Mathf.SmoothStep(0f, 1f, factor)); _x = Quaternion.Slerp(oldHeading, newPoint.gameObject.transform.rotation, Mathf.SmoothStep(0f, 1f, factor)).eulerAngles.y; _y = Mathf.Lerp(oldAngle, newPoint.startAngle, Mathf.SmoothStep(0f, 1f, factor)); _distance = Mathf.Lerp(oldDistance, newPoint.startDistance, Mathf.SmoothStep(0f, 1f, factor)); yield return null; } _focusPosition = newFocus; _maxDistance = newPoint.maxDistance; _minDistance = newPoint.minDistance; _highAngle = newPoint.maxAngle; _lowAngle = newPoint.minAngle; // _target = newTarget; } }
/** * Move the camera to its initial position. */ void Start () { if (_target != null) { Vector2 angles = _target.transform.localEulerAngles; if(!_target.GetComponent<CameraPoint>()) { _x = angles.y; _y = 0f; } else { CameraPoint cp = _target.GetComponent<CameraPoint>(); _x = angles.y; _y = cp.startAngle; _distance = cp.startDistance; } } else { _target = new GameObject("CameraTarget"); _x = 0f; _y = 0f; } // _distance = .75f * _maxDistance; _distanceVector = new Vector3(0.0f,0.0f,-_distance); _focusPosition = _target.transform.position; Input.gyro.enabled = true; }
// Todo: cubic interpolation public override void OnNewFrame(Game game, NewFrameEventArgs args) { float dt = args.GetDt(); if (playingTime == -1) { return; } playingTime += dt; float playingDist = playingTime * playingSpeed; UpdateAvi(dt); float distA = 0; int foundPoint = -1; for (int i = 0; i < cameraPointsCount - 1; i++) { CameraPoint a = cameraPoints[i]; CameraPoint b = cameraPoints[i + 1]; float dist = Distance(a, b); if (playingDist >= distA && playingDist < distA + dist) { foundPoint = i; break; } distA += dist; } if (foundPoint == -1) { Stop(); return; } { CameraPoint a = cameraPoints[foundPoint]; CameraPoint b = cameraPoints[foundPoint + 1]; CameraPoint aminus = a; CameraPoint bplus = b; if (foundPoint - 1 >= 0) { aminus = cameraPoints[foundPoint - 1]; } if (foundPoint + 2 < cameraPointsCount) { bplus = cameraPoints[foundPoint + 2]; } float t = (playingDist - distA) / Distance(a, b); float x = q(t, aminus.positionGlX, a.positionGlX, b.positionGlX, bplus.positionGlX); float y = q(t, aminus.positionGlY, a.positionGlY, b.positionGlY, bplus.positionGlY); float z = q(t, aminus.positionGlZ, a.positionGlZ, b.positionGlZ, bplus.positionGlZ); m.SetLocalPosition(x, y, z); float orientx = q(t, aminus.orientationGlX, a.orientationGlX, b.orientationGlX, bplus.orientationGlX); float orienty = q(t, aminus.orientationGlY, a.orientationGlY, b.orientationGlY, bplus.orientationGlY); float orientz = q(t, aminus.orientationGlZ, a.orientationGlZ, b.orientationGlZ, bplus.orientationGlZ); m.SetLocalOrientation(orientx, orienty, orientz); } }
float Distance(CameraPoint a, CameraPoint b) { float dx = a.positionGlX - b.positionGlX; float dy = a.positionGlY - b.positionGlY; float dz = a.positionGlZ - b.positionGlZ; return(p.MathSqrt(dx * dx + dy * dy + dz * dz)); }
public void MoveToNextEnemyCameraPoint() { CameraPoint nextCameraPoint = ReturnEnemyCameraPoint(); MoveToCameraPoint(nextCameraPoint); isLookingAtEnemy = true; isLookingAtPlayer = false; }
private void LateUpdate() { if (CurPreview != -1) { SetCamOnPoint(SmoothCamPoints[CurPreview]); } if (Preview != null) { SetCamOnPoint(Preview); } if (this.takeHiResShot) { CameraPoint StartCP = new CameraPoint(); StartCP.pos = camera.transform.position; StartCP.rot = camera.transform.rotation; camera.enabled = false; float LoadBias = QualitySettings.lodBias; QualitySettings.lodBias = Mathf.Infinity; ScriptableSingleton <UIAssetManager> .Instance.uiWindowFrameGO.enabled = false; if (this.followPath) { this.SetCamOnPoint(this.SmoothCamPoints[this.CurScreenShotCount]); } else { if (CamPoints.Count > 0) { this.SetCamOnPoint(this.CamPoints[0]); } } float StartNear = camera.nearClipPlane; float StartFar = camera.farClipPlane; camera.nearClipPlane = 0f; camera.farClipPlane = 1600f; RenderTexture renderTexture = new RenderTexture(this.resWidth, this.resHeight, 24); this.camera.targetTexture = renderTexture; Texture2D texture2D = new Texture2D(this.resWidth, this.resHeight, TextureFormat.RGB24, false); this.camera.Render(); RenderTexture.active = renderTexture; texture2D.ReadPixels(new Rect(0f, 0f, (float)this.resWidth, (float)this.resHeight), 0, 0); SetCamOnPoint(StartCP); camera.enabled = true; this.camera.targetTexture = null; RenderTexture.active = null; Destroy(renderTexture); byte[] bytes = texture2D.EncodeToPNG(); string text = TimeLapse.ScreenShotName(this.resWidth, this.resHeight, this.Path, CurScreenShotCount, Name); File.WriteAllBytes(text, bytes); Debug.Log(string.Format("Took screenshot to: {0}", text)); Destroy(texture2D); QualitySettings.lodBias = LoadBias; camera.nearClipPlane = StartNear; camera.farClipPlane = StartFar; this.takeHiResShot = false; } }
bool IsInRange(CameraPoint Point) { if (Target.transform.position.x > Point.transform.position.x - Point.FixedSize.x && Target.transform.position.x < Point.transform.position.x + Point.FixedSize.x && Target.transform.position.y > Point.transform.position.y - Point.FixedSize.y && Target.transform.position.y < Point.transform.position.y + Point.FixedSize.y) return true; else return false; }
public void SetCameraPoint(CameraPoint cameraPoint) { newWaypointTime = Time.time; previousOrthographicSize = camera.orthographicSize; previousX = transform.position.x; previousY = transform.position.y; previousZ = transform.position.z; this.cameraPoint = cameraPoint; arrived = false; }
private void MoveToCameraPoint(CameraPoint targetCameraPoint) { if (currentCameraTransitionCoroutine != null) { StopCoroutine(currentCameraTransitionCoroutine); } currentCameraTransitionCoroutine = CameraPointTransition(targetCameraPoint); StartCoroutine(CameraPointTransition(targetCameraPoint)); }
public override MapItem Deserialize(BinaryReader r) { var point = new CameraPoint(false); ReadKdopItem(r, point); point.Tags = ReadObjectList <Token>(r); point.Node = new UnresolvedNode(r.ReadUInt64()); return(point); }
public override void Start(ClientModManager modmanager) { m = modmanager; p = modmanager.GetPlatform(); one = 1; cameraPoints = new CameraPoint[256]; cameraPointsCount = 0; playingTime = -1; position = new float[3]; orientation = new float[3]; }
public GameObject GetSavedCamPoint(int _savedID) { foreach (GameObject curCP in allCamPoints) { CameraPoint cpRef = curCP.GetComponent <CameraPoint>(); if (cpRef.isActive) { cpRef.isActive = false; } } return(allCamPoints.Find(camPoint => camPoint.GetComponent <CameraPoint> ().localID == _savedID)); }
//固定摄像机模式 bool MethodFixed(CameraPoint Point) { if (IsInRange(Point)) { Vector3 Destination = new Vector3(Point.transform.position.x, Point.transform.position.y, MainCamera.transform.position.z); Vector3 PositionNow = Vector3.Lerp(MainCamera.transform.position, Destination, FollowSpeed * Time.deltaTime); MainCamera.transform.position = new Vector3(PositionNow.x, PositionNow.y, PositionNow.z); return true; } return false; }
void SetCameraPos(CameraPoint point) { var offset = Vector3.zero; if (focusObj) { var focusTran = focusObj.transform; switch (point) { case CameraPoint.Front: offset = focusTran.forward * 10; break; case CameraPoint.Left: offset = focusTran.right * (-10); break; case CameraPoint.Right: offset = focusTran.right * 10; break; case CameraPoint.Body: offset = focusTran.forward * 20; break; } go.transform.position = focusTran.position + offset; focusPos = focusTran.position; } else { focusPos = Vector3.zero; switch (point) { case CameraPoint.Front: offset = Vector3.forward * 10; break; case CameraPoint.Left: offset = Vector3.right * (-10); break; case CameraPoint.Right: offset = Vector3.right * 10; break; case CameraPoint.Body: offset = Vector3.forward * 20; break; } go.transform.position = offset; } go.transform.LookAt(focusPos); }
public override void update(float time_delta_fraction) { // Acquire the Camera Point nearest the player. GameObject targetPoint = CameraPoint.GetCurrentCameraPoint(); // Calculate the displacement the camera should make. Vector3 dp = (targetPoint.transform.position - cam.transform.position) * 0.02f; dp = new Vector3(dp.x, dp.y, 0); // Apply the calculated displacement. cam.transform.position += dp * time_delta_fraction; }
float TotalDistance() { float totalDistance = 0; for (int i = 0; i < cameraPointsCount - 1; i++) { CameraPoint a = cameraPoints[i]; CameraPoint b = cameraPoints[i + 1]; float dist = Distance(a, b); totalDistance += dist; } return(totalDistance); }
public void MoveToNextPlayerCameraPoint() { if (++playerCurrentCameraPointIndex > playerCameraPoints.Length - 1) { playerCurrentCameraPointIndex = 0; } CameraPoint nextCameraPoint = ReturnNextPlayerCameraPoint(); MoveToCameraPoint(nextCameraPoint); isLookingAtPlayer = true; isLookingAtEnemy = false; }
public Transform GetPoint(CameraPoint cameraPoint) { switch (cameraPoint) { case CameraPoint.Top: return(_top); case CameraPoint.Side: return(_side); case CameraPoint.Front: return(_front); } return(null); }
/// <summary> /// Initialises a new instance of the <see cref="CameraPathInterpolator" /> class. /// </summary> /// <param name="points">The list of nodes along a complete camera path.</param> /// <param name="target">The target, if any, that the camera focusses on as it traverses the path.</param> internal CameraPathInterpolator(IEnumerable <CameraPoint> points, Vec3d target = null) { _cameraPath = points.ToList(); // NOTE: We don't count the origin position in the count here. _nodesToTravel = _cameraPath.Count - 1; _point = new CameraPoint(); var linearPath = _cameraPath.Count == 2; var tmpInterpolator = linearPath ? LinearInterpolator.Create(_point) : CubicInterpolator.Create(_point); _interpolator = target != null ? TargetInterpolator.Create(tmpInterpolator, _point, target) : tmpInterpolator; }
IEnumerator singleOrDouble(){ yield return new WaitForSeconds(0.3f); if(touch.tapCount == 2) { //this coroutine has been called twice. We should stop the next one here otherwise we get two double tap StopCoroutine("singleOrDouble"); Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit)){ switchFocusPoint(hit.point); if (customCamera){ CameraPoint cp = _target.GetComponent<CameraPoint>(); _maxDistance = cp.maxDistance; _minDistance = cp.minDistance; _highAngle = cp.maxAngle; _lowAngle = cp.minAngle; customCamera = false; } } } }
public Vector3 GetCorner(CameraPoint corner, float distance) { var pos = new Vector3(); var fov = _cam.GetComponent <Camera>().fieldOfView *Math.PI / 180; float aspect = (float)Screen.width / (float)Screen.height; switch (corner) { case CameraPoint.Center: pos = _cam.transform.position + _cam.transform.TransformDirection(Vector3.forward * distance); break; case CameraPoint.BottonLeft: pos = _cam.transform.position + _cam.transform.TransformDirection( Vector3.forward * distance + (Vector3.left * (float)(Math.Tan(fov / 2) * distance * aspect)) + (Vector3.down * (float)(Math.Tan(fov / 2) * distance)) ); break; case CameraPoint.TopRight: pos = _cam.transform.position + _cam.transform.TransformDirection( Vector3.forward * distance + (Vector3.right * (float)(Math.Tan(fov / 2) * distance * aspect)) + (Vector3.up * (float)(Math.Tan(fov / 2) * distance)) ); break; } if (_bootstrap.IsEditor) { Debug.DrawRay(pos, Vector3.up * 2, Color.red, 5); } return(pos); }
void OnEnable() { myCameraPoint = (CameraPoint)target; }
public void switchFocusPoint(CameraPoint newPoint){ StopCoroutine("moveCameraFocus"); StartCoroutine("moveCameraFocus", newPoint); }
private void Awake() { Instance = this; }
public override bool OnClientCommand(Game game, ClientCommandArgs args) { if (args.command == "cam") { IntRef argumentsLength = new IntRef(); string[] arguments = p.StringSplit(args.arguments, " ", argumentsLength); if (p.StringTrim(args.arguments) == "") { m.DisplayNotification("&6AutoCamera help."); m.DisplayNotification("&6.cam p&f - add a point to path"); m.DisplayNotification("&6.cam start [real seconds]&f - play the path"); m.DisplayNotification("&6.cam rec [real seconds] [video seconds]&f - play and record to .avi file"); m.DisplayNotification("&6.cam stop&f - stop playing and recording"); m.DisplayNotification("&6.cam clear&f - remove all points from path"); m.DisplayNotification("&6.cam save&f - copy path points to clipboard"); m.DisplayNotification("&6.cam load [points]&f - load path points"); return true; } if (arguments[0] == "p") { m.DisplayNotification("Point defined."); CameraPoint point = new CameraPoint(); point.positionGlX = m.GetLocalPositionX(); point.positionGlY = m.GetLocalPositionY(); point.positionGlZ = m.GetLocalPositionZ(); point.orientationGlX = m.GetLocalOrientationX(); point.orientationGlY = m.GetLocalOrientationY(); point.orientationGlZ = m.GetLocalOrientationZ(); cameraPoints[cameraPointsCount++] = point; } if (arguments[0] == "start" || arguments[0] == "play" || arguments[0] == "rec") { if (!m.IsFreemoveAllowed()) { m.DisplayNotification("Free move not allowed."); return true; } if (cameraPointsCount == 0) { m.DisplayNotification("No points defined. Enter points with \".cam p\" command."); return true; } playingSpeed = 1; float totalRecTime = -1; if (arguments[0] == "rec") { if (argumentsLength.value >= 3) { // video time totalRecTime = p.FloatParse(arguments[2]); } avi = m.AviWriterCreate(); avi.Open(p.StringFormat("{0}.avi", p.Timestamp()), framerate, m.GetWindowWidth(), m.GetWindowHeight()); } if (argumentsLength.value >= 2) { // play time float totalTime = p.FloatParse(arguments[1]); playingSpeed = TotalDistance() / totalTime; if (totalRecTime == -1) { recspeed = 10; } else { recspeed = totalTime / totalRecTime; } } playingTime = 0; firstFrameDone = false; previousPositionX = m.GetLocalPositionX(); previousPositionY = m.GetLocalPositionY(); previousPositionZ = m.GetLocalPositionZ(); previousOrientationX = m.GetLocalOrientationX(); previousOrientationY = m.GetLocalOrientationY(); previousOrientationZ = m.GetLocalOrientationZ(); m.ShowGui(0); previousFreemove = m.GetFreemove(); m.SetFreemove(FreemoveLevelEnum.Noclip); m.EnableCameraControl(false); } if (arguments[0] == "stop") { m.DisplayNotification("Camera stopped."); Stop(); } if (arguments[0] == "clear") { m.DisplayNotification("Camera points cleared."); cameraPointsCount = 0; Stop(); } if (arguments[0] == "save") { string s = "1,"; for (int i = 0; i < cameraPointsCount; i++) { CameraPoint point = cameraPoints[i]; s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlX * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlY * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlZ * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlX * 1000))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlY * 1000))); s = p.StringFormat2("{0}{1}", s, p.IntToString(p.FloatToInt(point.orientationGlZ * 1000))); if (i != cameraPointsCount - 1) { s = p.StringFormat("{0},", s); } } p.ClipboardSetText(s); m.DisplayNotification("Camera points copied to clipboard."); } if (arguments[0] == "load") { IntRef pointsLength = new IntRef(); string[] points = p.StringSplit(arguments[1], ",", pointsLength); int n = (pointsLength.value - 1) / 6; cameraPointsCount = 0; for (int i = 0; i < n; i++) { CameraPoint point = new CameraPoint(); point.positionGlX = one * p.IntParse(points[1 + i * 6 + 0]) / 100; point.positionGlY = one * p.IntParse(points[1 + i * 6 + 1]) / 100; point.positionGlZ = one * p.IntParse(points[1 + i * 6 + 2]) / 100; point.orientationGlX = one * p.IntParse(points[1 + i * 6 + 3]) / 1000; point.orientationGlY = one * p.IntParse(points[1 + i * 6 + 4]) / 1000; point.orientationGlZ = one * p.IntParse(points[1 + i * 6 + 5]) / 1000; cameraPoints[cameraPointsCount++] = point; } m.DisplayNotification(p.StringFormat("Camera points loaded: {0}", p.IntToString(n))); } return true; } return false; }
// ִ������Start���� void Awake() { Instance = this; }
/// <summary> /// Initializes a new instance of the <see cref="InterpolationNodeArray" /> struct. /// </summary> /// <param name="previousNode"> /// The node before the last left behind node, which is the same as the current node at the beginning of the path. /// </param> /// <param name="currentNode">The most recent node the player left behind.</param> /// <param name="nextNode">The upcoming node the player has to pass.</param> /// <param name="nodeAfterNext">The node after the upcoming node which is the same as the next node at the end of the path.</param> internal InterpolationNodeArray( CameraPoint previousNode, CameraPoint currentNode, CameraPoint nextNode, CameraPoint nodeAfterNext) { (Previous, Current, Next, Subsequent) = (previousNode, currentNode, nextNode, nodeAfterNext); }
/// <summary> /// Initialises a new instance of the <see cref="TargetInterpolator" /> class. /// </summary> /// <param name="interpolator">The base interpolator to use for position and additional angles.</param> /// <param name="point">The camera point to transpose values into.</param> /// <param name="targetPos">The target position for the camera to focus on.</param> internal static ICameraPointInterpolator Create( ICameraPointInterpolator interpolator, CameraPoint point, Vec3d targetPos) { return(new TargetInterpolator(interpolator, point, targetPos)); }
public CameraPoint(CameraPoint point) { Time = point.Time; Easing = point.Easing; Data = point.Data; }
float Distance(CameraPoint a, CameraPoint b) { float dx = a.positionGlX - b.positionGlX; float dy = a.positionGlY - b.positionGlY; float dz = a.positionGlZ - b.positionGlZ; return p.MathSqrt(dx * dx + dy * dy + dz * dz); }
public override bool OnClientCommand(Game game, ClientCommandArgs args) { if (args.command == "cam") { IntRef argumentsLength = new IntRef(); string[] arguments = p.StringSplit(args.arguments, " ", argumentsLength); if (p.StringTrim(args.arguments) == "") { m.DisplayNotification("&6AutoCamera help."); m.DisplayNotification("&6.cam p&f - add a point to path"); m.DisplayNotification("&6.cam start [real seconds]&f - play the path"); m.DisplayNotification("&6.cam rec [real seconds] [video seconds]&f - play and record to .avi file"); m.DisplayNotification("&6.cam stop&f - stop playing and recording"); m.DisplayNotification("&6.cam clear&f - remove all points from path"); m.DisplayNotification("&6.cam save&f - copy path points to clipboard"); m.DisplayNotification("&6.cam load [points]&f - load path points"); return(true); } if (arguments[0] == "p") { m.DisplayNotification("Point defined."); CameraPoint point = new CameraPoint(); point.positionGlX = m.GetLocalPositionX(); point.positionGlY = m.GetLocalPositionY(); point.positionGlZ = m.GetLocalPositionZ(); point.orientationGlX = m.GetLocalOrientationX(); point.orientationGlY = m.GetLocalOrientationY(); point.orientationGlZ = m.GetLocalOrientationZ(); cameraPoints[cameraPointsCount++] = point; } if (arguments[0] == "start" || arguments[0] == "play" || arguments[0] == "rec") { if (!m.IsFreemoveAllowed()) { m.DisplayNotification("Free move not allowed."); return(true); } if (cameraPointsCount == 0) { m.DisplayNotification("No points defined. Enter points with \".cam p\" command."); return(true); } playingSpeed = 1; float totalRecTime = -1; if (arguments[0] == "rec") { if (argumentsLength.value >= 3) { // video time totalRecTime = p.FloatParse(arguments[2]); } avi = m.AviWriterCreate(); avi.Open(p.StringFormat("{0}.avi", p.Timestamp()), framerate, m.GetWindowWidth(), m.GetWindowHeight()); } if (argumentsLength.value >= 2) { // play time float totalTime = p.FloatParse(arguments[1]); playingSpeed = TotalDistance() / totalTime; if (totalRecTime == -1) { recspeed = 10; } else { recspeed = totalTime / totalRecTime; } } playingTime = 0; firstFrameDone = false; previousPositionX = m.GetLocalPositionX(); previousPositionY = m.GetLocalPositionY(); previousPositionZ = m.GetLocalPositionZ(); previousOrientationX = m.GetLocalOrientationX(); previousOrientationY = m.GetLocalOrientationY(); previousOrientationZ = m.GetLocalOrientationZ(); m.ShowGui(0); previousFreemove = m.GetFreemove(); m.SetFreemove(FreemoveLevelEnum.Noclip); m.EnableCameraControl(false); } if (arguments[0] == "stop") { m.DisplayNotification("Camera stopped."); Stop(); } if (arguments[0] == "clear") { m.DisplayNotification("Camera points cleared."); cameraPointsCount = 0; Stop(); } if (arguments[0] == "save") { string s = "1,"; for (int i = 0; i < cameraPointsCount; i++) { CameraPoint point = cameraPoints[i]; s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlX * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlY * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlZ * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlX * 1000))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlY * 1000))); s = p.StringFormat2("{0}{1}", s, p.IntToString(p.FloatToInt(point.orientationGlZ * 1000))); if (i != cameraPointsCount - 1) { s = p.StringFormat("{0},", s); } } p.ClipboardSetText(s); m.DisplayNotification("Camera points copied to clipboard."); } if (arguments[0] == "load") { IntRef pointsLength = new IntRef(); string[] points = p.StringSplit(arguments[1], ",", pointsLength); int n = (pointsLength.value - 1) / 6; cameraPointsCount = 0; for (int i = 0; i < n; i++) { CameraPoint point = new CameraPoint(); point.positionGlX = one * p.IntParse(points[1 + i * 6 + 0]) / 100; point.positionGlY = one * p.IntParse(points[1 + i * 6 + 1]) / 100; point.positionGlZ = one * p.IntParse(points[1 + i * 6 + 2]) / 100; point.orientationGlX = one * p.IntParse(points[1 + i * 6 + 3]) / 1000; point.orientationGlY = one * p.IntParse(points[1 + i * 6 + 4]) / 1000; point.orientationGlZ = one * p.IntParse(points[1 + i * 6 + 5]) / 1000; cameraPoints[cameraPointsCount++] = point; } m.DisplayNotification(p.StringFormat("Camera points loaded: {0}", p.IntToString(n))); } return(true); } return(false); }
public Vector3 GetCorner(CameraPoint corner) { return(GetCorner(corner, 1)); }
/// <summary> /// Initialises a new instance of the <see cref="InterpolatorBase" /> class. /// </summary> /// <param name="point">The builder to use for intermediary steps.</param> protected InterpolatorBase(CameraPoint point) { Point = point; }
public void switchFocusPoint(CameraPoint newPoint) { StopCoroutine("moveCameraFocus"); StartCoroutine("moveCameraFocus", newPoint); }
void Awake() { Instance = this; }
IEnumerator moveCameraFocus(CameraPoint newPoint) { _maxDistance = Mathf.Max(newPoint.maxDistance,_maxDistance); _minDistance = Mathf.Min(newPoint.minDistance, _minDistance); _highAngle = Mathf.Max(newPoint.maxAngle, _highAngle); _lowAngle = Mathf.Min(newPoint.minAngle, _lowAngle); Vector3 oldFocus = _focusPosition; Vector3 newFocus = newPoint.gameObject.transform.position; float oldDistance = _distance; float oldAngle = _y; Quaternion oldHeading = transform.rotation; oldHeading.eulerAngles = new Vector3(0f, oldHeading.eulerAngles.y,0f); float startTime = Time.time; float travelTime = (newFocus-_focusPosition).magnitude / 10f; if (travelTime > 0.1f){ float factor; while(Time.time <= startTime + travelTime){ factor = (Time.time - startTime)/travelTime; _focusPosition = Vector3.Lerp(oldFocus, newFocus, Mathf.SmoothStep(0f, 1f, factor)); _x = Quaternion.Slerp(oldHeading, newPoint.gameObject.transform.rotation, Mathf.SmoothStep(0f, 1f, factor)).eulerAngles.y; _y = Mathf.Lerp(oldAngle, newPoint.startAngle, Mathf.SmoothStep(0f, 1f, factor)); _distance = Mathf.Lerp(oldDistance, newPoint.startDistance, Mathf.SmoothStep(0f, 1f, factor)); yield return null; } _focusPosition = newFocus; _maxDistance = newPoint.maxDistance; _minDistance = newPoint.minDistance; _highAngle = newPoint.maxAngle; _lowAngle = newPoint.minAngle; } }