/*
	Lan Wars.
	Copyright (c) 2009, 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_3D_H
#define CAMERA_3D_H

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

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

	//=================================================================================================================
	/// @brief		Represents a 3D camera.
	/// @todo		Convert camera from 2d into 3d
	/// @todo		Create a Lookat() function which will look at a given position
	//=================================================================================================================
	
	class Camera3D : public ObjectBase
	{
		public:

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

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

				Camera3D( Window * window , const Vec3f & position , float z_near , float z_far );
				
				/// 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 Vec3f & position ){ m_position = position; }
				
				/// Sets the orientation of the camera
				
				inline void SetOrientation( const Matrix4f & o ){ m_orientation = o; }
				
				/// Rotates the camera about it's local world x-axis:
				
				void RotateLocalX( float amount );
				
				/// Rotates the camera about it's local world y-axis:
				
				void RotateLocalY( float amount );
				
				/// Rotates the camera about it's local z-axis:
				
				void RotateLocalZ( float amount );												
				
				/// Rotates the camera about the world x-axis:
				
				void RotateX( float amount );
				
				/// Rotates the camera about the world y-axis:
				
				void RotateY( float amount );
				
				/// Rotates the camera about the world z-axis:
				
				void RotateZ( float amount );				
				
				/// Moves the camera in world coordinates:

				void Move( const Vec3f & amount );
				
				/// Moves the camera relative to it's direction
				
				void MoveLocal( const Vec3f & amount );
				
				/// Returns the right vector of the camera
				
				Vec3f GetRight() const { return m_orientation.GetRow(0).ToVec3(); }

				/// Returns the up vector of the camera
				
				Vec3f GetUp() const { return m_orientation.GetRow(1).ToVec3(); }
				
				/// Returns the forward vector of the camera
				
				Vec3f GetForward() const { return m_orientation.GetRow(2).ToVec3(); }
				
				/// Interpolates the camera towards the given position

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

				/// Looks at the given position:

				void LookAt( const Vec3f & position );

				/// Gets the position of the camera:

				inline Vec3f GetPosition() const { return m_position; }
				
				/// 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;
				
				/// Returns a combined view and projection matrix for the camera
				
				Matrix4f GetViewProjectionMatrix() const;

		private:

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// The position of the camera
				
				Vec3f m_position;
				
				/// The orientation of the camera
				
				Matrix4f m_orientation;

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

};

#endif 