Add an edge loop to the body, an edge loop connects the end points * @param {Array } points * @param {number} [density] * @param {number} [friction] * @param {number} [restitution] * @param {boolean} [isSensor]
(points, density, friction, restitution, isSensor)
| 336 | * @param {number} [restitution] |
| 337 | * @param {boolean} [isSensor] */ |
| 338 | addEdgeLoop(points, density, friction, restitution, isSensor) |
| 339 | { |
| 340 | ASSERT(isArray(points), 'points must be an array'); |
| 341 | const fixtures = [], edgePoints = []; |
| 342 | const getPoint = i=> points[mod(i,points.length)]; |
| 343 | for (let i=0; i<points.length; ++i) |
| 344 | { |
| 345 | const shape = new box2d.instance.b2EdgeShape(); |
| 346 | shape.set_m_vertex0(box2d.vec2dTo(getPoint(i-1))); |
| 347 | shape.set_m_vertex1(box2d.vec2dTo(getPoint(i+0))); |
| 348 | shape.set_m_vertex2(box2d.vec2dTo(getPoint(i+1))); |
| 349 | shape.set_m_vertex3(box2d.vec2dTo(getPoint(i+2))); |
| 350 | const f = this.addShape(shape, density, friction, restitution, isSensor); |
| 351 | fixtures.push(f); |
| 352 | i < points.length && edgePoints.push(points[i].copy()); |
| 353 | } |
| 354 | this.edgeLoops.push(edgePoints); |
| 355 | return fixtures; |
| 356 | } |
| 357 | |
| 358 | /** Destroy a fixture from the body |
| 359 | * @param {Object} [fixture] */ |