Class Paths
raft.kilavuz.runtime
java.lang.Object
  raft.kilavuz.runtime.Paths

public class Paths
extends Object

provides static methods to create and manipulate paths. below is an overview of methods provided by this class

for performance reasons, most of the time the same PathPosition instance is returned by PathIterator's. so if you want to need that value later store it in your own instance.


Nested Class Summary
static interface
Paths.Condition
used to check if a certain condition is met.
static class
Paths.Wrapper
utility class to wrap another PathIterator which delegates calls to wrapped one.
Field Summary
static short
ANIMATE_FALLDOWN
animate falling down
static short
ANIMATE_FORWARD
animate forward step
static short
ANIMATE_NONE
no animation
static short
ANIMATE_TURN_LEFT
animate turn left step
static short
ANIMATE_TURN_RIGHT
animate turn right step
static boolean
PORTAL_EXITS_CREATE
exit points through regular portals are generated
static boolean
PORTAL_EXITS_DONT_CREATE
exit points through regular portals arent generated
Method Summary
acceleratedSegment(SimpleVector direction, SimpleVector from, SimpleVector to, short animation, float v0, float a)
creates a PathIterator which moves over a straight line with accelaration.
conditionalSegment(PathPosition pathPosition, Paths.Condition condition)
creates a conditional PathIterator.
curvedPath(Land.Point first, AStar.Path path, Land.Point last, SimpleVector currentDirection, SimpleVector lastDirection, PortalPasser portalPasser)

creates a curved path which consists bezier curves and straight lines where possible.

curvedSegment(SimpleVector p1, SimpleVector cp1, SimpleVector cp2, SimpleVector p2, float velocity, short animation)
returns a PathIterator which follows a cubic bezier curve at constant speed.
curvedSegment(Land.Point p1, Land.Point cp1, Land.Point cp2, Land.Point p2, float gridVelocity, short animation)
returns a PathIterator which follows a cubic bezier curve at constant speed all four points must be in same sector.
linearPath(Land.Point first, AStar.Path path, Land.Point last, SimpleVector currentDirection, PortalPasser portalPasser)

creates a linear path which consists of straight lines and turns at corners of lines.

linearSegment(SimpleVector direction, SimpleVector from, SimpleVector to, float velocity, short animation)
returns a PathIterator which goes linearly between given points.
linearSegment(SimpleVector direction, Land.Point from, Land.Point to, float gridVelocity, short animation)
returns a PathIterator which goes linearly between given points.
mergePaths(List<PathIterator> paths)
merges given paths into a single path
mergePaths(PathIterator... paths)
merges given paths into a single path
pathPoints(Land.Point first, AStar.Path path, Land.Point last, boolean createPortalExits)

creates a list of points to follow the given path.

turnSegment(SimpleVector from, SimpleVector to, SimpleVector location, float turnVelocity)
creates a PathIterator which horizontally (around y axis) turns at given location.
Field Detail
ANIMATE_NONE
public static final short ANIMATE_NONE
no animation

ANIMATE_FORWARD
public static final short ANIMATE_FORWARD
animate forward step

ANIMATE_TURN_LEFT
public static final short ANIMATE_TURN_LEFT
animate turn left step

ANIMATE_TURN_RIGHT
public static final short ANIMATE_TURN_RIGHT
animate turn right step

ANIMATE_FALLDOWN
public static final short ANIMATE_FALLDOWN
animate falling down

PORTAL_EXITS_CREATE
public static final boolean PORTAL_EXITS_CREATE
exit points through regular portals are generated

PORTAL_EXITS_DONT_CREATE
public static final boolean PORTAL_EXITS_DONT_CREATE
exit points through regular portals arent generated
Method Detail
pathPoints
public static List<Land.PointpathPoints(Land.Point first,
                                          AStar.Path path,
                                          Land.Point last,
                                          boolean createPortalExits)

creates a list of points to follow the given path. the created points (other than portal exits) marks the corners to which the unit can go straight.

for non-regular portals always there are two succesive points on result regardless of createPortalExits variable. for regular portals exit points are created as follows:

  • if no action is required to pass through a portal, a point is created on the intersection point of sector boundary and the line connects previous and next points. note, although the point is on border of two sectors, it belongs to first sector. same point in next sector can be retrieved from Point.getPointOnAdjacentSector
  • if an action is required to pass through a portal, a point is created on the intersection line as a no-action portal. a second point is created in the next sector half units away from former created point
Parameters:
first - first point on path, ie the location of path finding unit
path - found path
last - last point on path, ie the destination location of path finding unit
createPortalExits - if true points through regular portal exits are also created note without them, returned Points are corners of the path. portal exits doesnt change the shape of path
Returns:
an unmodifiable view of points to follow the given path
Throws:
ClassCastException - if path is not created for Land
IllegalArgumentException - if first point in first sector or last point is not in last sector
See Also:

linearPath
public static PathIterator linearPath(Land.Point first,
                                      AStar.Path path,
                                      Land.Point last,
                                      SimpleVector currentDirection,
                                      PortalPasser portalPasser)

creates a linear path which consists of straight lines and turns at corners of lines. move and turn speed is taken from PathContext encapsulated in path. the returned path will try to stay away from corners and sides by PathContext.distanceToEdges. note this may not always possible if very small sectors are on the way

note here straight means straight from top view, elevations are calculated along the path so the unit can nicely follow the terrain.

Parameters:
first - first point on path, ie the location of path finding unit
path - found path
last - last point on path, ie the destination location of path finding unit
currentDirection - current direction of path finding unit
portalPasser - for portals which require sepecific action, corresponding path segments are created with this factory. if null is passed, or factory returns null for a segment, a default implementation which just skips to end point is used
Returns:
an executable path
Throws:
ClassCastException - if path is not created for Land
IllegalArgumentException - if first point in first sector or last point is not in last sector, or velocity or turnVelocity <= 0
See Also:

