Dart Documentationbox2d_htmlFixture

Fixture class

A fixture is used to attach a shape to a body for collision detection. You cannot reuse fixtures.

class Fixture {
  final AxisAlignedBox box;

  num density;

  Fixture next;

  Body body;

  Shape shape;

  num friction;

  num restitution;

  DynamicTreeNode proxy;

  final Filter filter;

  bool isSensor;

  Object userData;

  final AxisAlignedBox _poolOne;
  final AxisAlignedBox _poolTwo;

  /**
   * Constructs a new Fixture with default values.
   */
  Fixture()
      : box = new AxisAlignedBox(),
        body = null,
        next = null,
        proxy = null,
        shape = null,
        filter = new Filter(),
        _poolOne = new AxisAlignedBox(),
        _poolTwo = new AxisAlignedBox();

  /**
   * Sets this fixture according to the given body and definition.
   */
  void create(Body b, FixtureDef def) {
    userData = def.userData;
    friction = def.friction;
    restitution = def.restitution;

    body = b;
    next = null;

    filter.setFrom(def.filter);

    isSensor = def.isSensor;

    shape = def.shape.clone();

    density = def.density;
  }

  /**
   * Destroys this fixture. Before being called, this shape's proxy must be
   * destroyed. After being called, this fixture's shape is null.
   */
  void destroy() {
    // The proxy must be destroyed before calling this.
    assert(proxy == null);

    // Free the child shape.
    shape = null;
  }

  /** These support body activation/deactivation. */
  void createProxy(BroadPhase broadPhase, Transform xf){
    assert(proxy == null);

    // Create proxy in the broad-phase.
    shape.computeAxisAlignedBox(box, xf);
    proxy = broadPhase.createProxy(box, this);
  }

  /**
   * Destroys this Fixture's proxy.
   */
  void destroyProxy(BroadPhase broadPhase) {
    // If proxy is already destroyed, do nothing.
    if (proxy == null) {
      return;
    }

    // Destroy the proxy.
    broadPhase.destroyProxy(proxy);
    proxy = null;
  }

  //TODO(gregbglw): Write comment once know what does.
  void synchronize(BroadPhase broadPhase, Transform transformOne,
      Transform transformTwo) {
    if (proxy == null) {
      return;
    }

    // Compute an Axis Aligned Box that covers the swept shape.
    shape.computeAxisAlignedBox(_poolOne, transformOne);
    shape.computeAxisAlignedBox(_poolTwo, transformTwo);
    box.lowerBound.x = _poolOne.lowerBound.x < _poolTwo.lowerBound.x ? 
        _poolOne.lowerBound.x : _poolTwo.lowerBound.x;
    box.lowerBound.y = _poolOne.lowerBound.y < _poolTwo.lowerBound.y ?
        _poolOne.lowerBound.y : _poolTwo.lowerBound.y;
    box.upperBound.x = _poolOne.upperBound.x > _poolTwo.upperBound.x ?
        _poolOne.upperBound.x : _poolTwo.upperBound.x;
    box.upperBound.y = _poolOne.upperBound.y > _poolTwo.upperBound.y ?
        _poolOne.upperBound.y : _poolTwo.upperBound.y;

    Vector disp = _poolOne.lowerBound;
    disp.x = transformTwo.position.x - transformOne.position.x;
    disp.y = transformTwo.position.y - transformOne.position.y;

    broadPhase.moveProxy(proxy, box, disp);
  }

  /**
   * Get the mass data for this fixture. The mass data is based on the density
   * and the shape. The rotational inertia is about the shape's origin.
   */
  void getMassData(MassData massData) {
    shape.computeMass(massData, density);
  }

  /**
   * Get the type of the child shape.
   */
  int get type() {
    return shape.type;
  }
}

Constructors

new Fixture() #

Constructs a new Fixture with default values.

Fixture()
    : box = new AxisAlignedBox(),
      body = null,
      next = null,
      proxy = null,
      shape = null,
      filter = new Filter(),
      _poolOne = new AxisAlignedBox(),
      _poolTwo = new AxisAlignedBox();

