// IslandDoc.cpp : implementation of the CIslandDoc class
//

#include "stdafx.h"

#include "IslandPerson.h"
#include "Helpers/helper.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CIslandPerson construction/destruction
CIslandPerson::CIslandPerson()
{
	// TODO: add one-time construction code here
	//a person will alays have a height of 40

	ZeroMemory(
    &m_positionMatrix, 	 
    sizeof(m_positionMatrix)   
   );

	//make it the identity
	m_positionMatrix[0] = 1;
	m_positionMatrix[5] = 1;
	m_positionMatrix[10] = 1;
	m_positionMatrix[15] = 1;

	m_bShiftIsDown = false;

	m_dFootTranslation = 0;
	m_dHeight = 0;

}
CIslandPerson::CIslandPerson(int nID)
{
	// TODO: add one-time construction code here
	//a person will alays have a height of 40

	ZeroMemory(
    &m_positionMatrix, 	 
    sizeof(m_positionMatrix)   
   );

	//make it the identity
	m_positionMatrix[0] = 1;
	m_positionMatrix[5] = 1;
	m_positionMatrix[10] = 1;
	m_positionMatrix[15] = 1;

	m_bShiftIsDown = false;

	//I know the poeple are bounded in local co-ordiantes by
	//(-10, -30, -5) and (10, 15, 5)
	m_nID = nID;
	if (m_nID == MAN || m_nID == WOMAN)
	{
		m_boundingBox.m_minPoint.m_x = -10;
		m_boundingBox.m_minPoint.m_y = -30;
		m_boundingBox.m_minPoint.m_z = -5;

		m_boundingBox.m_maxPoint.m_x = 10;
		m_boundingBox.m_maxPoint.m_y = 15;
		m_boundingBox.m_maxPoint.m_z = 5;
	}
	else if (m_nID == GIRL || m_nID == BOY)
	{
		m_boundingBox.m_minPoint.m_x = -5;
		m_boundingBox.m_minPoint.m_y = -17.5;
		m_boundingBox.m_minPoint.m_z = -5;

		m_boundingBox.m_maxPoint.m_x = 5;
		m_boundingBox.m_maxPoint.m_y = 10;
		m_boundingBox.m_maxPoint.m_z = 5;
	}

	m_dFootTranslation = 0;
	m_dHeight = 0;

}

CIslandPerson::~CIslandPerson()
{
}

/////////////////////////////////////////////////////////////////////////////
// CIslandPerson serialization

void CIslandPerson::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		//output our bonding box points
		ar << m_boundingBox.m_minPoint.m_x;
		ar << m_boundingBox.m_minPoint.m_y;
		ar << m_boundingBox.m_minPoint.m_z;

		ar << m_boundingBox.m_maxPoint.m_x;
		ar << m_boundingBox.m_maxPoint.m_y;
		ar << m_boundingBox.m_maxPoint.m_z;

		ar << m_dFootTranslation;
		ar << m_dHeight;
		ar << m_nID;

		//output our position matrix
		for (int i = 0; i < 16; i++)
			ar << m_positionMatrix[i];

		m_camera.Serialize(ar);
	}
	else
	{
		// TODO: add loading code here
		ar >> m_boundingBox.m_minPoint.m_x;
		ar >> m_boundingBox.m_minPoint.m_y;
		ar >> m_boundingBox.m_minPoint.m_z;

		ar >> m_boundingBox.m_maxPoint.m_x;
		ar >> m_boundingBox.m_maxPoint.m_y;
		ar >> m_boundingBox.m_maxPoint.m_z;

		ar >> m_dFootTranslation;
		ar >> m_dHeight;
		ar >> m_nID;

		for (int i = 0; i < 16; i++)
			ar >> m_positionMatrix[i];

		m_camera.Serialize(ar);
	}
}

