kripken / ammo.js

Direct port of the Bullet physics engine to JavaScript using Emscripten
Other
4.14k stars 558 forks source link

Constructors. #14

Open schteppe opened 12 years ago

schteppe commented 12 years ago

I was just wondering, is it possible to use other constructors of Bullet classes than the first?

For example, the btHingeConstraint. It's got four constructors:

new Ammo.btHingeConstraint (rbA, rbB, pivotInA, pivotInB, axisInA, axisInB, useReferenceFrameA)
new Ammo.btHingeConstraint (rbA, pivotInA, axisInA, useReferenceFrameA)
new Ammo.btHingeConstraint (rbA, rbB, rbAFrame, rbBFrame, useReferenceFrameA)
new Ammo.btHingeConstraint (rbA, rbAFrame, useReferenceFrameA)

(See http://www.bulletphysics.com/Bullet/BulletFull/classbtHingeConstraint.html for full doc.)

The first constructor seems to work (see the ragdoll demo), but nothing happens when I try any other constructor. Did I miss something obvious here?

kripken commented 12 years ago

It should be possible to use different overloaded constructors, assuming they are differentiated by the number of parameters.

For btHingeConstraint, looking in the generated code (bullet/build/bindings.js or builds/ammo.new.js - they only exist if you build locally though), there is

function btHingeConstraint(arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
  if (arg3 === undefined)
    this.ptr = _emscripten_bind_btHingeConstraint__btHingeConstraint_p3(arg0.ptr, arg1.ptr, arg2.ptr);
  else   if (arg4 === undefined)
    this.ptr = _emscripten_bind_btHingeConstraint__btHingeConstraint_p4(arg0.ptr, arg1.ptr, arg2.ptr, arg3);
  else   if (arg6 === undefined)
    this.ptr = _emscripten_bind_btHingeConstraint__btHingeConstraint_p6(arg0.ptr, arg1.ptr, arg2.ptr, arg3.ptr, arg4.ptr, arg5.ptr);
  else 
    this.ptr = _emscripten_bind_btHingeConstraint__btHingeConstraint_p7(arg0.ptr, arg1.ptr, arg2.ptr, arg3.ptr, arg4.ptr, arg5.ptr, arg6);
  btHingeConstraint.prototype.__cache__[this.ptr] = this;
  this.__class__ = btHingeConstraint;
}

which looks like it handles the 4 cases. Or at least tries to - I haven't tested it myself ;)

Can you provide a testcase that shows the problem you are seeing?

schteppe commented 12 years ago

After working some more with this, I realized there is nothing wrong with the constructors. I can use the two first constructors without problem, see my double pendulum at: http://granular.cs.umu.se/ammo/Demos/PendulumDemo/

I cannot seem to be able to use the 3rd or 4th constructor though (which uses local frames). No matter how I use them, the constraint seem to be unsolveable and blow up.

I have tried to port the Ragdolldemo from the original Bullet Physics trunk and also this simple demo: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=3191, without success.

I'm fine with using pivots and axes, but I find it annoying to not be able to use frames. I'll do some more testing and come back.

Did anyone else try to use the frame-based hinge constraints?

RodrigoHamuy commented 7 years ago

Hi @schteppe , did you found the issue with this? I was trying to port the FokLiftDemo from Bullet and it uses the frame-based btHingeConstraint. Whenever I apply this hinge my objects will get NaN positions.

schteppe commented 7 years ago

@RodrigoHamuy it was a loooong time ago... Don't really remember. If I solved it back then, you can probably find the solution here: https://github.com/schteppe/ammo.js-demos

RodrigoHamuy commented 7 years ago

Thanks @schteppe ! The frame based constructor is there now. The issue for me was that it didn't work if you set the hinge limit to 0,0. Instead, I use 0.0001 now and it works. Anyway, yeah, this is a super old issue, thanks for answering!

bberak commented 4 years ago

Hey @RodrigoHamuy can you give some more details about your fix? I've set my limits to 0.0001 but I'm still getting NaN values for my body transformations..