flameforge2d

revoluteJointDef.localAnchorA y-axes looks wrong


From this, I would expect the following RevoluteJoint bodyB, to be higher up than the blue box on the y-axe - setting revoluteJointDef.localAnchorA?

flame_forge2d: ^0.11.0
    class Box extends BaseBox { // just a BodyComponent for same shape
      BaseBox? boxB;
      Box(position, paint, [this.boxB]) : super(position, paint);
    
      @override
      Body createBody() {
        super.createBody();
    
        if (this.boxB != null) {
          paint.color = Colors.blue;

          final revoluteJointDef = RevoluteJointDef();
          revoluteJointDef.bodyA = body;
          revoluteJointDef.bodyB = this.boxB!.body;

          revoluteJointDef.localAnchorA.setFrom(Vector2(1, 1));

          RevoluteJoint joint = RevoluteJoint(revoluteJointDef);
          world.createJoint(joint);
        }
        return body;
      }
    }

enter image description here

I would expect it to be like this:

enter image description here


Solution

  • In flame_forge2d 0.11.0 the coordinate system was flipped on the y-axis to be the same coordinate system as Flame, so larger y-values will result in further down, instead of further up like it is in normal forge2d.

    Just negate the y-value of the anchor and you should get your intended result:

    revoluteJointDef.localAnchorA.setFrom(Vector2(1, -1));