Box2DWeb b2EdgeShape

How to make a b2EdgeShape? Making a simple b2EdgeShape. Simple boilerplate b2EdgeShape to build on top of.

My code:

Code: Select all

var bodyDef = new Box2D.Dynamics.b2BodyDef;
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
bodyDef.position.SetV(new Box2D.Common.Math.b2Vec2(250/30, 250/30));

var fixtureDef = new Box2D.Dynamics.b2FixtureDef;
fixtureDef.shape = new Box2D.Collision.Shapes.b2EdgeShape(
  new Box2D.Common.Math.b2Vec2(2.5,0),
  new Box2D.Common.Math.b2Vec2(2.5,2.5));

fixtureDef.density = 0;
fixtureDef.restitution = 0.0;
fixtureDef.friction = 0.0;

var body = world.CreateBody(bodyDef);
var fixture = body.CreateFixture(fixtureDef);
Please explain what the problem is.
Does this code run? Does it give you some error? Does it run with no errors but the result is not what you expected? How is the result different from what you expected? etc
Presumably you know all the answers to these questions already, so it would be helpful to tell us so we don't have to set up this code and try running it ourselves (hint: most likely, nobody will do that).
irresistible force wrote:Please explain what the problem is.
Does this code run? Does it give you some error? Does it run with no errors but the result is not what you expected? How is the result different from what you expected? etc
Presumably you know all the answers to these questions already, so it would be helpful to tell us so we don't have to set up this code and try running it ourselves (hint: most likely, nobody will do that).


irresistible force wrote:Please explain what the problem is.
Does this code run? Does it give you some error? Does it run with no errors but the result is not what you expected? How is the result different from what you expected? etc
Presumably you know all the answers to these questions already, so it would be helpful to tell us so we don't have to set up this code and try running it ourselves (hint: most likely, nobody will do that).


I been trying to make an b2EdgeShape, I'm asking you how to go about it:

Code: Select all

     /*TypeError: Cannot read property 'ComputeAABB' of null {stack: (...), message: "Cannot read property 'ComputeAABB' of null"}*/
     fixtureDef.shape = new Box2D.Collision.Shapes.b2EdgeShape(
       new Box2D.Common.Math.b2Vec2(2.5,0),
       new Box2D.Common.Math.b2Vec2(2.5,2.5)
     );
    
     var aabb = new Box2D.Collision.b2AABB;
     console.log("foo");
     aabb.lowerBound = new b2Vec2(2.5,0);
     aabb.upperBound = new b2Vec2(2.5,2.5);
     var mat22 = new Box2D.Common.Math.b2Mat22;
     mat22.col1 = new b2Vec2(2.5,0);
      mat22.col2 = new b2Vec2(2.5,2.5);   
     var transform =  new Box2D.Common.Math.b2Transform;
      console.log("bar"); 
     console.log(fixtureDef.shape.ComputeAABB);
     transform.position = new b2Vec2(0,0);
     console.log("foobar");
     transform.R = mat22;
     fixtureDef.shape.ComputeAABB(aabb,transform);
     console.log("baz");
    
     debugger;
Please ask a specific question, or at least answer the four that I asked.
irresistible force wrote:Please ask a specific question, or at least answer the four that I asked.


I have answer those question... The error message is in the code I paste, on the first line.

I don't know how to set an b2EdgeShape, nor do I know how to set/define a b2EdgeChainDef. I been trying.... I don't like asking others for help, but I can't figure it out. the b2EdgeChainDef point to the problem in the internal box2d source code in a function call Create on the fixtureDef....

Code: Select all

fixtureDef.Create();
when I go into the source code, I see that fixtureDef.copy is not define... I don't know what else to do.... b2EdgeShape and b2EdgeChainDef, if you know how to defined these two shape, please show a generic code example, with an optional explanation that follow, and I can figure out the rest.
Maybe this will help: https://code.google.com/p/box2dweb/issues/detail?id=31

Original thread: https://box2d.org/forum/viewtopic.php?t=9930