Multiple constraints vs user constraint

30 views
Skip to first unread message

Andy Croft

unread,
May 9, 2017, 2:55:47 PM5/9/17
to Nape Physics
My scenario involves a series of bodies linked together in a chain-like fashion.  The goal is to create a "greenstick" object that is pliable but not rope-like in regards to how the joints behave.  An example might be a diving board or a bent paperclip. 

I'm working in AS3.  I'll try to be concise, my questions are in bold orange.  Any guidance would be greatly appreciated :)

I'm trying to devise an efficient method of combining the following constraint effects:
  • PivotJoint: stiff, end-to-end join between two bodies
  • AngleJoint: narrow angle of min/max to limit the chain looping back onto itself (hopefully)
  • WeldJoint: elastic, high frequency… hope to create an "angular tension" between two bodies
Initially I made a class containing those three constraint types.  The class provided an interface to easily link the two bodiesIt works but it seems inefficient to have a class containing three separate constraints that the simulation will iterate over to accomplish ONE goal. 

A UserConstraint seems the logical choice, it could handle all the calculations in a single object.  Unfortunately, I am having a hard time understanding how the interface works in overriding the predefined function calls.

Looking at the documentation (Constraints.pdf), I attempted to combine the example Pivot and Angle joints and was confounded. 
  • Override Functions: I understand the "override functions" pass an array/vector of numbers to be initialized/manipulated.  These values are used internally somehow in the sausage-factory of physics. 
    • How are the dimensions and content of these arrays determined?  For instance, comparing the PivotJoint to the AngleJoint:
      PivotJoint: Page 13 in Constraints.pdf
      override public function __position(err:Vector.<Number>):void
      {
          err
      [0] = (body2.position.x + _rel2.x) - (body1.position.x + _
      rel1.x);
          err
      [1] = (body2.position.y + _rel2.y) - (body1.position.y + _rel1.y);
      }//END FUNCTION: __position

      AngleJoint: Page 14 in Constraints.pdf
      override public function __position(err:Vector.<Number>):void
      {
          err
      [0] = error; //determined in __prepare() function already
      }//END FUNCTION: __position
  • HAXE vs AS3: Looking at the AngleJoint example in the documentation, I see a Vec3 accessing a property named w.  I assume this is the "scalar weight" mentioned under the definition of the AngleJoint (page 6).
    public override function __velocity(err:TArray<Float>):Void {
        var v1 = body1.constraintVelocity;
        var v2 = body2.constraintVelocity;
        err[0] = (weight * (ratio * v2.w)) - v1.w;
    }
    • Is there an equivalent property in AS3?
    • If not, will this confound my effort to emulate the AngleJoint?


Reply all
Reply to author
Forward
0 new messages