MCPcopy Index your code
hub / github.com/KilledByAPixel/LittleJS / addEdgeLoop

Method addEdgeLoop

plugins/box2d.js:338–356  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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] */

Callers

nothing calls this directly

Calls 5

addShapeMethod · 0.95
isArrayFunction · 0.85
vec2dToMethod · 0.80
ASSERTFunction · 0.50
copyMethod · 0.45

Tested by

no test coverage detected