//rotate or move to look in the direction specified by
//nDirection.
//reutrns true if we are to pop up a chil,
//false otherwise
CIslandPerson* CIslandPerson::MoveOrTurnInDirection(int nDirection, BOOL bKeyUP, CBoundingBoxTree* boundingBoxTree,
																					CBoundingBoxTree* boundingBoxTreeGround,
																					CList<CIslandPerson*, CIslandPerson*> *otherPeople)
{
	//num to move
	int nMove = 10;
	//num to rotate
	int nRotate = 10;
	switch(nDirection)
	{
		case VK_UP:
			if (m_bShiftIsDown)
				//rotate up
				m_camera.SetNextXRotation(nMove);
			else
				m_camera.SetNextZTranslation(-nMove);
			break;
		case VK_RIGHT:
			m_camera.SetNextYRotation(-nMove);
			break;
		case VK_DOWN:
			if (m_bShiftIsDown)
				//rotate down
				m_camera.SetNextXRotation(-nMove);
			else
				m_camera.SetNextZTranslation(nMove);
			break;
		case VK_LEFT:	
			m_camera.SetNextYRotation(nMove);
			break;
		case VK_SHIFT:
			//this means we will be loking up or down
			//only god can do this
			if (m_nID == GOD)
			{
				if (bKeyUP)
					m_bShiftIsDown = false;
				else
					m_bShiftIsDown = true;
			}
			break;
	};
	
	//I want to know if we now collides with anything
	if (m_nID != GOD)
	{
		//test the objects
		if (CheckForBodyCollision(boundingBoxTree))
		{
			m_camera.ResetNextTranslations();
			return NULL;
		}
		//check for collision with the other poeple
		if (otherPeople != NULL)
		{
			CIslandPerson* personCollision = CheckForPeopleCollision(otherPeople);
			if (personCollision)
			{
				return personCollision;
			}
		}
		//TEST THE GROUND	
		C3DPoint moveToPointRightMin = GetMoveToPointFront(3, true, true);
		moveToPointRightMin.m_y -= 100;
		C3DPoint maxTestPointRight = GetMoveToPointFront(1, true, true);
		
		C3DPoint moveToPointLeftMin = GetMoveToPointFront(3, false, true);
		moveToPointLeftMin.m_y -= 100;
		C3DPoint maxTestPointLeft = GetMoveToPointFront(1, false, true);
		
		//find out where we are colliding with the ground
		//so we can raise ourselves the proper height
		//test really further down in case our min
		//is still above the ground, this can happen
		//if we ere standing on a high point before
		//first check right
		CFace* faceRight = boundingBoxTreeGround->IntersectsFace(maxTestPointRight,moveToPointRightMin);
		CFace* faceLeft = boundingBoxTreeGround->IntersectsFace(maxTestPointLeft,moveToPointLeftMin);
		if (faceRight || faceLeft)
		{
			C3DPoint* groundCollisionPointRight = NULL;
			C3DPoint* groundCollisionPointLeft = NULL;
			if (faceRight)
				groundCollisionPointRight = faceRight->IsInBetween(maxTestPointRight,moveToPointRightMin);
			if (faceLeft)
				groundCollisionPointLeft = faceLeft->IsInBetween(maxTestPointLeft,moveToPointLeftMin);
			//arrange to translate us up the max
			//y between the left and right intersect points
			double dy = 0;
			if (groundCollisionPointRight)
				if (dy < groundCollisionPointRight->m_y)
					dy = groundCollisionPointRight->m_y;
			if (groundCollisionPointLeft)
				if (dy < groundCollisionPointLeft->m_y)
					dy = groundCollisionPointLeft->m_y;

			//intial height is 40 and our bottom is at 
			//-30.  So we are drawn intially at 10
			if (m_nID == MAN || m_nID == WOMAN)
				m_dFootTranslation = dy - 10; 
			if (groundCollisionPointRight)
				delete (groundCollisionPointRight);
			if (groundCollisionPointLeft)
				delete (groundCollisionPointLeft);

			//the camera needs to be moved to keep up with our eyes
			//only the y of the camera needs to be changed
			m_camera.SetHeight(dy + 40);
		}
		else
		{
			//need to double check becasue we can fall through
			//the seem between ground cells, very hard to duplicate
			double dSaveZ = m_camera.GetNextZTranslation();
			m_camera.SetNextZTranslation(dSaveZ - 10);
			moveToPointRightMin = GetMoveToPointFront(3, true, true);
			moveToPointRightMin.m_y -= 100;
			maxTestPointRight = GetMoveToPointFront(1, true, true);
			maxTestPointRight.m_y += 100;
			C3DPoint* groundCollisionPoint = boundingBoxTreeGround->Intersects(maxTestPointRight,moveToPointRightMin);
			m_camera.SetNextZTranslation(dSaveZ);
			if (groundCollisionPoint != NULL)
			{
				//rest the last z
				delete(groundCollisionPoint);
			}
			else
			{
				//we aren't colliding with the ground.
				//we've hit an edge and have fallen off
				//so translate down
				m_camera.SetHeight(-20);
				//fall forward some
				if (m_dFootTranslation != -60)
				{
					::MessageBox(NULL,"You idiot, now how will you get back up?", "Fell off Cliff", MB_OK);
					m_camera.SetNextZTranslation(m_camera.GetNextZTranslation() - 30);
				}
				m_dFootTranslation = -60;
			}
			
		}
		

		
	}
	RecalculateMatrices();
	return NULL;
}

