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

		RayHitAccumulator.h

		Copyright: (c) 2008 Daz3D Inc. All rights reserved.

		Author:	Charles
		Date:	02/07/2008

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

#ifndef __RayHitAccumulator__
#define __RayHitAccumulator__

#if CP_PRAGMA_ONCE
#pragma once
#endif

struct RaytracedInstance;

/// \addtogroup Data
/// \{

/// Accumulates all the ray hits seen by transparency along a given ray
class TRayHitAccumulator
{
public:
	TRayHitAccumulator();
	~TRayHitAccumulator();

	inline void Reset() { fRayHitCount=0; fCurrentInstance=NULL; }

	void SortRayHitsByDistance();

	RayHit3D*						AddNewRayHit();
	void							SetRayHitCount(int32 count);
	
	inline void						SetCurrentInstance(const RaytracedInstance* instance) { fCurrentInstance = instance; }

	inline const RaytracedInstance*	GetCurrentInstance()		{ return fCurrentInstance; }
	inline int32					GetRayHitCount()			{ return fRayHitCount; }
	inline RayHit3D*				GetLastRayHit()				{ return fRayHitList[fRayHitCount-1]; }
	inline RayHit3D*				GetRayHit(int32 index)		{ MCAssert(index<fRayHitCount); return fRayHitList[index]; }

protected:
	TMCPtrArray<RayHit3D>				fRayHitList;				// big array where we store the rayhit as they are created

	int32								fRayHitCount;			// number of elements of the array that are used

	const RaytracedInstance*			fCurrentInstance;
};

/// \}

#endif