Skip to content
Oğuz Eroğlu edited this page Jun 15, 2020 · 7 revisions

Definition

Graph is a Kompute implementation of the Graph data structure. Kompute Graphs are implemented as directed graph and weights of the edges are calculated based on the distance between two vertices. Graphs may be consumed via RandomPathBehavior.

AStar class may be used in order to generate the most optimal Path from one vertex of the Graph to another.

Usage

// create an instance of Graph
var graph = new Kompute.Graph();

// define vertices
var vertex1 = new Kompute.Vector3D(10, 20, 30);
var vertex2 = new Kompute.Vector3D(40, 50, 60);

// insert vertices into Graph
graph.addVertex(vertex1);
graph.addVertex(vertex2);

// add an egde from vertex1 to vertex2
// The weight of this edge would be the distance between vertex1 and vertex2
graph.addEdge(vertex1, vertex2);

Graphs are designed to be used by a single steerable. In order to use the same graph for multiple steerables, they should be cloned first:

// The clonedGraph may be consumed by another Steerable via RandomPathBehavior or manually.
var clonedGraph = graph.clone();

Inserting into the World

Graphs need to be inserted into the world in order to be properly consumed by the RandomPathBehavior. This is a must because of the performance optimisations for findClosestVertexToPoint API used by the RandomPathBehavior.

// create a World
var world = new Kompute.World(1000, 1000, 1000, 10);

// insert the Graph into the World
world.insertGraph(graph);

Inserting a JumpDescriptor

An instance of JumpDescriptor may be inserted into Graph in order to automatically trigger a jump while applying RandomPathBehavior or constructing a Path via AStar. To successfully insert a JumpDescriptor into a Graph, both landingPosition and takeoffPosition has to be present as vertices in the Graph. If there's no edge present from landingPosition to takeoffPosition, an edge is automatically created while inserting the JumpDescriptor.

// create an instance of JumpDescriptor
var jumpDescriptor = new Kompute.JumpDescriptor({
  takeoffPosition: vertex, landingPosition: vertex2,
  runupSatisfactionRadius: 100, takeoffPositionSatisfactionRadius: 100,
  takeoffVelocitySatisfactionRadius: 100
});

// add the jump descriptor to the graph
graph.addJumpDescriptor(jumpDescriptor)

Visualising

Graphs may be visualised for debugging purposes via DebugHelper. See here.

Clone this wiki locally