void CIslandPerson::RecalculateMatrices()
{
	glPushMatrix();
	glLoadIdentity();
	//do the rotations
	//but do the inverse of everything
	glRotated(-m_camera.GetNextXRotation(), 1.0, 0.0, 0.0); //rotate degrees on the x-axis
	glRotated(-m_camera.GetNextYRotation(), 0.0, 1.0, 0.0); //rotate degrees on the y-axis
	glRotated(-m_camera.GetNextZRotation(), 0.0, 0.0, 1.0); //rotate degrees on the z-axis
	
	glTranslated(-m_camera.GetNextXTranslation(), 
		-m_camera.GetNextYTranslation(), -m_camera.GetNextZTranslation()); //translate from the origin

	glMultMatrixd(m_camera.GetCameraMatrix());

	double newMatrix[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, newMatrix);
	glPopMatrix();
	m_camera.SetCameraMatrix(newMatrix);

	//want the inverse of everything we just di for our global
	//postion
	glPushMatrix();
	glLoadIdentity();
		glMultMatrixd(m_positionMatrix);
		glRotated(m_camera.GetNextXRotation(), 1.0, 0.0, 0.0); //rotate degrees on the x-axis
		glRotated(m_camera.GetNextYRotation(), 0.0, 1.0, 0.0); //rotate degrees on the y-axis
		glRotated(m_camera.GetNextZRotation(), 0.0, 0.0, 1.0); //rotate degrees on the z-axis
		glTranslated(m_camera.GetNextXTranslation(), 
				m_camera.GetNextYTranslation(), m_camera.GetNextZTranslation()); //translate from the origin
	
		glGetDoublev(GL_MODELVIEW_MATRIX, m_positionMatrix);
	glPopMatrix();

	m_camera.ResetNextTranslations();
}


double * CIslandPerson::GetPointOfViewMatrix(void)
{
	return m_camera.GetCameraMatrix();
}

