/*
	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_BOX_H
#define GAME_BOX_H

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

#include "GameObjects/GameObjectBase.h"
#include "Graphics/Texture.h"
#include "Graphics/PixelShader.h"
#include "Graphics/VertexShader.h"
#include "Graphics/VertexFormat.h"
#include "Graphics/ShaderUniform.h"

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

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================

	class RigidBody;

	//=================================================================================================================
	/// @brief		This class represents a box. It renders the box as well as holding the boxe's 
	///				RigidBody and shape.
	//=================================================================================================================

	class GameBox : public GameObjectBase
	{
		public:
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================
				
				/// Creates the box with the specified parameters
				
				GameBox( const Vec3f & position , const Vec3f & size );
				
				/// Destroys the box

				~GameBox();
				
				/// Renders the plane
				
				virtual void OnDraw( Camera3D * c );
				
				/// Updates the box and does the physics
				
				virtual void OnUpdate( float time_delta );
				
				/// Returns the type name of this object
				
				virtual const char * GetTypeName() const { return "GameBox"; }

				/// Returns the rigid body used by this box

				inline RigidBody & GetBody(){ return * m_body; }

		private:

			//=========================================================================================================
			// Functions
			//=========================================================================================================
				
				/// Checks if we are to apply a force from keyboard input
				
				void CheckKeyboardInput();
				
				/// This debug function draws a raycast against the rigid body from the camera position

				void DrawRaycast( Camera3D * c );				

				#ifdef USE_DEBUG_CONSOLE

					/// This debug function draws contacts for the rigid body

					void DrawContacts( Camera3D * c );

					/// Console command: enables drawing of contacts for the rigid body
					
					static bool ConCmd_P_DrawBoxContacts( bool arg  , bool arg_given );

					/// Console command: enables drawing of a raycast against the box
					
					static bool ConCmd_P_DrawBoxRaycast( bool arg  , bool arg_given );

				#endif
				
				/// Copying is disallowed
				
				GameBox( const GameBox & other );

				/// Copying is disallowed
				
				GameBox & operator = ( const GameBox & other );				

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// Vertex shader used to render the plane
				
				VertexShader m_vs;
			
				/// Pixel shader used to render the plane
				
				PixelShader m_ps;
				
				/// Vertex format for the plane
				
				VertexFormat m_vf;
				
				/// The transform uniform variable on the vertex shader
				
				ShaderUniform m_u_transform;
				
				/// Texture used to draw the plane
				
				Texture m_texture;
				
				/// True if all our graphics resources are ok
				
				bool m_valid_resources;

				/// The rigid body for the box

				RigidBody * m_body;
				
				/// Basic pixel shader for line etc. drawing

				PixelShader m_basic_ps;				

				/// Debug only:

				#ifdef USE_DEBUG_CONSOLE

					/// If true then we draw contacts for the box

					static bool s_draw_contacts;

					/// If true then we draw the result of a raycast against the box

					static bool s_draw_raycast;

				#endif
	};
}

#endif
