/// <summary>
        /// Applies the properties of this VirtualTransform to the given VirtualTransform.
        /// Scale isn't applied unless set to true.
        /// </summary>
        /// <param name="virtualTransform">VirtualTransform you want to apply this VirtualTransform's properties to.</param>
        /// <param name="applyScale">If you also want to apply scale.</param>
        public void ApplyTo(VirtualTransform virtualTransform, bool applyScale = false)
        {
            virtualTransform.Position = this.Position;
            virtualTransform.Rotation = this.Rotation;

            if (applyScale)
            {
                virtualTransform.LocalScale = this.LocalScale;
            }
        }
Example #2
0
        /// <summary>
        /// Switches the active camera to the given index.
        /// </summary>
        /// <param name="index">Index in the list of cameras.</param>
        /// <param name="copyComponents">Whether or not components fields will be copied from the current camera to the next.</param>
        public void SwitchCamera(int index, bool copyComponents = false)
        {
            if (index < 0 || index > CameraControllers.Count - 1)
            {
                throw new ArgumentOutOfRangeException("The index: " + index + " is not a valid index for a Camera.");
            }

            Typo.Utilities.Cameras.CameraController previousCameraController = CameraControllers[_currentCameraIndex];

            // Setup out new index, and the position we left off of
            _switchTransform    = new VirtualTransform(CameraTransform);
            _currentCameraIndex = index;
            _switchBeginTime    = Time.time;

            // Copy the fields before we initialize
            if (copyComponents)
            {
                CameraControllers[_currentCameraIndex].CopyPublicFields(previousCameraController);
            }

            // We want the camera to initialize, but we don't want it actually updating. Enabling and disabling will do that.
            Debug.Log(CameraControllers[_currentCameraIndex].gameObject.name);
            CameraControllers[_currentCameraIndex].enabled = true;
            CameraControllers[_currentCameraIndex].enabled = false;

            // Setting up the speed after the new camera has been initialized so that we have the correct position for measurements.
            // If we're at 0 or less, then set our position to the new camera's position immediately.
            if (SwitchSpeed <= 0)
            {
                // Snap if equal or less than 0
                _switchSpeed = float.MaxValue;
                CameraControllers[_currentCameraIndex].CameraTransform.ApplyTo(CameraTransform);
            }
            // Otherwise, we set up the speed.
            else
            {
                _switchSpeed = SwitchSpeed;
                if (ConstantSwitchSpeedInit)
                {
                    _switchSpeed = Vector3.Distance(_switchTransform.Position, CameraControllers[_currentCameraIndex].CameraTransform.Position) / SwitchSpeed;
                }
            }
        }
