MCPcopy
hub / github.com/KilledByAPixel/LittleJS / setupDebugDraw

Function setupDebugDraw

plugins/box2d.js:2010–2076  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2008
2009 // box2d debug drawing
2010 function setupDebugDraw()
2011 {
2012 // setup debug draw
2013 const debugLineWidth = .1;
2014 const debugDraw = new box2d.instance.JSDraw();
2015 const box2dColor = (c)=> new Color(c.get_r(), c.get_g(), c.get_b());
2016 const box2dColorPointer = (c)=>
2017 box2dColor(box2d.instance.wrapPointer(c, box2d.instance.b2Color));
2018 const getDebugColor = (color)=>box2dColorPointer(color).scale(1,.8);
2019 const getPointsList = (vertices, vertexCount)=>
2020 {
2021 const points = [];
2022 for (let i=vertexCount; i--;)
2023 points.push(box2d.vec2FromPointer(vertices+i*8));
2024 return points;
2025 }
2026 debugDraw.DrawSegment = function(point1, point2, color)
2027 {
2028 color = getDebugColor(color);
2029 point1 = box2d.vec2FromPointer(point1);
2030 point2 = box2d.vec2FromPointer(point2);
2031 drawLine(point1, point2, debugLineWidth, color, vec2(), 0, false);
2032 };
2033 debugDraw.DrawPolygon = function(vertices, vertexCount, color)
2034 {
2035 color = getDebugColor(color);
2036 const points = getPointsList(vertices, vertexCount);
2037 drawPoly(points, CLEAR_WHITE, debugLineWidth, color, vec2(), 0, false);
2038 };
2039 debugDraw.DrawSolidPolygon = function(vertices, vertexCount, color)
2040 {
2041 color = getDebugColor(color);
2042 const points = getPointsList(vertices, vertexCount);
2043 drawPoly(points, color, 0, color, vec2(), 0, false);
2044 };
2045 debugDraw.DrawCircle = function(center, radius, color)
2046 {
2047 color = getDebugColor(color);
2048 center = box2d.vec2FromPointer(center);
2049 drawCircle(center, radius*2, CLEAR_WHITE, debugLineWidth, color, false);
2050 };
2051 debugDraw.DrawSolidCircle = function(center, radius, axis, color)
2052 {
2053 color = getDebugColor(color);
2054 center = box2d.vec2FromPointer(center);
2055 axis = box2d.vec2FromPointer(axis).scale(radius);
2056 drawCircle(center, radius*2, color, debugLineWidth, color, false);
2057 drawLine(vec2(), axis, debugLineWidth, color, center, 0, false);
2058 };
2059 debugDraw.DrawTransform = function(transform)
2060 {
2061 transform = box2d.instance.wrapPointer(transform, box2d.instance.b2Transform);
2062 const pos = box2d.vec2From(transform.get_p());
2063 const angle = -transform.get_q().GetAngle();
2064 const p1 = vec2(1,0), c1 = rgb(.75,0,0,.8);
2065 const p2 = vec2(0,1), c2 = rgb(0,.75,0,.8);
2066 drawLine(vec2(), p1, debugLineWidth, c1, pos, angle, false);
2067 drawLine(vec2(), p2, debugLineWidth, c2, pos, angle, false);

Callers 1

box2dInitFunction · 0.85

Calls 10

getDebugColorFunction · 0.85
drawLineFunction · 0.85
vec2Function · 0.85
getPointsListFunction · 0.85
drawPolyFunction · 0.85
drawCircleFunction · 0.85
rgbFunction · 0.85
vec2FromPointerMethod · 0.80
vec2FromMethod · 0.80
scaleMethod · 0.45

Tested by

no test coverage detected