Skip to content

Debugging

Oğuz Eroğlu edited this page Jul 29, 2020 · 7 revisions

Visual Debugging

DebugHelper class helps programmers to visually debug their Kompute worlds. This class expects a three.js constructor for 3D rendering.

Entities

To visualise entities, their look direciton and speed:

// create a DebugHelper instance
var debugHelper = new Kompute.DebugHelper(
  world, // refers to a Kompute.World instance in which we add our elements
  threeInstance, // refers to a THREE instance
  scene // refers to a THREE.Scene instance to do the rendering on
);

// actiave the debugHelper
debugHelper.activate();

Paths

To visualise Paths:

// create an instance of DebugHelper
var debugHelper = new Kompute.DebugHelper(world, threeInstance, scene);

// create a Path
var path = new Kompute.Path();
path.addWaypoint(new Kompute.Vector3D(100, 200, 300));

// visualise the Path using debugHelper
debugHelper.visualisePath(path);

// or to specify the size of the waypoint visualisation (default size is 5 units)
// debugHelper.visualisePath(path, 15); // this visualises the waypoints with 15 units of size.

AStar Paths

Paths generated by AStar may be dynamically visualised via visualiseAStar API.

// we assume graph is an instance of Kompute.Graph

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

debugHelper.visualiseAStar(aStar);

// The path visualisation will now be automatically updated everytime AStar constructs a new path with `findShortestPath` API.

Graphs

To visualise Graphs:

// create an instance of DebugHelper
var debugHelper = new Kompute.DebugHelper(world, threeInstance, scene);

// create a Graph
var graph = new Kompute.Graph();

var v1 = new Kompute.Vector3D(10, 20, 30);
var v2 = new Kompute.Vector3D(30, 40, 50);

graph.addVertex(v1);
graph.addVertex(v2);

graph.addEdge(v1, v2);

// visualise the Graph
debugHelper.visualiseGraph(graph);

JumpDescriptors

To visualise JumpDescriptors:

// create an instance of JumpDescriptor
var jumpDescriptor = new Kompute.JumpDescriptor({
  takeoffPosition: new Kompute.Vector3D(100, 0, 0),
  landingPosition: new Kompute.Vector3D(150, 100, 0),
  runupSatisfactionRadius: 50,
  takeoffPositionSatisfactionRadius: 35,
  takeoffVelocitySatisfactionRadius: 20
});

// visualise the JumpDescriptor. This renders a 3D Bezier curve.
debugHelper.visualiseJumpDescriptor(jumpDescriptor);

Deactivating

Deactivating DebugHelper:

debugHelper.deactivate();

Logging

logger module logs the internal states of behaviors to console when activated. Note that this module is a singleton and does not need to be constructed.

Usage:

// to enable
Kompute.logger.enable();

// to disable
Kompute.logger.disable();

Clone this wiki locally