/*
	Trig Wars.
	Copyright (c) 2008, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CAMERA_2D_H
#define CAMERA_2D_H

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================
	
	class Window;

	//=================================================================================================================
	/// @brief		Represents a 2D camera.
	//=================================================================================================================
	
	class Camera2D : public ObjectBase
	{
		public:

			//=========================================================================================================
			// Functions
			//=========================================================================================================

				/// Creates the 2D camera at the given position and with the given reference view area:

				Camera2D( Window * window , const Vec2f & position , const Vec2f & reference_size , float z_near , float z_far );

				/// Gets the reference view area of the camera that it tries to display whilst keeping aspect ratio

				inline Vec2f GetReferenceViewArea() const { return m_reference_size; }

				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				/// @brief	Sets the reference view area that the camera tries to display whilst keeping aspect ratio
				/// @param	area - view area to try and show
				/// @pre	Given area must be valid
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

				inline void SetReferenceViewArea( const Vec2f & area )
				{
					ENSURE( area.x > 0 , "Given area must be valid" );
					ENSURE( area.y > 0 , "Given area must be valid" );

					m_reference_size = area;
				}
				
				/// Tells the object to announce it's type name: this is the type name without the Game:: namespace

				virtual const char * GetTypeName() const;						

				/// Sets the position of the camera

				inline void SetPosition( const Vec2f & position ){ m_position = position; }
				
				/// Interpolates the camera towards the given position

				void LerpTo( const Vec2f & position , float amount );

				/// Gets the position of the camera:

				inline Vec2f GetPosition() const { return m_position; }
				
				/// Gets the area of the world shown currently by the camera:
				
				inline Vec2f GetViewArea() const;
				
				/// Gets the near plane distance
				
				inline float GetNearDist() const { return m_z_near; }
				
				/// Gets the far plane distance
				
				inline float GetFarDist() const { return m_z_far; }				

				/// Gets the window used by the camera

				inline Window * GetWindow(){ return m_window; }

				/// Gets the view matrix used by the camera
				
				Matrix4f GetViewMatrix() const;
				
				/// Gets the projection matrix used by the camera
				
				Matrix4f GetProjectionMatrix() const;
				
				/// Gets the world matrix used by the camera
				
				Matrix4f GetWorldMatrix() const;
				
				/// Returns a combined view and projection matrix for the camera
				
				Matrix4f GetViewProjectionMatrix() const;

		private:

			//=========================================================================================================
			// Variables
			//=========================================================================================================
				
				/// Position of the camera:
				
				Vec2f m_position;
				
				/// Size of the world the camera will try and show, whilst maintaining an aspect correct view
				
				Vec2f m_reference_size;

				/// Near z value
				
				float m_z_near;
				
				/// Far z value
				
				float m_z_far;
				
				/// Window used by the camera
				
				Window * m_window;		
	};

};

#endif 