Dart Documentationbox2d_htmlDebugDraw

DebugDraw abstract class

Implement this abstract class to allow DartBox2d to automatically draw your physics for debugging purposes. Not intended to replace your own custom rendering routines! Draws shapes by default.

abstract class DebugDraw {
  // TODO(gregbglw): Draw joints once have them implemented. Also draw other
  // neat stuff described below.

  /// draw shapes
  static const int e_shapeBit = 0x0001;
  /// draw joint connections
  static const int e_jointBit = 0x0002;
  /// draw core (TimeOfImpact) shapes
  static const int e_aabbBit = 0x0004;
  /// draw axis aligned boxes
  static const int e_pairBit = 0x0008;
  /// draw center of mass 
  static const int e_centerOfMassBit = 0x0010;
  /// draw dynamic tree.
  static const int e_dynamicTreeBit = 0x0020;
  /// draw with lines (vs. default filled polygons).
  static const int e_lineDrawingBit = 0x0040;

  int flags;
  IViewportTransform viewportTransform;

  DebugDraw(IViewportTransform viewport)
      : flags = e_shapeBit,
        viewportTransform = viewport;

  void appendFlags(int value) { flags |= value; }
  void clearFlags(int value) { flags &= ~value; }

  /** Draw a closed polygon provided in CCW order. */
  abstract void drawPolygon(List<Vector> vertices, int vertexCount,
      Color3 color);

  /** Draws the given point with the given radius and color.  */
  abstract void drawPoint(Vector point, num radiusOnScreen, Color3 color);

  /** Draw a solid closed polygon provided in CCW order. */
  abstract void drawSolidPolygon(List<Vector> vertices, int vertexCount,
      Color3 color);

  /** Draw a circle. */
  abstract void drawCircle(Vector center, num radius, Color3 color,
      [Vector axis]);

  /** Draw a solid circle. */
  abstract void drawSolidCircle(Vector center, num radius, Color3 color,
      [Vector axis]);

  /** Draw a line segment. */
  abstract void drawSegment(Vector p1, Vector p2, Color3 color);

  /** Draw a transform.  Choose your own length scale. */
  abstract void drawTransform(Transform xf, Color3 color);

  /** Draw a string. */
  // TODO(dominich): font.
  abstract void drawString(num x, num y, String s, Color3 color);

  /**
   * Sets the center of the viewport to the given x and y values and the
   * viewport scale to the given scale.
   */
  void setCamera(num x, num y, num scale) {
    viewportTransform.setCamera(x,y,scale);
  }

  /**
   * Screen coordinates are specified in argScreen. These coordinates are
   * converted to World coordinates and placed in the argWorld return vector.
   */
  void getScreenToWorldToOut(Vector argScreen, Vector argWorld) {
    viewportTransform.getScreenToWorld(argScreen, argWorld);
  }

  /**
   * World coordinates are specified in argWorld. These coordinates are
   * converted to screen coordinates and placed in the argScreen return vector.
   */
  void getWorldToScreenToOut(Vector argWorld, Vector argScreen) {
    viewportTransform.getWorldToScreen(argWorld, argScreen);
  }
}

Subclasses

CanvasDraw

Constructors

new DebugDraw(IViewportTransform viewport) #

DebugDraw(IViewportTransform viewport)
    : flags = e_shapeBit,
      viewportTransform = viewport;

Static Properties

const int e_aabbBit #

draw core (TimeOfImpact) shapes

static const int e_aabbBit = 0x0004;

const int e_centerOfMassBit #

draw center of mass

static const int e_centerOfMassBit = 0x0010;

const int e_dynamicTreeBit #

draw dynamic tree.

static const int e_dynamicTreeBit = 0x0020;

const int e_jointBit #

draw joint connections

static const int e_jointBit = 0x0002;

const int e_lineDrawingBit #

draw with lines (vs. default filled polygons).

static const int e_lineDrawingBit = 0x0040;

const int e_pairBit #

draw axis aligned boxes

static const int e_pairBit = 0x0008;

const int e_shapeBit #

draw shapes

static const int e_shapeBit = 0x0001;

Properties

int flags #

int flags;

final Type runtimeType #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

IViewportTransform viewportTransform #

IViewportTransform viewportTransform;

Operators

bool operator ==(other) #

inherited from Object

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

bool operator ==(other) => identical(this, other);

Methods

void appendFlags(int value) #

void appendFlags(int value) { flags |= value; }

void clearFlags(int value) #

void clearFlags(int value) { flags &= ~value; }

new DebugDraw(IViewportTransform viewport) #

DebugDraw(IViewportTransform viewport)
    : flags = e_shapeBit,
      viewportTransform = viewport;

abstract void drawCircle(Vector center, num radius, Color3 color, [Vector axis]) #

Draw a circle.

abstract void drawPoint(Vector point, num radiusOnScreen, Color3 color) #

Draws the given point with the given radius and color.

abstract void drawPolygon(List<Vector> vertices, int vertexCount, Color3 color) #

Draw a closed polygon provided in CCW order.

abstract void drawSegment(Vector p1, Vector p2, Color3 color) #

Draw a line segment.

abstract void drawSolidCircle(Vector center, num radius, Color3 color, [Vector axis]) #

Draw a solid circle.

abstract void drawSolidPolygon(List<Vector> vertices, int vertexCount, Color3 color) #

Draw a solid closed polygon provided in CCW order.

abstract void drawString(num x, num y, String s, Color3 color) #

Draw a string.

abstract void drawTransform(Transform xf, Color3 color) #

Draw a transform. Choose your own length scale.

void getScreenToWorldToOut(Vector argScreen, Vector argWorld) #

Screen coordinates are specified in argScreen. These coordinates are converted to World coordinates and placed in the argWorld return vector.

void getScreenToWorldToOut(Vector argScreen, Vector argWorld) {
  viewportTransform.getScreenToWorld(argScreen, argWorld);
}

void getWorldToScreenToOut(Vector argWorld, Vector argScreen) #

World coordinates are specified in argWorld. These coordinates are converted to screen coordinates and placed in the argScreen return vector.

void getWorldToScreenToOut(Vector argWorld, Vector argScreen) {
  viewportTransform.getWorldToScreen(argWorld, argScreen);
}

int hashCode() #

inherited from Object

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

external int hashCode();

noSuchMethod(String name, List args) #

inherited from Object

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

external Dynamic noSuchMethod(String name, List args);

const Object() #

inherited from Object

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

const Object();

void setCamera(num x, num y, num scale) #

Sets the center of the viewport to the given x and y values and the viewport scale to the given scale.

void setCamera(num x, num y, num scale) {
  viewportTransform.setCamera(x,y,scale);
}

String toString() #

inherited from Object

Returns a string representation of this object.

external String toString();