/*!
	@project Rune
	@file RuPathRover_Simple.cpp

	Copyright (c) 2004-2005 All rights reserved

	@author John Tang
	@date 2006/02/09
*/

#include "../PathEngine/RuPathRover_Simple.h"
#include "../Scene/Base/RuEntityBase.h"

#pragma unmanaged

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

ruRTTI_DEFINE_SUBCLASS(CRuPathRover_Simple, IRuObject)
ruHEAP_DEFINE_SUBCLASS(CRuPathRover_Simple, "CRuPathRover_Simple", "IRuPathRover_Base")
ruCLASSGUID_DEFINE(CRuPathRover_Simple, 0xEF791660, 0xA69446b2, 0xB9D775DB, 0x6A0EFB2B)

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

CRuPathRover_Simple::CRuPathRover_Simple()
:	m_colObject(NULL)
{
}

CRuPathRover_Simple::~CRuPathRover_Simple()
{
	ruSAFE_RELEASE(m_colObject);
}

BOOL CRuPathRover_Simple::SetCollisionObject(IRuObject *colObject)
{
	colObject->AddRef();
	ruSAFE_RELEASE(m_colObject);
	m_colObject = colObject;

	return TRUE;
}

BOOL CRuPathRover_Simple::IsPathValid(const CRuVector3 &startPt, const CRuVector3 &endPt)
{
	CRuCollisionQuery_Segment_HitTest segQuery;

	segQuery.m_colSegment = CRuSegment3(startPt + CRuVector3(0.0f, 10.0f, 0.0f), endPt + CRuVector3(0.0f, 10.0f, 0.0f));

	if(m_colObject->GetType().IsSubClassOf(CRuEntity::Type))
	{
		static_cast<CRuEntity *>(m_colObject)->QueryCollision(&segQuery);
	}
	else if(m_colObject->GetType().IsSubClassOf(IRuCollisionHierarchy::Type))
	{
		static_cast<IRuCollisionHierarchy *>(m_colObject)->QueryCollision(&segQuery);
	}

	if(segQuery.m_positiveHit)
	{
		return FALSE;
	}

	return TRUE;
}

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

#pragma managed
