/*
	Trampoline Sim.
	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 GAME_SHAPE_H
#define GAME_SHAPE_H

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

#include "Physics/Contact.h"
#include "Physics/RaycastResult.h"
#include "Physics/Ray.h"

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

namespace Game
{
	//=================================================================================================================
	/// @brief		This is the base class for all shapes.
	//=================================================================================================================
	
	class Shape
	{
		public:

			//=========================================================================================================
			// Enums
			//=========================================================================================================

				/// Enum representing the different types of shapes

				enum ShapeType
				{
					/// A cuboid / box shape

					SHAPE_BOX ,

					/// A plane shape

					SHAPE_PLANE ,
					
					/// A heightfield shape
					
					SHAPE_HEIGHTFIELD
				};
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				//=====================================================================================================
				/// @brief		Creates the shape
				/// @param		position - position the shape is initially in
				/// @param		orientation - orientation of the shape
				/// @param		type - enum representing the type of shape
				//=====================================================================================================
				
				Shape( const Vec3f & position , const Quaternionf & orientation , ShapeType type )
				{
					SetPosition(position);
					SetOrientation(orientation);

					// Save type

					m_type = type;
				}
				
				//=====================================================================================================
				/// @brief		Destructor.
				//=====================================================================================================
				
				virtual ~Shape(){}
				
				//=====================================================================================================
				/// @brief		Returns the type of this shape
				/// @returns	The type of this shape
				//=====================================================================================================
				
				inline ShapeType GetType() const { return m_type; }
				
				//=====================================================================================================
				/// @brief		Returns the position of the shape
				/// @returns	The position of the shape
				//=====================================================================================================
				
				inline const Vec3f & GetPosition() const { return m_position; }
				
				//=====================================================================================================
				/// @brief		Returns the orientation of the shape
				/// @returns	The orientation of the shape
				//=====================================================================================================
				
				inline const Quaternionf & GetOrientation() const { return m_orientation; }
				
				//=====================================================================================================
				/// @brief		Sets the position of the shape:
				/// @param		position - new position of the shape
				/// @pre		Position must be valid
				//=====================================================================================================
				
				inline void SetPosition( const Vec3f & position )
				{ 
					ENSURE( Float::IsValid(position.x) , "Position must be valid" )
					ENSURE( Float::IsValid(position.y) , "Position must be valid" )
					ENSURE( Float::IsValid(position.z) , "Position must be valid" )
				
					m_position = position;
				}

				//=====================================================================================================
				/// @brief		Sets the orientation of the rigid body:
				/// @param		orientation - new orientation of the rigid body
				/// @pre		Given orientation must be valid
				//=====================================================================================================
				
				inline void SetOrientation( const Quaternionf & orientation )
				{ 
					// Make sure ok
					
					ENSURE( Float::IsValid( orientation.x ) , "Given orientation must be valid" ) 
					ENSURE( Float::IsValid( orientation.y ) , "Given orientation must be valid" ) 
					ENSURE( Float::IsValid( orientation.z ) , "Given orientation must be valid" ) 
					ENSURE( Float::IsValid( orientation.s ) , "Given orientation must be valid" )
				
					m_orientation = orientation;
				}
				
				//=====================================================================================================
				/// @brief		Generates a list of collision contacts with the other shape
				/// @param		other - other shape to generate a list of for 
				/// @param		contacts - where to save the resulting contacts
				//=====================================================================================================

				virtual void GenerateContacts( const Shape & other , std::vector<Contact> & contacts ) const = 0;

				//=====================================================================================================
				/// @brief		Raycasts against this shape and returns the result
				/// @param		ray - ray to cast against the shape
				/// @returns	Result of the raycast
				//=====================================================================================================

				virtual RaycastResult Raycast( Ray & ray ) const = 0;

		private:
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================			
				
				/// Copying is disallowed
				
				Shape( const Shape & other );

				/// Copying is disallowed
				
				Shape & operator = ( const Shape & other );			
		
			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// This is the position of the shape
				
				Vec3f m_position;
				
				/// This is the orientation of the shape
				
				Quaternionf m_orientation;

				/// This is the type of the shape

				ShapeType m_type;
	};
}

#endif
