Beispiel #1
0
        //--------------------------------------
        //  Methods
        //--------------------------------------

        //	PUBLIC

        /// <summary>
        /// Start this instance.
        /// </summary>
        void Start()
        {
            //DEFAULT
            _currentCameraTrackingPriority = TrackingPriority.Low;

            //
            _trackableObjectComponents_list   = new List <TrackableObjectComponent>();
            TrackingCameraComponent._instance = this;


            //X
            float xPositionTemporaryTarget_float = 20;

            _xPosition_lerptarget = new LerpTarget(transform.position.x, xPositionTemporaryTarget_float, _xPositionMin_float, _xPositionMax_float, _xPositionAcceleration_float);

            //
            //Y
            float yPositionTemporaryTarget_float = 20;

            _yPosition_lerptarget = new LerpTarget(transform.position.y, yPositionTemporaryTarget_float, _yPositionMin_float, _yPositionMax_float, _yPositionAcceleration_float);

            //Z
            //NOTE: WE USE NEGATIVES BECAUSE THE 'DISTANCE' IS IN THE NEGATIVE QUADRANT (OF CARTESIAN COORDS)
            //NOTE, WE REVERSE MIN/MAX HERE BY DESIGN BECAUSE OF NEGATIVE VALUES
            _zPosition_lerptarget = new LerpTarget(transform.position.z, -_distanceDefault_float, -_distanceMax_float, -_distanceMin_float, _zPositionAcceleration_float);
        }
Beispiel #2
0
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        //\ 
        //\ MOVEMENT
        //\ 
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

        /// <summary>
        /// Dolly the Camera (Move in Z axis)
        /// </summary>
        private void _doDollyCamera()
        {
            Rect viewport_rect = _getViewportRect(_zPlaneCoordinate_float);
            Rect highAndLowTrackableObjects_rect = _getRectForAllTrackableObjects(TrackingPriority.Low);
            bool areAllHighAndLowTrackableObjectsInView_boolean = RectHelper.IsRectWithinRect(viewport_rect, highAndLowTrackableObjects_rect);
            //
            Rect currentTarget_rect = _getRectForAllTrackableObjects(_currentCameraTrackingPriority);
            bool isCurrentTargetRectWithinBoundary_boolean = RectHelper.IsRectWithinRect(_viewportBoundary_rect, currentTarget_rect);



            //
            //********************************
            //1. IF WE CAN SEE LOW+HIGH THEN ALWAYS ZOOM IN MORE
            //********************************
            if (areAllHighAndLowTrackableObjectsInView_boolean)
            {
                _doUpdateZPositionTargetValue(isCurrentTargetRectWithinBoundary_boolean, areAllHighAndLowTrackableObjectsInView_boolean, 0.05f);
                if (_currentCameraTrackingPriority == TrackingPriority.High)
                {
                    _currentCameraTrackingPriority = TrackingPriority.Low;
                }
            }
            else
            {
                //********************************
                //2. IF WE CAN'T SEE LOW+HIGH AND CANNOT ZOOM OUT MORE, THEN CHANGE FOCUS
                //TO JUST THE HIGH PRIORITY OBJECTS
                //********************************
                if (_zPosition_lerptarget.targetValue == _zPosition_lerptarget.minimum)
                {
                    if (_currentCameraTrackingPriority == TrackingPriority.Low)
                    {
                        _currentCameraTrackingPriority = TrackingPriority.High;
                    }
                }
                _doUpdateZPositionTargetValue(isCurrentTargetRectWithinBoundary_boolean, areAllHighAndLowTrackableObjectsInView_boolean, -0.05f);
            }

            //UPDATE POSITION
            _zPosition_lerptarget.lerpCurrentToTarget(1);
            transform.position = new Vector3(transform.position.x, transform.position.y, _zPosition_lerptarget.targetValue);
        }
