// This function is called from the motion planner. It is // used to check for collisions between an edge between // nodes n1 and n2, and a wall segment. // The function uses an iterative approach by moving along // the edge a "safe" distance, defined to be the shortest distance // to the wall segment, until the end of the edge is reached or // a collision occurs. public bool CollisionFound(Navigation.Node n1, Navigation.Node n2, double tol) { // Check that within boundaries if (n2.x > maxWorkspaceX || n2.x < minWorkspaceX || n2.y > maxWorkspaceY || n2.y < minWorkspaceY) { return(true); } // Check for collision with walls double theta = Math.Atan2(n2.y - n1.y, n2.x - n1.x); double edgeSize = Math.Sqrt(Math.Pow(n2.y - n1.y, 2) + Math.Pow(n2.x - n1.x, 2)); double sinTheta = Math.Sin(theta); double cosTheta = Math.Cos(theta); // Loop through segments for (int segment = 0; segment < numMapSegments; segment++) { double distTravelledOnEdge = 0; double ex = n1.x, ey = n1.y; double distToSegment; while (distTravelledOnEdge - tol < edgeSize) { distToSegment = GetWallDistance(ex, ey, segment, tol, n2.x, n2.y); if (distToSegment - tol < 0.05) { return(true); } ex += cosTheta * distToSegment; ey += sinTheta * distToSegment; distTravelledOnEdge += distToSegment; } } return(false); }
/// <summary> /// Get the next node in the current room and walk to it. /// </summary> /// <returns>False if the path to the room node is rejected, True otherwise.</returns> private bool GoToNextRoomNode() { Navigation.Node node = roomNodes.Pop(); return(monster.navigation.StartPath(node)); }