Esempio n. 1
0
/*	ProjectPathOnCellWall
------------------------------------------------------------------------------------------
	
	ProjectPathOnCellWall projects a path intersecting the wall with the wall itself. This
	can be used to convert a path colliding with a cell wall to a resulting path moving
	along the wall. The input parameter MotionPath MUST contain a starting point (EndPointA)
	which is the point of intersection with the path and cell wall number [SideNumber]
	and an ending point (EndPointB) which resides outside of the cell.
	
------------------------------------------------------------------------------------------
*/
void NavigationCell::ProjectPathOnCellWall(CELL_SIDE SideNumber, Line2D& MotionPath)const
{
	// compute the normalized vector of the cell wall in question
	vector2 WallNormal = m_Side[SideNumber].EndPointB() - m_Side[SideNumber].EndPointA();
	WallNormal.normalize();

	// determine the vector of our current movement
	vector2 MotionVector = MotionPath.EndPointB() - MotionPath.EndPointA();

	// compute dot product of our MotionVector and the normalized cell wall
	// this gives us the magnatude of our motion along the wall
	float DotResult = DotProduct(MotionVector,WallNormal);
    
	// our projected vector is then the normalized wall vector times our new found magnatude
	MotionVector = (DotResult * WallNormal);

	// redirect our motion path along the new reflected direction
	MotionPath.SetEndPointB(MotionPath.EndPointA() + MotionVector);

	//
	// Make sure starting point of motion path is within the cell
	//
	vector2 NewPoint = MotionPath.EndPointA();
	ForcePointToCellCollumn(NewPoint);
	MotionPath.SetEndPointA(NewPoint);

	//
	// Make sure destination point does not intersect this wall again
	//
	NewPoint = MotionPath.EndPointB();
	ForcePointToWallInterior(SideNumber, NewPoint);
	MotionPath.SetEndPointB(NewPoint);

}
Esempio n. 2
0
/*	ClassifyPathToCell
------------------------------------------------------------------------------------------
	
	Classifies a Path in relationship to this cell. A path is represented by a 2D line
	where Point A is the start of the path and Point B is the desired position.

	If the path exits this cell on a side which is linked to another cell, that cell index
	is returned in the NextCell parameter and SideHit contains the side number of the wall 
	exited through.
	
	If the path collides with a side of the cell which has no link (a solid edge), 
	SideHit contains the side number (0-2) of the colliding wall.

	In either case PointOfIntersection will contain the point where the path intersected
	with the wall of the cell if it is provided by the caller.
	
------------------------------------------------------------------------------------------
*/
NavigationCell::PATH_RESULT NavigationCell::ClassifyPathToCell(const Line2D& MotionPath, NavigationCell** pNextCell, CELL_SIDE& Side, vector2* pPointOfIntersection)const
{
	int InteriorCount = 0;

	// Check our MotionPath against each of the three cell walls
	for (int i=0; i<3; ++i)
	{
		// Classify the MotionPath endpoints as being either ON_LINE,
		// or to its LEFT_SIDE or RIGHT_SIDE. 
		// Since our triangle vertices are in clockwise order, 
		// we know that points  to the right of each line are inside the cell.
		// Points to the left are outside. 
		// We do this test using the ClassifyPoint function of Line2D

		// If the destination endpoint of the MotionPath 
		// is Not on the right side of this wall...
		if (m_Side[i].ClassifyPoint(MotionPath.EndPointB()) != Line2D::RIGHT_SIDE)
		{
			// ..and the starting endpoint of the MotionPath 
			// is Not on the left side of this wall...
			if (m_Side[i].ClassifyPoint(MotionPath.EndPointA()) != Line2D::LEFT_SIDE)
			{
				// Check to see if we intersect the wall 
				// using the Intersection function of Line2D
				Line2D::LINE_CLASSIFICATION IntersectResult = MotionPath.Intersection(m_Side[i], pPointOfIntersection);
				
				if (IntersectResult == Line2D::SEGMENTS_INTERSECT || IntersectResult == Line2D::A_BISECTS_B)
				{
					// record the link to the next adjacent cell
					// (or NULL if no attachement exists)
					// and the enumerated ID of the side we hit.
					*pNextCell = m_Link[i];
					Side = (CELL_SIDE)i;
					return (EXITING_CELL);
				}
			}
		}
		else
		{
			// The destination endpoint of the MotionPath is on the right side.
			// Increment our InteriorCount so we'll know how many walls we were
			// to the right of.
			InteriorCount++;
		}
	}

	// An InteriorCount of 3 means the destination endpoint of the MotionPath 
	// was on the right side of all walls in the cell. 
	// That means it is located within this triangle, and this is our ending cell.
	if (InteriorCount == 3)
	{
		return (ENDING_CELL);
	}

	// We only reach here is if the MotionPath does not intersect the cell at all.
	return (NO_RELATIONSHIP);
}