/****************************************************************************************

		BasicCameraLightGel.h

		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Ray Dream
		Date:	9/29/98

		Revision History

		when		who			what & why
		==========	==========	======================================================
		8/6/99		cph			added direct inheritance of interfaces for basic classes
		10/21/98	Alec		added new calls from camera interface
		
*****************************************************************************************/

#ifndef __BasicCameraLightGel__
#define __BasicCameraLightGel__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "I3DExLight.h"   
#include "I3DExCamera.h"   
#include "I3DExGel.h"   

#include "BasicCOMImplementations.h"
#include "MCBasicTypes.h"

/// \addtogroup BaseClass
/// \{

/****************************************************************************\
*                                                                            *
*       TBasicCamera                                                         *
*                                                                            *
\****************************************************************************/

const real32	kgDefaultNearPlane = 0.5f;

/// Basic Camera class.  Derive from this for a default implementation of I3DExCamera.
/// \see I3DExCamera
class TBasicCamera : public I3DExCamera, public TBasicDataExchanger  
{
	public:
		virtual MCCOMErr 	MCCOMAPI QueryInterface			(const MCIID &riid, void** ppvObj);

		virtual uint32 		MCCOMAPI AddRef					() { return TBasicDataExchanger::AddRef(); }

		// tell the camera about it's modelToWorldTfm
		virtual MCCOMErr	MCCOMAPI SetTransform			(const TTransform3D& transform);
		
		// generate a ray through a given screen location [-1,1]
		virtual boolean		MCCOMAPI CreateRay				(const TVector2& screenPosition, TVector3& worldOrigin, TVector3& worldDirection) const;

		// generate a ray through a given screen location [-1,1]
		virtual boolean		MCCOMAPI CreateRay				(const TVector2& screenPosition,const TVector2& screenDerivate, Ray3D &ray) const;
		

		virtual boolean		MCCOMAPI CreateRay			(const TVector2&	screenPosition,
														 const TVector2&	screenDerivate,
														 const TVector2&	lensPosition,	// for depth of field
														 Ray3D&				ray);

		// true if w component from projection is always 1.0
		virtual boolean		MCCOMAPI IsProjectionAffine		(void) const;
		
		// this routine converts the position into a [-1,1] space,
		// returns false if pt behind the camera 
		// note that the result is not divided by w in the pre-divide routine
		virtual boolean		MCCOMAPI PreProject3DTo2D		(const TVector3& cameraPosition, TVector4& projectedPosition) const;
		virtual boolean		MCCOMAPI Project3DTo2D			(const TVector3& cameraPosition, TVector3& screenPosition) const;
									
		// retrieve an id for the camera
		virtual uint32		MCCOMAPI GetPrimitiveID			() const = 0;
		
		virtual MCCOMErr	MCCOMAPI SetNearPlane			(real32 value) { return MC_S_FALSE; }						
		
		// return standard camera info used in the renderers
		virtual void		MCCOMAPI GetStandardCameraInfo	(TStandardCameraInfo& cameraInfo) const;

		virtual MCCOMErr	MCCOMAPI SetHalfWidth			(real value);

		virtual void		MCCOMAPI SetRenderingUVBox		(const TBBox2D& inUVBox) { }

		virtual boolean		MCCOMAPI InitDepthOfField		(int32& samplingQuality);

		/*virtual real32	MCCOMAPI GetScalingFactor()	const;
		virtual void	MCCOMAPI SetScalingFactor(real32 inValue);*/
};



/****************************************************************************\
*                                                                            *
*       TBasicLight                                                          *
*                                                                            *
\****************************************************************************/
/// Basic Light class.  Derive from this for a default implementation of an I3DExLightsource.
/// \see I3DExLightsource
class TBasicLight : public I3DExLightsource, public TBasicDataExchanger 
{
public:
	virtual MCCOMErr 	MCCOMAPI QueryInterface			(const MCIID &riid, void** ppvObj);
	virtual uint32 		MCCOMAPI AddRef					() { return TBasicDataExchanger::AddRef(); }

	virtual MCCOMErr 	MCCOMAPI SetTransform			(TTransform3D* transform);
	virtual MCCOMErr	MCCOMAPI GetDirection			(const TVector3& point,TVector3& resultDirection,real& resultDistance);
	virtual boolean 	MCCOMAPI GetColor				(const TVector3& point,const TVector3& direction,const real distance,TMCColorRGB& result,real& ShadowIntensity);
	virtual boolean 	MCCOMAPI IsVisibleInPerspective	();
	virtual uint32 		MCCOMAPI GetPrimitiveID			();
	virtual MCCOMErr 	MCCOMAPI ForEachShadowBuffer	(ForEachShadowBufferCallback proc,void* priv);
	virtual MCCOMErr	MCCOMAPI GetLightParameter		(int32 keyword, void* parameter) { return MC_S_OK; }
	virtual MCCOMErr	MCCOMAPI GetLightInfo			(boolean& hasLightCone,boolean& hasLightSphere,real& halfAngle,TTransform3D& transform);
	virtual boolean		MCCOMAPI GetUVfromDirection		(TVector2& uv,const TVector3& direction) const;
	virtual LightTraceElement*	MCCOMAPI GetNewTrace	(int16* nb);

	virtual MCCOMErr	MCCOMAPI GetStandardLight		(TStandardLight& light) const;

	virtual void		MCCOMAPI InitSampling(const TBBox3D&	sceneBoundingBox,
											  real&				solidAngle,
											  int32&			regionCount);

	virtual void		MCCOMAPI GetRandomRay			(int32 regionIndex,Ray3D& ray) const;

	virtual int32		MCCOMAPI GetShadowBufferCount	() const;
	virtual void		MCCOMAPI GetShadowBuffer		(int32				bufferIndex,
														 I3DShCamera**		camera,
														 TBBox2D&			uvBox) const;
	virtual real32		MCCOMAPI GetScalingFactor()	const			{ return 1.0f; }
	virtual void		MCCOMAPI SetScalingFactor(real32 inValue)	{ }
	virtual MCCOMErr	MCCOMAPI UpdateAtmosphere(I3DShScene* inScene)	{ return MC_S_OK; }
	virtual real MCCOMAPI UpdateLightRadius(const real radiusFromShadowFeature) const { return radiusFromShadowFeature; }
};




/****************************************************************************\
*                                                                            *
*       TBasicGel                                                            *
*                                                                            *
\****************************************************************************/
/// Basic Gel class.  Derive from this for a default implementation of I3DExLightsourceGel
/// \see I3DExLightsourceGel
class TBasicGel : public I3DExLightsourceGel, public TBasicDataExchanger 
{
	public:
		virtual MCCOMErr 	MCCOMAPI QueryInterface	(const MCIID& riid, void** ppvObj);
		virtual uint32 		MCCOMAPI AddRef			() { return TBasicDataExchanger::AddRef(); }

		virtual boolean 	MCCOMAPI GetGelValues	(const TVector2& gelScreenPosition,TMCColorRGB& result);
};
/// \}
#endif