C3DPoint CIslandPerson::GetGlobalPointFront(int nLevel/*1,2,3*/, BOOL bRight, BOOL bUseTranslation)
{
	C3DPoint point;
	//gets the translation
	double dPoint[4] = {0,0,0,1};
	if (m_nID != GOD)
	{
		dPoint[0] = m_boundingBox.m_maxPoint.m_x;
		if (!bRight)
			dPoint[0]-=20;
		dPoint[1] = m_boundingBox.m_maxPoint.m_y;
		if (nLevel == 2)
			dPoint[1] -= 30;
		if (nLevel == 3)
			dPoint[1] -= 45;
		if (nLevel == 4)
		{
			dPoint[1] -= 30; //move to our torso
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (nLevel == 5)
		{
			dPoint[1] -= 45; //move to our feet
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (bUseTranslation)
			dPoint[1] += m_dFootTranslation;
		dPoint[2] = m_boundingBox.m_maxPoint.m_z;
	}
	double dResultTrans[4];
	CHelper::MultiplyPointByMatrix(dPoint, m_positionMatrix, dResultTrans);
	
	point.m_x = dResultTrans[0];
	point.m_y = dResultTrans[1];
	point.m_z = dResultTrans[2];

	return point;
}


C3DPoint CIslandPerson::GetGlobalPointBack(int nLevel/*1,2,3*/, BOOL bRight, BOOL bUseTranslation)
{
	C3DPoint point;
	//gets the translation
	double dPoint[4] = {0,0,0,1};
	if (m_nID != GOD)
	{
		dPoint[0] = m_boundingBox.m_minPoint.m_x;
		if (!bRight)
			dPoint[0]-=20;
		dPoint[1] = m_boundingBox.m_minPoint.m_y;
		if (nLevel == 2)
			dPoint[1] += 15;
		if (nLevel == 1)
			dPoint[1] += 45;
		if (nLevel == 4)
		{
			dPoint[1] += 15; //move to our torso
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (nLevel == 5)
		{
			dPoint[1] += 45; //move to our feet
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (bUseTranslation)
			dPoint[1] += m_dFootTranslation;
		dPoint[2] = m_boundingBox.m_minPoint.m_z;
	}
	double dResultTrans[4];
	CHelper::MultiplyPointByMatrix(dPoint, m_positionMatrix, dResultTrans);
	
	point.m_x = dResultTrans[0];
	point.m_y = dResultTrans[1];
	point.m_z = dResultTrans[2];

	return point;
}

C3DPoint CIslandPerson::GetMoveToPointBack(int nLevel/*1,2,3*/, BOOL bRight, BOOL bUseTranslation)
{
	glPushMatrix();
	glLoadIdentity();
		glMultMatrixd(m_positionMatrix);
		glRotated(m_camera.GetNextXRotation(), 1.0, 0.0, 0.0); //rotate degrees on the x-axis
		glRotated(m_camera.GetNextYRotation(), 0.0, 1.0, 0.0); //rotate degrees on the y-axis
		glRotated(m_camera.GetNextZRotation(), 0.0, 0.0, 1.0); //rotate degrees on the z-axis

	glTranslated(m_camera.GetNextXTranslation(), 
		m_camera.GetNextYTranslation(), m_camera.GetNextZTranslation()); //translate from the origin

	double matrix[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, matrix);
	glPopMatrix();

	//now we have the next translation matrix
	C3DPoint result;
	double dPoint[4] = {0,0,0,1};
	if (m_nID != GOD)
	{
		dPoint[0] = m_boundingBox.m_minPoint.m_x;
		if (!bRight)
			dPoint[0]-=20;
		dPoint[1] = m_boundingBox.m_minPoint.m_y;
		if (nLevel == 2)
			dPoint[1] += 15;
		if (nLevel == 1)
			dPoint[1] += 45;
		if (nLevel == 4)
		{
			dPoint[1] += 15; //move to our torso
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (nLevel == 5)
		{
			dPoint[1] += 45; //move to our feet
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (bUseTranslation)
			dPoint[1] += m_dFootTranslation;
		dPoint[2] = m_boundingBox.m_minPoint.m_z;
	}
	double dResultTrans[4];
	CHelper::MultiplyPointByMatrix(dPoint, matrix, dResultTrans);
	
	result.m_x = dResultTrans[0];
	result.m_y = dResultTrans[1];
	result.m_z = dResultTrans[2];

	return result;
}

//return our bounding box in global co-ordinates
CBoundingBox CIslandPerson::GetBoundingBoxGlobal(void)
{
	CBoundingBox box;
	//want the transaltion only, not the turn
	//because that screws things up
	double dPoint[4] = {0,0,0,1};
	double dResultTrans[4];
	CHelper::MultiplyPointByMatrix(dPoint, m_positionMatrix, dResultTrans);
	
	box.m_minPoint.m_x = m_boundingBox.m_minPoint.m_x + dResultTrans[0];
	box.m_minPoint.m_y = m_boundingBox.m_minPoint.m_y + dResultTrans[1];
	box.m_minPoint.m_z = m_boundingBox.m_minPoint.m_x + dResultTrans[2];

	box.m_maxPoint.m_x = m_boundingBox.m_maxPoint.m_x + dResultTrans[0];
	box.m_maxPoint.m_y = m_boundingBox.m_maxPoint.m_y + dResultTrans[1];
	box.m_maxPoint.m_z = m_boundingBox.m_maxPoint.m_z + dResultTrans[2];

	return box;
}

C3DPoint CIslandPerson::GetMoveToPointFront(int nLevel/*1,2,3*/, BOOL bRight, BOOL bUseTranslation)
{
	glPushMatrix();
	glLoadIdentity();
		glMultMatrixd(m_positionMatrix);
		glRotated(m_camera.GetNextXRotation(), 1.0, 0.0, 0.0); //rotate degrees on the x-axis
		glRotated(m_camera.GetNextYRotation(), 0.0, 1.0, 0.0); //rotate degrees on the y-axis
		glRotated(m_camera.GetNextZRotation(), 0.0, 0.0, 1.0); //rotate degrees on the z-axis

	glTranslated(m_camera.GetNextXTranslation(), 
		m_camera.GetNextYTranslation(), m_camera.GetNextZTranslation()); //translate from the origin

	double matrix[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, matrix);
	glPopMatrix();

	//now we have the next translation matrix
	C3DPoint result;
	double dPoint[4] = {0,0,0,1};
	if (m_nID != GOD)
	{
		dPoint[0] = m_boundingBox.m_maxPoint.m_x;
		if (!bRight)
			dPoint[0]-=20;
		
		dPoint[1] = m_boundingBox.m_maxPoint.m_y;
		if (nLevel == 2)
			dPoint[1] -= 30;
		if (nLevel == 3)
			dPoint[1] -= 45;
		if (nLevel == 4)
		{
			dPoint[1] -= 30; //move to our torso
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (nLevel == 5)
		{
			dPoint[1] -= 45; //move to our feet
			if (bRight)
				dPoint[0]-=10;
			else
				dPoint[0]+=10;
		}
		if (bUseTranslation)
			dPoint[1] += m_dFootTranslation;
		dPoint[2] = m_boundingBox.m_maxPoint.m_z;
	}
	double dResultTrans[4];
	CHelper::MultiplyPointByMatrix(dPoint, matrix, dResultTrans);
	
	result.m_x = dResultTrans[0];
	result.m_y = dResultTrans[1];
	result.m_z = dResultTrans[2];

	return result;
}

void CIslandPerson::SetInitialPosition(double x, double y, double z)
{
	m_positionMatrix[12] = x;
	m_positionMatrix[13] = y;
	m_positionMatrix[14] = z;
	//set the camera to our eyes
	m_camera.SetInitialPosition(-x, -y, -z);
}

BOOL CIslandPerson::operator==(CIslandPerson person)
{

	return (m_nID = person.GetID());
}

void CIslandPerson::Draw()
{
	glPushMatrix();

	 glMultMatrixd(m_positionMatrix);
	
	 if (m_nID == MAN || m_nID == WOMAN)
	 {
			glTranslatef(0, m_dFootTranslation, 0);
	 
			// Body Color
			glColor3f(255,255,0);
			//draws a solid box at 0,0,0 with a width
			//of 20, a height of 30 and a depth ot 10
			auxSolidBox(20.0f, 30.0f, 10.0f);

			// Eye Color
			glColor3f(0,255,255);
			glTranslatef(5.0f, 10.0f, -5.0f);
			auxSolidSphere(3.0f);
			glTranslatef(-10.0f, 0.0f, 0.0f);
			auxSolidSphere(3.0f);

			//if we are the woman, draw a skirt
			if (m_nID == WOMAN)
			{
				// Leg color
				glColor3f(255,0,255);
			}
			else
			{
				// Leg color
				glColor3f(0,0,0);	
			}
			glTranslatef(0.0f, -25.0f, 5.0f);
			auxSolidCylinder(3.0f, 15.0f);
			glTranslatef(10.0f, 0.0f, 0.0f);
			auxSolidCylinder(3.0f, 15.0f);
	 }
	 else if (m_nID == BOY || m_nID == GIRL)
	 {
			glTranslatef(0, m_dFootTranslation, 0);
	 
			// Body Color
			glColor3f(255,0,0);
			//draws a solid box at 0,0,0 with a width
			//of 10, a height of 20 and a depth of 10
			auxSolidBox(10.0f, 20.0f, 10.0f);

			// Eye Color
			glColor3f(0,255,255);
			glTranslatef(2.5f, 5.0f, -5.0f);
			auxSolidSphere(3.0f);
			glTranslatef(-5.0f, 0.0f, 0.0f);
			auxSolidSphere(3.0f);

			//if we are the girl, draw a skirt
			if (m_nID == GIRL)
			{
				// Leg color
				glColor3f(255,0,255);
			}
			else
			{
				// Leg color
				glColor3f(0,0,0);	
			}
			glTranslatef(0.0f, -15.0f, 5.0f);
			auxSolidCylinder(3.0f, 7.5f);
			glTranslatef(5.0f, 0.0f, 0.0f);
			auxSolidCylinder(3.0f, 7.5f);
	 }
	glPopMatrix();

	//update the min and max of our bounding box
}

BOOL CIslandPerson::CheckForBodyCollision(CBoundingBoxTree* tree)
{
	//the right
	if (CheckSideForCollision(tree,true))
		return true;
	//the left
	if (CheckSideForCollision(tree,false))
		return true;
	return false;
}

BOOL CIslandPerson::CheckSideForCollision(CBoundingBoxTree *tree, BOOL bSide)
{
	C3DPoint curPointTopSideMax = GetGlobalPointFront(1, bSide, true);
	C3DPoint moveToPointTopSideMax = GetMoveToPointFront(1, bSide, true);

	//check our top right
	C3DPoint* collisionPoint = tree->Intersects(curPointTopSideMax,moveToPointTopSideMax);
	if (collisionPoint != NULL)
	{	
		delete (collisionPoint);
		return true;
	}

	//check the front bottom right of our torso
	C3DPoint middleCurPoint = GetGlobalPointFront(2, bSide, true);
	C3DPoint middleMoveToPoint = GetMoveToPointFront(2, bSide, true);
	collisionPoint = tree->Intersects(middleCurPoint,middleMoveToPoint);
	if (collisionPoint != NULL)
	{	
		delete (collisionPoint);
		return true;
	}

	//check the front bottom right of our foot
	C3DPoint bottomCurPoint = GetGlobalPointFront(3, bSide, true);
	C3DPoint bottomMoveToPoint = GetMoveToPointFront(3, bSide, true);
	//take a little off these because we don't want to hit the cliff
	bottomCurPoint.m_y += 5;
	bottomMoveToPoint.m_y += 5;
	collisionPoint = tree->Intersects(bottomCurPoint,bottomMoveToPoint);
	if (collisionPoint != NULL)
	{	
		delete (collisionPoint);
		return true;
	}
	return false;
}

CIslandPerson* CIslandPerson::CheckForPeopleCollision(CList<CIslandPerson*, CIslandPerson*> *otherPeople)
{
	POSITION pos = otherPeople->GetHeadPosition();
	while (pos != NULL)
	{
		CIslandPerson* person = otherPeople->GetAt(pos);
		//check if we are colliding with this person
		//check our left and right side
		//the right
		if (CheckSideForPersonCollision(person,true))
			return person;
		//the left
		if (CheckSideForPersonCollision(person,false))
		return person;
		
		otherPeople->GetNext(pos);
	}
	return NULL;
}

BOOL CIslandPerson::CheckSideForPersonCollision(CIslandPerson* person, BOOL bSide)
{
	C3DPoint curPointTopSideMax = GetGlobalPointFront(1, bSide, true);
	C3DPoint moveToPointTopSideMax = GetMoveToPointFront(1, bSide, true);

	CBoundingBox box = person->GetBoundingBoxGlobal();
	if (box.IsInBetween(curPointTopSideMax, moveToPointTopSideMax) < 1)
			return true;

	//check the front bottom of our torso
	C3DPoint middleCurPoint = GetGlobalPointFront(2, bSide, true);
	C3DPoint middleMoveToPoint = GetMoveToPointFront(2, bSide, true);
	if (box.IsInBetween(middleCurPoint, middleMoveToPoint) < 1)
			return true;

	//check the middle of our torso
	C3DPoint middleTorsoCurPoint = GetGlobalPointFront(4, bSide, true);
	C3DPoint middleTorsoMoveToPoint = GetMoveToPointFront(4, bSide, true);
	if (box.IsInBetween(middleTorsoCurPoint, middleTorsoMoveToPoint) < 1)
			return true;

	//check the front bottom of our foot
	C3DPoint bottomCurPoint = GetGlobalPointFront(3, bSide, true);
	C3DPoint bottomMoveToPoint = GetMoveToPointFront(3, bSide, true);
	if (box.IsInBetween(bottomCurPoint, bottomMoveToPoint) < 1)
			return true;

	//check in between our feet
	C3DPoint bottomMiddleCurPoint = GetGlobalPointFront(5, bSide, true);
	C3DPoint bottomMiddleMoveToPoint = GetMoveToPointFront(5, bSide, true);
	if (box.IsInBetween(bottomMiddleCurPoint, bottomMiddleMoveToPoint) < 1)
			return true;
	return false;
}