Example #3
0
        public override void UpdateCamera()
        {
            // This was a public variable can switch the camera.
            if (CurrentIndex != _currentCameraIndex)
            {
                SwitchCamera(CurrentIndex);
            }
            Typo.Utilities.Cameras.CameraController cam = CameraControllers[_currentCameraIndex];

            cam.UpdateCamera();

            // Lerping, we have to calculate between positions.
            if (Time.time - _switchBeginTime < _switchSpeed)
            {
                float t  = (Time.time - _switchBeginTime) / _switchSpeed;
                float pt = PositionLerpTransformer.Process(t);
                float rt = RotationLerpTransformer.Process(t);

                var lerpVirtualTransform = new VirtualTransform();

                // Lerp position
                lerpVirtualTransform.Position = Vector3.Lerp(_switchTransform.Position, cam.CameraTransform.Position, pt);

                // Lerp rotation
                lerpVirtualTransform.Rotation = SwitchSlerpRotation ?
                                                Quaternion.Slerp(_switchTransform.Rotation, cam.CameraTransform.Rotation, rt) :
                                                Quaternion.Lerp(_switchTransform.Rotation, cam.CameraTransform.Rotation, rt);

                lerpVirtualTransform.ApplyTo(CameraTransform);
            }
            // Not Lerping, we just set the position.
            else
            {
                cam.CameraTransform.ApplyTo(CameraTransform);
            }
        }
        /// <summary>
        /// If you override the Awake method, be sure to call the base.Awake() in the new awake method.
        /// </summary>
        protected virtual void Awake()
        {
            IsInitialized = false;

            if (Camera != null)
            {
                CameraTransform = new VirtualTransform();
            }
            else
            {
                throw new MissingMemberException("The Camera was not set on this CameraController. Please add a Camera reference to this CameraController.");
            }

            if (!ComponentsAdded)
            {
                _components = new Dictionary <Type, CameraComponent>();

                AddCameraComponents();

                ComponentsAdded = true;
            }

            InitializeComponents();
        }
 /// <summary>
 /// Finds the local rotation of this VirtualTransform using the given parent VirtualTransform rotation.
 /// </summary>
 /// <param name="parentTransform">Transform of the parent.</param>
 /// <returns>Local rotation of this VirtualTransform relative to the parent rotation.</returns>
 public Quaternion GetLocalRotation(VirtualTransform parentTransform)
 {
     return(GetLocalRotation(parentTransform.Rotation));
 }
 /// <summary>
 /// Finds the local position of this VirtualTransform using the given parent VirtualTransform's position.
 /// </summary>
 /// <param name="parentTransform">The VirtualTransform of the parent.</param>
 /// <returns>The local position relative to the given parent position.</returns>
 public Vector3 GetLocalPosition(VirtualTransform parentTransform)
 {
     return(GetLocalPosition(parentTransform.Position));
 }
 /// <summary>
 /// Rotates the VirtualTransform to look at the position of the given VirtualTransform.
 /// </summary>
 /// <param name="virtualTransform">The VirtualTransform whose position in world space to look at.</param>
 /// <param name="worldUp">Upwards vector.</param>
 public void LookAt(VirtualTransform virtualTransform, Vector3 worldUp)
 {
     LookAt(virtualTransform.Position, worldUp);
 }
 /// <summary>
 /// Rotates the VirtualTransform to look at the position of the given VirtualTransform.
 /// Uses Vector3.up as the worldUp vector.
 /// </summary>
 /// <param name="virtualTransform">The VirtualTransform whose position in world space to look at.</param>
 public void LookAt(VirtualTransform virtualTransform)
 {
     LookAt(virtualTransform.Position, Vector3.up);
 }
 /// <summary>
 /// Rotates around the position of the VirtualTransform by the given amount of degrees on the Vector3.Up axis.
 /// </summary>
 /// <param name="virtualTransform">VirtualTransform whose position to rotate around.</param>
 /// <param name="angle">Degrees.</param>
 /// <param name="axis">Axis to rotate on.</param>
 public void RotateAround(VirtualTransform virtualTransform, float angle, Vector3 axis)
 {
     RotateAround(virtualTransform, angle, axis);
 }
 /// <summary>
 /// Applies the position, rotation, and localScale properties of the VirtualTransform to this VirtualTransform.
 /// </summary>
 /// <param name="virtualTransform">The VirtualTransform whose properties you want to apply to this VirtualTransform.</param>
 public void Apply(VirtualTransform virtualTransform)
 {
     this.Position   = virtualTransform.Position;
     this.Rotation   = virtualTransform.Rotation;
     this.LocalScale = virtualTransform.LocalScale;
 }
 /// <summary>
 /// Constructs a VirtualTransform setting the position, rotation, and local scale to the values of the given VirtualTransform.
 /// </summary>
 /// <param name="virtualTransform">VirtualTransform whose properties you want to copy.</param>
 public VirtualTransform(VirtualTransform virtualTransform)
 {
     Position   = virtualTransform.Position;
     Rotation   = virtualTransform.Rotation;
     LocalScale = virtualTransform.LocalScale;
 }