curvedPath
public static PathIterator curvedPath(Land.Point first,
                                      AStar.Path path,
                                      Land.Point last,
                                      SimpleVector currentDirection,
                                      SimpleVector lastDirection,
                                      PortalPasser portalPasser)

creates a curved path which consists bezier curves and straight lines where possible. move speed is taken from PathContext encapsulated in path. curvature is defined by PathContext.distanceToEdges

the returned path follows the curve at constant speed no matter what the curvature is. this is done by internally accumulating small curve segments and hence is somehow expensive. to reduce cost straight lines are used whereever possible. elevations are calculated along the path so the unit can nicely follow the terrain.

note, the returned path is guaranteed to stay in sectors which the original path goes through. but if very small sectors are on the way distanceToEdges may not be honored

also note, specifying a current and last direction which is just (or almost) the opposite to direction of next/previous segment may result in very ugly turns. this method doesnt make any attempt to fix such case. if required one may explicitly create a turn or curved segment and merge it with the returned path

Parameters:
first - first point on path, ie the location of path finding unit
path - found path
last - last point on path, ie the destination location of path finding unit
currentDirection - current direction of path finding unit, may be null.
lastDirection - last direction in path, may be null
portalPasser - for portals which require sepecific action, corresponding path segments are created with this factory. if null is passed, or factory returns null for a segment, a default implementation which just skips to end point is used
Returns:
an executable path
Throws:
ClassCastException - if path is not created for Land
IllegalArgumentException - if first point in first sector or last point is not in last sector, or velocity or turnVelocity <= 0
See Also:

turnSegment
public static PathIterator turnSegment(SimpleVector from,
                                       SimpleVector to,
                                       SimpleVector location,
                                       float turnVelocity)
creates a PathIterator which horizontally (around y axis) turns at given location. decides which direction is shorter
Parameters:
from - initialDirection
to - lastDirection
location - where turn will occur
turnVelocity - turn velocity in radians per second, must be positive

linearSegment
public static PathIterator linearSegment(SimpleVector direction,
                                         SimpleVector from,
                                         SimpleVector to,
                                         float velocity,
                                         short animation)
returns a PathIterator which goes linearly between given points. this method does not take elevations into account.
Parameters:
direction - direction in move, if null the horizontal part of vector from-to is used. if horizontal part is empty, then (0,0,1) is used
from - initial location
to - last location
velocity - move velocity in world units per second, must be positive
animation - animation used in this segment

linearSegment
public static PathIterator linearSegment(SimpleVector direction,
                                         Land.Point from,
                                         Land.Point to,
                                         float gridVelocity,
                                         short animation)
returns a PathIterator which goes linearly between given points. from and to must be in same sector. this method takes elevations into account.
Parameters:
direction - direction in move, if null the horizontal part of vector from-to is used. if horizontal part is empty, then (0,0,1) is used
from - initial location
to - last location
gridVelocity - move velocity in grid units per second, must be positive
animation - animation used in this segment
Throws:
IllegalArgumentException - if two points are not in same sector

curvedSegment
public static PathIterator curvedSegment(SimpleVector p1,
                                         SimpleVector cp1,
                                         SimpleVector cp2,
                                         SimpleVector p2,
                                         float velocity,
                                         short animation)
returns a PathIterator which follows a cubic bezier curve at constant speed. this method does not take elevations into account.
Parameters:
p1 - first point on curve
cp1 - first control point
cp2 - second control point
p2 - last point on curve
velocity - move velocity in world units per second, must be positive
animation - animation used in this segment

curvedSegment
public static PathIterator curvedSegment(Land.Point p1,
                                         Land.Point cp1,
                                         Land.Point cp2,
                                         Land.Point p2,
                                         float gridVelocity,
                                         short animation)
returns a PathIterator which follows a cubic bezier curve at constant speed all four points must be in same sector. this method takes elevations into account.
Parameters:
p1 - first point on curve
cp1 - first control point
cp2 - second control point
p2 - last point on curve
gridVelocity - move velocity in grid units per second, must be positive
animation - animation used in this segment
Throws:
IllegalArgumentException - if all four points are not in same sector

acceleratedSegment
public static PathIterator acceleratedSegment(SimpleVector direction,
                                              SimpleVector from,
                                              SimpleVector to,
                                              short animation,
                                              float v0,
                                              float a)
creates a PathIterator which moves over a straight line with accelaration.
Parameters:
direction - direction in move
from - source location
to - destination location
animation - animation during this segment
v0 - initial velocity
a - acceleration
Throws:
IllegalArgumentException - if unit cannot reach destination point with given initial velocity and acceleration

conditionalSegment
public static PathIterator conditionalSegment(PathPosition pathPosition,
                                              Paths.Condition condition)
creates a conditional PathIterator. conditional iterators returns true for hasNext() and UNDEFINED for remaining() until the condition is met. they're typically used for pausing path execution until some specific event occurs (for example wait for an elevator to arrive)
Parameters:
pathPosition - the point on path which is used while waiting for condition met
condition - waited event
See Also:

mergePaths
public static PathIterator mergePaths(PathIterator... paths)
merges given paths into a single path

mergePaths
public static PathIterator mergePaths(List<PathIterator> paths)
merges given paths into a single path
Java API documentation generated with DocFlex/Doclet v1.5.2
DocFlex/Doclet is both a multi-format Javadoc doclet and a free edition of DocFlex/Javadoc. If you need to customize your Javadoc without writing a full-blown doclet from scratch, DocFlex/Javadoc may be the only tool able to help you! Find out more at www.docflex.com