Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
pathfinding [2020/11/06 10:07] – [Dimensions] admin | pathfinding [2020/11/06 10:20] – [Configuration] admin | ||
---|---|---|---|
Line 47: | Line 47: | ||
<file pascal> | <file pascal> | ||
+ | const | ||
+ | PATHFINDING_GRID_X | ||
+ | PATHFINDING_GRID_Z | ||
+ | PATHFINDING_3DSIZE_X = 20; | ||
+ | PATHFINDING_3DSIZE_Z = 20; | ||
+ | | ||
var LGridSize : TPoint; | var LGridSize : TPoint; | ||
LSize3D : TPointF; | LSize3D : TPointF; | ||
Line 97: | Line 103: | ||
FPathAnim.Enabled := true; | FPathAnim.Enabled := true; | ||
FPathAnim.Start(); | FPathAnim.Start(); | ||
+ | </ | ||
+ | |||
+ | ===== Update ===== | ||
+ | |||
+ | In case you want to update the map and path at runtime, you can use the following code snippet. | ||
+ | |||
+ | <file pascal> | ||
+ | // new computation of path | ||
+ | FPathFinder.FindPath(Point3D(5, | ||
+ | |||
+ | // refresh map in our image | ||
+ | FPathFinder.Draw(FVerifyBmp); | ||
+ | Image1.Bitmap.Assign(FVerifyBmp); | ||
+ | |||
+ | // stop the current animation | ||
+ | FPathAnim.Stop(); | ||
+ | FPathAnim.Enabled := false; | ||
+ | |||
+ | // apply computed path data to our existing TGorillaPath3D instance, instead for recreating each time | ||
+ | FPathFinder.ApplyToPath3D(FPath); | ||
+ | |||
+ | // reset the used path data in our path animation | ||
+ | FPathAnim.Path := FPath.Path; | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Visualize ===== | ||
+ | |||
+ | <file pascal> | ||
+ | LGridSize : TPoint; | ||
+ | FVerifyBmp : TBitmap; | ||
+ | |||
+ | [...] | ||
+ | |||
+ | // create a bitmap - to show map and path in a tiny image | ||
+ | // we use the adjusted grid size which includes agent width | ||
+ | LGridSize := FPathFinder.AdjustedGridSize; | ||
+ | FVerifyBmp := TBitmap.Create(LGridSize.X, | ||
+ | |||
+ | // an image component, we've placed inside of our TGorillaViewport | ||
+ | Image1.Width | ||
+ | Image1.Position.X := Form1.Width - Image1.Width - 32; | ||
+ | Image1.Height := LGridSize.Y * 4; | ||
+ | |||
+ | // draw pathfinder map | ||
+ | FPathFinder.Draw(FVerifyBmp); | ||
+ | // apply computed image to our visual feedback image in the viewport | ||
+ | Image1.Bitmap.Assign(FVerifyBmp); | ||
</ | </ |