Beispiel #3
0
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        //\ 
        //\ OTHER
        //\ 
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

        /// <summary>
        /// _gets the rect for all trackable objects.
        ///
        /// NOTE:   POSSIBLE OPTIMIZATION --STORE THIS RECT AND ONLY
        ///         UPDATE UPON CHANGES TO _trackableObjectComponents_list
        ///
        ///
        /// NOTE:   WHEN _trackableObjectComponents_list.Count == 0, THE CAMERA
        ///         WILL LOOK AT 0,0 BECAUSE OF ' new Rect();' and that is acceptable
        ///
        ///
        /// </summary>
        /// <returns>The rect for all trackable objects.</returns>
        private Rect _getRectForAllTrackableObjects(TrackingPriority aMinimumPriority)
        {
            //
            Bounds allTrackableObjects_bounds;
            Rect   allTrackableObjects_rect = new Rect();

            //********************************
            //MAKE A FILTERED LIST (ASSUME PRIORITY = NONE BY DEFAULT)
            //********************************
            List <TrackableObjectComponent> _prioritizedTrackableObjectComponents_list = _trackableObjectComponents_list;

            switch (aMinimumPriority)
            {
            case TrackingPriority.Low:
                _prioritizedTrackableObjectComponents_list = (List <TrackableObjectComponent>)_trackableObjectComponents_list.Where(
                    trackableObjectComponent => trackableObjectComponent.trackingPriority == TrackingPriority.Low || trackableObjectComponent.trackingPriority == TrackingPriority.High).ToList();
                break;

            case TrackingPriority.High:
                _prioritizedTrackableObjectComponents_list = (List <TrackableObjectComponent>)_trackableObjectComponents_list.Where(
                    trackableObjectComponent => trackableObjectComponent.trackingPriority == aMinimumPriority).ToList();
                break;
            }

            //********************************
            //CREATE A BOUNDS THAT ENCAPSULATES ALL OBJECTS OF INTEREST
            //********************************
            if (_prioritizedTrackableObjectComponents_list.Count > 0)
            {
                //ENCAPSULATE NEEDS US TO START WITH A NON-'EMPTY' INSTANCE
                allTrackableObjects_bounds = _prioritizedTrackableObjectComponents_list[0].getBoundsWithProjection(camera);
                //
                foreach (TrackableObjectComponent trackableObjectComponent in _prioritizedTrackableObjectComponents_list)
                {
                    allTrackableObjects_bounds.Encapsulate(trackableObjectComponent.getBoundsWithProjection(camera));
                }
                allTrackableObjects_rect = RectHelper.ConvertBoundsToRect(allTrackableObjects_bounds, _zPlaneCoordinate_float);
            }

            //
            return(RectHelper.Expand(allTrackableObjects_rect, _borderPadding_float));
        }
        //--------------------------------------
        //  Methods
        //--------------------------------------
        /// <summary>
        /// Gets the debug color by priority.
        /// </summary>
        /// <returns>The debug color by priority.</returns>
        /// <param name="aTrackingPriority">A tracking priority.</param>
        public static Color GetDebugColorByPriority(TrackingPriority aTrackingPriority)
        {
            Color color = _DEBUG_COLOR_FOR_PRIORITY_NONE;

            switch (aTrackingPriority)
            {
            case TrackingPriority.None:
                color = _DEBUG_COLOR_FOR_PRIORITY_NONE;
                break;

            case TrackingPriority.Low:
                color = _DEBUG_COLOR_FOR_PRIORITY_LOW;
                break;

            case TrackingPriority.High:
                color = _DEBUG_COLOR_FOR_PRIORITY_HIGH;
                break;
            }

            return(color);
        }
Beispiel #5
0
 /// <summary>
 /// _dos the draw line between crosshairs.
 /// </summary>
 /// <param name="aTrackingPriority1">A tracking priority1.</param>
 /// <param name="aTrackingPriority2">A tracking priority2.</param>
 private void _doDrawLineBetweenCrosshairs(TrackingPriority aTrackingPriority1, TrackingPriority aTrackingPriority2)
 {
     DebugDraw.DrawLineBetweenCrosshairs(_getRectForAllTrackableObjects(aTrackingPriority1), _getRectForAllTrackableObjects(aTrackingPriority2), _zPlaneCoordinate_float, Constants.DEBUG_COLOR_VIEWPORT_CENTERPOINT);
 }
Beispiel #6
0
 /// <summary>
 /// Draw center point crosshairs for rect of all trackable objects.
 /// </summary>
 private void _doDrawCenterPointCrosshairsForRectOfAllTrackableObjects(TrackingPriority aTrackingPriority)
 {
     DebugDraw.DrawCenterPointCrosshairsForRect(_getRectForAllTrackableObjects(aTrackingPriority), _zPlaneCoordinate_float, Constants.GetDebugColorByPriority(aTrackingPriority));
 }
Beispiel #7
0
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        //\ 
        //\ DRAWING
        //\ 
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


        /// <summary>
        /// Draw one rect for all trackable objects.
        ///
        /// NOTE: WE LOOP THROUGH OBJECTS OF INTEREST AND DRAW A RECT AROUND ALL
        ///
        /// </summary>
        private void _doDrawOneRectForAllTrackableObjects(TrackingPriority aTrackingPriority)
        {
            DebugDraw.DrawRect(_getRectForAllTrackableObjects(aTrackingPriority), _zPlaneCoordinate_float, Constants.GetDebugColorByPriority(aTrackingPriority));
        }
