public CameraAttitude Update() { var time = Time.unscaledTime - _lastChangedTime; if (time > _interval) { _lastChangedTime = Time.unscaledTime; if (!_creatures.Any()) { return(_lastCameraAttitude); } _currentIndex++; if (_currentIndex >= _creatures.Count) { _currentIndex = 0; } var creature = _creatures[_currentIndex]; var transform = creature.transform.GetChild(0).transform; _camera = new FocusCamera(transform, transitionTime: TransitionTime, initialDistance: InitialDistance, farAwayDistance: FarAwayDistance); _camera.Initialize(_lastCameraAttitude); } _lastCameraAttitude = _camera.Update(Time.unscaledDeltaTime); return(_lastCameraAttitude); }
private CameraAttitude FollowImmediately(CameraAttitude attitude, float distance) { _tempPolarAttitude.SetFromAttitude(attitude); _tempPolarAttitude.Distance = distance; _tempPolarAttitude.Rotate(Vector2.zero); return(_tempPolarAttitude.ToCameraAttitude()); }
public CameraAttitude Update(float deltaTime) { _elapsedTime += deltaTime; var t = Math.Abs(_transitionTime) < 0.01f ? 1.0f : Mathf.Clamp01(_elapsedTime / _transitionTime); _currentAttitude = CameraAttitude.Slerp(_currentAttitude, _targetAttitude, t); return(_currentAttitude); }
public void SetFromAttitude(CameraAttitude attitude) { var dir = attitude.Position - attitude.LookAt; Theta = Mathf.Atan2(dir.z, dir.x); Phi = Mathf.Atan2(dir.y, Mathf.Sqrt(dir.x * dir.x + dir.z * dir.z)); Distance = dir.magnitude; LookAt = attitude.LookAt; }
private CameraAttitude Follow(CameraAttitude attitude, float targetDistance, float transitionTime, float elapsedTime) { _tempPolarAttitude.SetFromAttitude(attitude); var t = Math.Abs(transitionTime) < 0.01f ? 1.0f : Mathf.Clamp01(elapsedTime / transitionTime); _tempPolarAttitude.Distance = Mathf.Lerp(_tempPolarAttitude.Distance, targetDistance, t); _tempPolarAttitude.Rotate(Vector2.zero); return(_tempPolarAttitude.ToCameraAttitude()); }
public AgentFocusStrategy(int interval = 5) { _interval = interval; _creatures = new List <Agent>(); _lastCameraAttitude = new CameraAttitude { LookAt = new Vector3(-1f, 0, -10f), Position = new Vector3(0.0f, 10.0f, -40.0f), }; // 最初は対象がいないので定点を見ておく _camera = new MonitoringCamera(_lastCameraAttitude); }
private CameraAttitude LookAtLate(CameraAttitude attitude, Vector3 focus) { var nowV = attitude.LookAt - attitude.Position; var goalV = focus - attitude.Position; var angle = Vector3.Angle(nowV, goalV); var t = Mathf.Clamp((_maxDamper - _minDamper) * (angle - _inSightAngle) / (_outSightAngle - _inSightAngle) + _minDamper, _minDamper, _maxDamper); attitude.LookAt = Vector3.Lerp(attitude.LookAt, focus, t); return(attitude); }
void Start() { if (target != null) { ChangeAttitude(defaultPresetID); softHorDis = current.distance; softAngle = current.angle; softHorBiaPercent = current.horBiaPercent; switchFrom = new CameraAttitude(softHorDis, softAngle, softHorBiaPercent); SetCamDegreeFromCamOriPos(); } }
CameraAttitude IOperatableCamera.Update(float deltaTime) { var focus = _focusTarget != null ? _focusTarget.position : _goalAttitude.LookAt; _elapsedTime += deltaTime; if (_elapsedTime < _transitionTime && Vector3.Distance(_currentAttitude.Position, focus) > _farAwayDistance) { _goalAttitude = LookAtImmediately(_goalAttitude, focus); _goalAttitude = FollowImmediately(_goalAttitude, _farAwayDistance - 1.0f); } else { _goalAttitude = LookAtLate(_goalAttitude, focus); _goalAttitude = Follow(_goalAttitude, _targetDistance, _transitionTime, _elapsedTime); } _currentAttitude = CameraAttitude.Slerp(_currentAttitude, _goalAttitude, 0.99f); return(_currentAttitude); }
private void Init(Camera target, ReactiveProperty <GameObject> selectedCreature, IObservable <Tuple <FallbackedEventReceiver.FallbackedEvents, PointerEventData> > eventObservable, CameraAttitude?defaultAttitude = null) { _selectedCreatureExtrenalProperty = selectedCreature; _target = target; _defaultAttitude = defaultAttitude ?? new CameraAttitude { LookAt = Vector3.zero, Position = new Vector3(0.0f, 10.0f, -40.0f), }; eventObservable .Where(x => x.Item1 == FallbackedEventReceiver.FallbackedEvents.Dragging) .Select(x => x.Item2) .Where(x => x.button == PointerEventData.InputButton.Left) .Select(x => x.delta) .Subscribe(LeftDragOperation) .AddTo(this); eventObservable .Where(x => x.Item1 == FallbackedEventReceiver.FallbackedEvents.Dragging) .Select(x => x.Item2) .Where(x => x.button == PointerEventData.InputButton.Right) .Select(x => x.delta) .Subscribe(RightDragOperation) .AddTo(this); eventObservable .Where(x => x.Item1 == FallbackedEventReceiver.FallbackedEvents.Scroll) .Select(x => x.Item2.scrollDelta) .Subscribe(ScrollOperation) .AddTo(this); selectedCreature .Subscribe(SelectOperation) .AddTo(this); }
public PolarCoordinatesAttitude(CameraAttitude attitude) { SetFromAttitude(attitude); }
void IOperatableCamera.Initialize(CameraAttitude attitude) { _currentAttitude = attitude; _goalAttitude = new PolarCoordinatesAttitude(_currentAttitude); }
private void Rotate(Vector2 diff) { _tempPolarAttitude.SetFromAttitude(_goalAttitude); _tempPolarAttitude.Rotate(diff); _goalAttitude = _tempPolarAttitude.ToCameraAttitude(); }
void IOperatableCamera.Initialize(CameraAttitude attitude) { _currentAttitude = attitude; _goalAttitude = attitude; }
void ChangeAttitude(int index) { if (0 <= index && index < presets.Length - 1) { currentAttitudeID = index; switchT = 0; IsSwitchingAttitude = true; switchFrom = new CameraAttitude(softHorDis, softAngle, softHorBiaPercent); } }
public MonitoringCamera(CameraAttitude targetAttitude, float transitionTime = 1.0f) { _targetAttitude = targetAttitude; _transitionTime = transitionTime; }
private CameraAttitude LookAtImmediately(CameraAttitude attitude, Vector3 focus) { attitude.LookAt = focus; return(attitude); }
void IOperatableCamera.Initialize(CameraAttitude attitude) { _currentAttitude = attitude; _elapsedTime = 0.0f; }
CameraAttitude IOperatableCamera.Update(float deltaTime) { _currentAttitude = CameraAttitude.Lerp(_currentAttitude, _goalAttitude.ToCameraAttitude(), 0.98f); return(_currentAttitude); }