@Deprecated //Use EntityNavigationManager.revolveMotionNewWay
public Cell ResolveMotionOnMesh(Vector3f StartPos, Cell StartCell, Vector3f EndPos) {
// create a 2D motion path from our Start and End positions, tossing out
// their Y values to project them
// down to the XZ plane.
Line2D MotionPath = new Line2D(new Vector2f(StartPos.x, StartPos.z),
new Vector2f(EndPos.x, EndPos.z));
// these three will hold the results of our tests against the cell walls
ClassifyResult Result = null;
// TestCell is the cell we are currently examining.
Cell TestCell = StartCell;
// do {
// i++;
// use NavigationCell to determine how our path and cell interact
// if(TestCell.IsPointInCellCollumn(MotionPath.EndPointA()))
// System.out.println("Start is in cell:"+TestCell);
// else
// System.out.println("Start is NOT in cell:"+TestCell);
// if(TestCell.IsPointInCellCollumn(MotionPath.EndPointB()))
// System.out.println("End is in cell:"+TestCell);
// else
// System.out.println("End is NOT in cell:"+TestCell);
Result = TestCell.ClassifyPathToCell(MotionPath);
// if exiting the cell...
if (Result.result == Cell.PATH_RESULT.EXITING_CELL) {
// Set if we are moving to an adjacent cell or we have hit a
// solid (unlinked) edge
if (Result.cell != null) {
// moving on. Set our motion origin to the point of
// intersection with this cell
// and continue, using the new cell as our test cell.
MotionPath.SetEndPointA(Result.intersection);
TestCell = Result.cell;
} else {
//FIXME this could also be the case of switching meshes :-< check this !!
// Cell c = Singleton.get().getNavManager().FindClosestCell(EndPos, true);
// if(c!= null && c != TestCell){
////System.out.println("Mesh switching");
// TestCell =c;
// }
// else{
//FIXME thid should push the entity more away from a wall than it does at the moment and make it move more perpendicular to the wall
//System.out.println("Hitting a wall!");
// we have hit a solid wall. Resolve the collision and
// correct our path.
MotionPath.SetEndPointA(Result.intersection);
TestCell.ProjectPathOnCellWall(Result.side, MotionPath);
// add some friction to the new MotionPath since we are
// scraping against a wall.
// we do this by reducing the magnatude of our motion by 10%
Vector2f Direction = MotionPath.EndPointB().subtract(
MotionPath.EndPointA()).mult(0.9f);
// Direction.mult(0.9f);
MotionPath.SetEndPointB(MotionPath.EndPointA().add(
Direction));
// }
}
} else if (Result.result == Cell.PATH_RESULT.NO_RELATIONSHIP) {
//System.out.println("NO RELATION");
//FIXME this could also be the case of optimized meshes
// Cell c =Singleton.get().getNavManager().FindClosestCell(EndPos, true);
// if(c!= null && c != TestCell){
// TestCell =c;
// } else {
// Although theoretically we should never encounter this case,
// we do sometimes find ourselves standing directly on a vertex
// of the cell.
// This can be viewed by some routines as being outside the
// cell.
// To accomodate this rare case, we can force our starting point
// to be within
// the current cell by nudging it back so we may continue.
Vector2f NewOrigin = MotionPath.EndPointA();
TestCell.ForcePointToCellCollumn(NewOrigin);
// MotionPath.SetEndPointA(NewOrigin);
//we do not want to iterate we just want them to stop at the wall and not cet out
MotionPath.SetEndPointB(NewOrigin);
// }