Beispiel #8
0
		//--------------------------------------
		//  Methods
		//--------------------------------------
		/// <summary>
		/// Gets the debug color by priority.
		/// </summary>
		/// <returns>The debug color by priority.</returns>
		/// <param name="aTrackingPriority">A tracking priority.</param>
		public static Color GetDebugColorByPriority (TrackingPriority aTrackingPriority)
		{
			Color color = _DEBUG_COLOR_FOR_PRIORITY_NONE;

			switch (aTrackingPriority) {
			case TrackingPriority.None:
					color = _DEBUG_COLOR_FOR_PRIORITY_NONE;
					break;
				case TrackingPriority.Low:
					color = _DEBUG_COLOR_FOR_PRIORITY_LOW;
					break;
				case TrackingPriority.High:
					color = _DEBUG_COLOR_FOR_PRIORITY_HIGH;
					break;
			}

			return color;
		}
		//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
		//\ 
		//\ OTHER
		//\ 
		//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

		/// <summary>
		/// _gets the rect for all trackable objects.
		/// 
		/// NOTE: 	POSSIBLE OPTIMIZATION --STORE THIS RECT AND ONLY 
		/// 		UPDATE UPON CHANGES TO _trackableObjectComponents_list
		/// 
		/// 
		/// NOTE:   WHEN _trackableObjectComponents_list.Count == 0, THE CAMERA
		/// 		WILL LOOK AT 0,0 BECAUSE OF ' new Rect();' and that is acceptable
		/// 
		/// 
		/// </summary>
		/// <returns>The rect for all trackable objects.</returns>
		private Rect _getRectForAllTrackableObjects (TrackingPriority aMinimumPriority)
		{
			//
			Bounds allTrackableObjects_bounds;
			Rect allTrackableObjects_rect = new Rect();

			//********************************
			//MAKE A FILTERED LIST (ASSUME PRIORITY = NONE BY DEFAULT)
			//********************************
			List<TrackableObjectComponent> _prioritizedTrackableObjectComponents_list  = _trackableObjectComponents_list ;

			switch (aMinimumPriority) {
			case TrackingPriority.Low:
				_prioritizedTrackableObjectComponents_list  =	(List<TrackableObjectComponent>)_trackableObjectComponents_list.Where (
					trackableObjectComponent => trackableObjectComponent.trackingPriority == TrackingPriority.Low || trackableObjectComponent.trackingPriority == TrackingPriority.High).ToList();
				break;
			case TrackingPriority.High:
					_prioritizedTrackableObjectComponents_list  =	(List<TrackableObjectComponent>)_trackableObjectComponents_list.Where (
						trackableObjectComponent => trackableObjectComponent.trackingPriority == aMinimumPriority).ToList();
				break;
			}

			//********************************
			//CREATE A BOUNDS THAT ENCAPSULATES ALL OBJECTS OF INTEREST
			//********************************
			if (_prioritizedTrackableObjectComponents_list.Count > 0) {

				//ENCAPSULATE NEEDS US TO START WITH A NON-'EMPTY' INSTANCE
				allTrackableObjects_bounds = _prioritizedTrackableObjectComponents_list[0].getBoundsWithProjection(camera);
				//
				foreach (TrackableObjectComponent trackableObjectComponent in _prioritizedTrackableObjectComponents_list) {

					allTrackableObjects_bounds.Encapsulate (trackableObjectComponent.getBoundsWithProjection(camera));
				}
				allTrackableObjects_rect = RectHelper.ConvertBoundsToRect (allTrackableObjects_bounds, _zPlaneCoordinate_float);
			} 

			//
			return RectHelper.Expand (allTrackableObjects_rect, _borderPadding_float );
		}
		/// <summary>
		/// _dos the draw line between crosshairs.
		/// </summary>
		/// <param name="aTrackingPriority1">A tracking priority1.</param>
		/// <param name="aTrackingPriority2">A tracking priority2.</param>
		private void _doDrawLineBetweenCrosshairs (TrackingPriority aTrackingPriority1, TrackingPriority aTrackingPriority2)
		{
			DebugDraw.DrawLineBetweenCrosshairs (_getRectForAllTrackableObjects(aTrackingPriority1), _getRectForAllTrackableObjects(aTrackingPriority2), _zPlaneCoordinate_float, Constants.DEBUG_COLOR_VIEWPORT_CENTERPOINT);

		}
		/// <summary>
		/// Draw center point crosshairs for rect of all trackable objects.
		/// </summary>
		private void _doDrawCenterPointCrosshairsForRectOfAllTrackableObjects (TrackingPriority aTrackingPriority)
		{
			DebugDraw.DrawCenterPointCrosshairsForRect (_getRectForAllTrackableObjects(aTrackingPriority), _zPlaneCoordinate_float, Constants.GetDebugColorByPriority (aTrackingPriority));
		}
		//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
		//\ 
		//\ DRAWING
		//\ 
		//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


		/// <summary>
		/// Draw one rect for all trackable objects.
		/// 
		/// NOTE: WE LOOP THROUGH OBJECTS OF INTEREST AND DRAW A RECT AROUND ALL
		/// 
		/// </summary>
		private void _doDrawOneRectForAllTrackableObjects (TrackingPriority aTrackingPriority)
		{

			DebugDraw.DrawRect (_getRectForAllTrackableObjects(aTrackingPriority), _zPlaneCoordinate_float, Constants.GetDebugColorByPriority (aTrackingPriority));
		}
		//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
		//\ 
		//\ MOVEMENT
		//\ 
		//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

		/// <summary>
		/// Dolly the Camera (Move in Z axis)
		/// </summary>
		private void _doDollyCamera ()
		{
			Rect viewport_rect 									= _getViewportRect(_zPlaneCoordinate_float);
			Rect highAndLowTrackableObjects_rect 				= _getRectForAllTrackableObjects(TrackingPriority.Low);
			bool areAllHighAndLowTrackableObjectsInView_boolean = RectHelper.IsRectWithinRect (viewport_rect, highAndLowTrackableObjects_rect);
			//
			Rect currentTarget_rect 							= _getRectForAllTrackableObjects(_currentCameraTrackingPriority);
			bool isCurrentTargetRectWithinBoundary_boolean 		= RectHelper.IsRectWithinRect (_viewportBoundary_rect, currentTarget_rect);



			//
			//********************************
			//1. IF WE CAN SEE LOW+HIGH THEN ALWAYS ZOOM IN MORE
			//********************************
			if (areAllHighAndLowTrackableObjectsInView_boolean) {
				_doUpdateZPositionTargetValue (isCurrentTargetRectWithinBoundary_boolean, areAllHighAndLowTrackableObjectsInView_boolean, 0.05f);
				if (_currentCameraTrackingPriority == TrackingPriority.High) {
					_currentCameraTrackingPriority = TrackingPriority.Low;
				}
			} else {
				 

				//********************************
				//2. IF WE CAN'T SEE LOW+HIGH AND CANNOT ZOOM OUT MORE, THEN CHANGE FOCUS
				//TO JUST THE HIGH PRIORITY OBJECTS
				//********************************
				if (_zPosition_lerptarget.targetValue == _zPosition_lerptarget.minimum) {
					if (_currentCameraTrackingPriority == TrackingPriority.Low) {
						_currentCameraTrackingPriority = TrackingPriority.High;
					}
				}
				_doUpdateZPositionTargetValue (isCurrentTargetRectWithinBoundary_boolean, areAllHighAndLowTrackableObjectsInView_boolean, -0.05f);

			}

			//UPDATE POSITION
			_zPosition_lerptarget.lerpCurrentToTarget (1);
			transform.position = new Vector3 (transform.position.x, transform.position.y, _zPosition_lerptarget.targetValue);


		}
		//--------------------------------------
		//  Methods
		//--------------------------------------

		//	PUBLIC 

		/// <summary>
		/// Start this instance.
		/// </summary>
	 	void Start () 
		{

			//DEFAULT
			_currentCameraTrackingPriority = TrackingPriority.Low;

			//
			_trackableObjectComponents_list = new List<TrackableObjectComponent>();
			TrackingCameraComponent._instance = this;


			//X
			float xPositionTemporaryTarget_float = 20;
			_xPosition_lerptarget = new LerpTarget (transform.position.x, xPositionTemporaryTarget_float, _xPositionMin_float, _xPositionMax_float, _xPositionAcceleration_float);

			//
			//Y
			float yPositionTemporaryTarget_float = 20;
			_yPosition_lerptarget = new LerpTarget (transform.position.y, yPositionTemporaryTarget_float, _yPositionMin_float, _yPositionMax_float, _yPositionAcceleration_float);

			//Z
			//NOTE: WE USE NEGATIVES BECAUSE THE 'DISTANCE' IS IN THE NEGATIVE QUADRANT (OF CARTESIAN COORDS)
			//NOTE, WE REVERSE MIN/MAX HERE BY DESIGN BECAUSE OF NEGATIVE VALUES
			_zPosition_lerptarget = new LerpTarget (transform.position.z, -_distanceDefault_float, -_distanceMax_float, -_distanceMin_float, _zPositionAcceleration_float);
		
		}