Example #1
0
 public void AddTarget(ICameraTarget cameraTarget)
 {
     if (!targets.Contains(cameraTarget))
     {
         targets.Add(cameraTarget);
     }
 }
        public ThirdPersonCamera(ICameraTarget target)
        {
            this.target = target;

            // Initialize values for the projection matrix
            fieldOfView = (float)Math.PI / 4.0f;

            nearDistance = 0.5f;
            farDistance = 100000.0f;

            updateProjectionMatrix();

            // Initialize values for the viewing matrix
            minZoom = 1.0f;
            maxZoom = 5000.0f;

            zoom = 100.0f;

            rotationXZ = 0.0f;

            minRotationY = -(float)Math.PI / 2.0f + 0.1f;
            maxRotationY = +(float)Math.PI / 2.0f - 0.1f;
            rotationY = -(float)Math.PI / 4.0f;

            updateViewMatrix();
        }
Example #3
0
 public void RemoveTarget(ICameraTarget cameraTarget)
 {
     if (targets.Contains(cameraTarget))
     {
         targets.Remove(cameraTarget);
     }
 }
Example #4
0
 public FixedCamera(Vector3 pos, ICameraTarget lookAtObject, float aspectRatio, float fov, float near, float far)
 {
     LookAtTarget = lookAtObject;
     AspectRatio  = aspectRatio;
     FieldOfView  = fov;
     NearPlane    = near;
     FarPlane     = far;
     Position     = pos;
 }
Example #5
0
        public void Init(ICameraTarget startingPoint)
        {
            var arrowTransform = transform;

            arrowTransform.SetParent(startingPoint.Follow);

            arrowTransform.localPosition = new Vector3(0, 4, 5);
            arrowTransform.rotation      = Quaternion.identity;
        }
 public FixedCamera(Vector3 pos, ICameraTarget lookAtObject, float aspectRatio, float fov, float near, float far)
 {
     LookAtTarget = lookAtObject;
     AspectRatio = aspectRatio;
     FieldOfView = fov;
     NearPlane = near;
     FarPlane = far;
     Position = pos;
 }
Example #7
0
    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible   = false;

        rigTrans        = transform.GetChild(0);
        mainCameraTrans = Camera.main.transform;
        if (followTargetTrans != null)
        {
            ICameraTarget target = followTargetTrans.GetComponent <ICameraTarget>();
            if (target != null)
            {
                target.cameraRoot = this;
            }
        }
        if (lookAtTargetTrans != null && useLookAt)
        {
            OnLookAt(lookAtTargetTrans);
        }
    }
		public void SetTarget(GameObject target)
		{
			if (!Equals(cameraTarget, null))
				cameraTarget.OnLostCameraFocus(this);

			if (target)
			{
				this.target = target.transform;
				cameraTarget = target.GetComponent<ICameraTarget>();

				if (!Equals(cameraTarget, null))
					cameraTarget.OnGainedCameraFocus(this);
			}
			else
			{
				this.target = null;
				cameraTarget = null;
			}

			onTargetChanged(this.target);
		}
        public CockpitCamera(ICameraTarget vehicle, Vector3 cameraOffset, int screenX, int screenY)
            : base(vehicle.Position + cameraOffset)
        {
            Speed     = 5f;
            TurnSpeed = 10f;

            LookAtTarget = vehicle;

            _cameraOffset = cameraOffset;
            _screenWidth  = screenX;
            _screenHeight = screenY;

            // Point it in the positive Z direction
            _relativeLookAtBase = Vector3.Backward;

            _yawAngle += MathHelper.ToRadians(180);

            LookAt = _relativeLookAtBase + Position;

#if !XBOX
            _tracker = new Tracker();
#endif
        }
        public CockpitCamera(ICameraTarget vehicle, Vector3 cameraOffset, int screenX, int screenY)
            : base(vehicle.Position + cameraOffset)
        {
            Speed = 5f;
            TurnSpeed = 10f;

            LookAtTarget = vehicle;

            _cameraOffset = cameraOffset;
            _screenWidth = screenX;
            _screenHeight = screenY;

            // Point it in the positive Z direction
            _relativeLookAtBase = Vector3.Backward;

            _yawAngle += MathHelper.ToRadians(180);

            LookAt = _relativeLookAtBase + Position;

            #if !XBOX
            _tracker = new Tracker();
            #endif
        }
Example #11
0
 public void AddTarget(ICameraTarget target)
 {
     _targets.Add(target);
     _targetTransition = true;
 }
Example #12
0
 public void RemoveTarget(ICameraTarget target)
 {
     _targets.Remove(target);
     _targetTransition = true;
 }
 public ChaseCamera(ICameraTarget target)
 {
     LookAtTarget = target;
 }
        private void InitCamera(CameraType type, Vector3 cameraPos, ICameraTarget target)
        {
            Components.Remove(_cockpitMesh);

            #region Handle different implementations

            if (type == CameraType.Fixed)
            {
                Camera = new FixedCamera
                             {
                                 FieldOfView = MathHelper.ToRadians(45),
                                 Position = cameraPos,
                             };
            }
            else if (type == CameraType.Chase)
            {
                Camera = new ChaseCamera
                             {
                                 DesiredPositionOffset = new Vector3(0.0f, 0.5f, 3.5f),
                                 LookAtOffset = new Vector3(0.0f, 0.0f, 0.0f),
                                 Damping = 600,
                                 Stiffness = 3000,
                                 IsElastic = true,
                                 FieldOfView = MathHelper.ToRadians(45),
                                 Position = cameraPos,
                             };
            }
            else if (type == CameraType.Free)
            {
                Camera = new FreeCamera(cameraPos, _screenWidth, _screenHeight)
                             {
                                 FieldOfView = MathHelper.ToRadians(45),
                                 Position = cameraPos,
                             };
            }
            else if (type == CameraType.Cockpit)
            {
                var offset = new Vector3(0, -0.1f, 0);
                Camera = new CockpitCamera(target, offset, _screenWidth, _screenHeight)
                             {
                                 FieldOfView = MathHelper.ToRadians(120),
                                 CockpitMesh = _cockpitMesh,
                             };
                Components.Add(_cockpitMesh);
            }
            else
                throw new NotImplementedException("Unknown camera type");

            #endregion


            if (target == null)
                Camera.LookAtTarget = new WorldDummy(Vector3.Zero);
            else
                Camera.LookAtTarget = target;


            Camera.NearPlane = 0.1f;
            Camera.FarPlane = 10000;
            Camera.AspectRatio = (float) _graphics.GraphicsDevice.Viewport.Width/
                                 _graphics.GraphicsDevice.Viewport.Height;
            Camera.Reset();
        }
Example #15
0
 public void SetFollowTarget(ICameraTarget checkpoint)
 {
     _followCheckpoint = checkpoint;
 }
 public ChaseCamera(ICameraTarget target)
 {
     LookAtTarget = target;
 }