box2d.js icon indicating copy to clipboard operation
box2d.js copied to clipboard

"b2MassData" is not bound / is not accessible.

Open Joncom opened this issue 12 years ago • 4 comments
trafficstars

Test case:

  1. Open up box2d.js/html5canvas_demo/testbed.html in browser.
  2. You should now be looking at the "dominos" test.
  3. Type massData = new Box2D.b2MassData(); in console.

Error: TypeError: undefined is not a function

Joncom avatar Jul 15 '13 20:07 Joncom

You can "trick" the old bindings generator into generating code for something by making it a class with a constructor. This makes it be bound, but I did not test beyond seeing it shows up as Box2D.b2MassData:

class b2MassData
{
public:
  b2MassData() {}

    /// The mass of the shape, usually in kilograms.
    float32 mass;

    /// The position of the shape's centroid relative to the shape's origin.
    b2Vec2 center;

    /// The rotational inertia of the shape about the local origin.
    float32 I;
};

kripken avatar Jul 16 '13 18:07 kripken

Yes, that's correct. Do you suggest this "trick" as an official fix? Although it may work in this instance, it does not seem viable for other similar cases. For example, b2Manifold is also unbound, but it will not work here. It seems that it fails because the struct in this case contains an enum.

Not sure why it makes a difference but it does...

struct b2Manifold
{
    b2Manifold() {}

    enum Type
    {
        e_circles,
        e_faceA,
        e_faceB
    };

    b2ManifoldPoint points[b2_maxManifoldPoints];   ///< the points of contact
    b2Vec2 localNormal;                             ///< not use for Type::e_points
    b2Vec2 localPoint;                              ///< usage depends on manifold type
    Type type;
    int32 pointCount;                               ///< the number of manifold points
};

Sorry for not providing an exact error message. I'm simply recalling from memory the events I experienced with your port a couple weeks ago.

Joncom avatar Jul 17 '13 05:07 Joncom

Same here, I wanted to change the mass of an object during the execution but I cant see how is it possible if b2MassData is not visible.

jagenjo avatar Jul 17 '13 15:07 jagenjo

It could be an official fix, yeah ;) the problem is the old bindings generator needs hacks like this to work, that's why moving to embind is a good idea.

An enum should not matter, but perhaps I forgot yet another weirdness in the old bindings generator. If you move the enum of out if, does it work? My first guess is that the issue is either that it is a struct and not a class, or that points' length depends on a variable (making it a C constant might help).

On Wed, Jul 17, 2013 at 8:57 AM, jagenjo [email protected] wrote:

Same here, I wanted to change the mass of an object during the execution but I cant see how is it possible if b2MassData is not visible.

— Reply to this email directly or view it on GitHubhttps://github.com/kripken/box2d.js/issues/38#issuecomment-21123335 .

kripken avatar Jul 19 '13 21:07 kripken