Dart Documentationbox2d_htmlDistanceJointDef

DistanceJointDef class

Distance joint definition. This requires defining an anchor point on both bodies and the non-zero length of the distance joint. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. This helps when saving and loading a game. Warning: Do not use a zero or short length.

class DistanceJointDef extends JointDef {
  /** The local anchor point relative to body1's origin. */
  final Vector localAnchorA;

  /** The local anchor point relative to body2's origin. */
  final Vector localAnchorB;

  /** The equilibrium length between the anchor points. */
  num length;

  /**
   * The mass-spring-damper frequency in Hertz.
   */
  num frequencyHz;

  /**
   * The damping ratio. 0 = no damping, 1 = critical damping.
   */
  num dampingRatio;

  DistanceJointDef() :
    super(),
    localAnchorA = new Vector(0.0, 0.0),
    localAnchorB = new Vector(0.0, 0.0),
    length = 1.0,
    frequencyHz = 0.0,
    dampingRatio = 0.0 {
    type = JointType.DISTANCE;
  }

  /**
   * Initialize the bodies, anchors, and length using the world
   * anchors.
   * b1: First body
   * b2: Second body
   * anchor1: World anchor on first body
   * anchor2: World anchor on second body
   */
  void initialize(Body b1, Body b2, Vector anchor1, Vector anchor2) {
    bodyA = b1;
    bodyB = b2;
    localAnchorA.setFrom(bodyA.getLocalPoint(anchor1));
    localAnchorB.setFrom(bodyB.getLocalPoint(anchor2));
    Vector d = new Vector.copy(anchor2);
    d.subLocal(anchor1);
    length = d.length;
  }
}

Extends

JointDef > DistanceJointDef

Constructors

new DistanceJointDef() #

DistanceJointDef() :
  super(),
  localAnchorA = new Vector(0.0, 0.0),
  localAnchorB = new Vector(0.0, 0.0),
  length = 1.0,
  frequencyHz = 0.0,
  dampingRatio = 0.0 {
  type = JointType.DISTANCE;
}

Properties

Body bodyA #

inherited from JointDef

The first attached body.

Body bodyA;

Body bodyB #

inherited from JointDef

The second attached body.

Body bodyB;

bool collideConnected #

inherited from JointDef

Set this flag to true if the attached bodies should collide.

bool collideConnected;

num dampingRatio #

The damping ratio. 0 = no damping, 1 = critical damping.

num dampingRatio;

num frequencyHz #

The mass-spring-damper frequency in Hertz.

num frequencyHz;

num length #

The equilibrium length between the anchor points.

num length;

final Vector localAnchorA #

The local anchor point relative to body1's origin.

final Vector localAnchorA;

final Vector localAnchorB #

The local anchor point relative to body2's origin.

final Vector localAnchorB;

final Type runtimeType #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

int type #

inherited from JointDef

The joint type is set automatically for concrete joint types.

int type;

Object userData #

inherited from JointDef

Use this to attach application specific data to your joints.

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

new DistanceJointDef() #

DistanceJointDef() :
  super(),
  localAnchorA = new Vector(0.0, 0.0),
  localAnchorB = new Vector(0.0, 0.0),
  length = 1.0,
  frequencyHz = 0.0,
  dampingRatio = 0.0 {
  type = JointType.DISTANCE;
}

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();

void initialize(Body b1, Body b2, Vector anchor1, Vector anchor2) #

Initialize the bodies, anchors, and length using the world anchors. b1: First body b2: Second body anchor1: World anchor on first body anchor2: World anchor on second body

void initialize(Body b1, Body b2, Vector anchor1, Vector anchor2) {
  bodyA = b1;
  bodyB = b2;
  localAnchorA.setFrom(bodyA.getLocalPoint(anchor1));
  localAnchorB.setFrom(bodyB.getLocalPoint(anchor2));
  Vector d = new Vector.copy(anchor2);
  d.subLocal(anchor1);
  length = d.length;
}

new JointDef() #

inherited from JointDef
JointDef() :
  type = JointType.UNKNOWN,
  userData = null,
  bodyA = null,
  bodyB = null,
  collideConnected = false { }

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();

String toString() #

inherited from Object

Returns a string representation of this object.

external String toString();