Properties

Body body #

Body body;

final AxisAlignedBox box #

final AxisAlignedBox box;

num density #

num density;

final Filter filter #

final Filter filter;

num friction #

num friction;

bool isSensor #

bool isSensor;

Fixture next #

Fixture next;

DynamicTreeNode proxy #

DynamicTreeNode proxy;

num restitution #

num restitution;

final Type runtimeType #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

Shape shape #

Shape shape;

final int type #

Get the type of the child shape.

int get type() {
  return shape.type;
}

Object userData #

Object userData;

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 create(Body b, FixtureDef def) #

Sets this fixture according to the given body and definition.

void create(Body b, FixtureDef def) {
  userData = def.userData;
  friction = def.friction;
  restitution = def.restitution;

  body = b;
  next = null;

  filter.setFrom(def.filter);

  isSensor = def.isSensor;

  shape = def.shape.clone();

  density = def.density;
}

void createProxy(BroadPhase broadPhase, Transform xf) #

These support body activation/deactivation.

void createProxy(BroadPhase broadPhase, Transform xf){
  assert(proxy == null);

  // Create proxy in the broad-phase.
  shape.computeAxisAlignedBox(box, xf);
  proxy = broadPhase.createProxy(box, this);
}

void destroy() #

Destroys this fixture. Before being called, this shape's proxy must be destroyed. After being called, this fixture's shape is null.

void destroy() {
  // The proxy must be destroyed before calling this.
  assert(proxy == null);

  // Free the child shape.
  shape = null;
}

void destroyProxy(BroadPhase broadPhase) #

Destroys this Fixture's proxy.

void destroyProxy(BroadPhase broadPhase) {
  // If proxy is already destroyed, do nothing.
  if (proxy == null) {
    return;
  }

  // Destroy the proxy.
  broadPhase.destroyProxy(proxy);
  proxy = null;
}

new Fixture() #

Constructs a new Fixture with default values.

Fixture()
    : box = new AxisAlignedBox(),
      body = null,
      next = null,
      proxy = null,
      shape = null,
      filter = new Filter(),
      _poolOne = new AxisAlignedBox(),
      _poolTwo = new AxisAlignedBox();

void getMassData(MassData massData) #

Get the mass data for this fixture. The mass data is based on the density and the shape. The rotational inertia is about the shape's origin.

void getMassData(MassData massData) {
  shape.computeMass(massData, density);
}

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 synchronize(BroadPhase broadPhase, Transform transformOne, Transform transformTwo) #

void synchronize(BroadPhase broadPhase, Transform transformOne,
    Transform transformTwo) {
  if (proxy == null) {
    return;
  }

  // Compute an Axis Aligned Box that covers the swept shape.
  shape.computeAxisAlignedBox(_poolOne, transformOne);
  shape.computeAxisAlignedBox(_poolTwo, transformTwo);
  box.lowerBound.x = _poolOne.lowerBound.x < _poolTwo.lowerBound.x ? 
      _poolOne.lowerBound.x : _poolTwo.lowerBound.x;
  box.lowerBound.y = _poolOne.lowerBound.y < _poolTwo.lowerBound.y ?
      _poolOne.lowerBound.y : _poolTwo.lowerBound.y;
  box.upperBound.x = _poolOne.upperBound.x > _poolTwo.upperBound.x ?
      _poolOne.upperBound.x : _poolTwo.upperBound.x;
  box.upperBound.y = _poolOne.upperBound.y > _poolTwo.upperBound.y ?
      _poolOne.upperBound.y : _poolTwo.upperBound.y;

  Vector disp = _poolOne.lowerBound;
  disp.x = transformTwo.position.x - transformOne.position.x;
  disp.y = transformTwo.position.y - transformOne.position.y;

  broadPhase.moveProxy(proxy, box, disp);
}

String toString() #

inherited from Object

Returns a string representation of this object.

external String toString();