UNPKG

@box2d/debug-draw

Version:

Debug drawing helper for @box2d

145 lines (144 loc) 4 kB
"use strict"; // MIT License Object.defineProperty(exports, "__esModule", { value: true }); exports.debugColors = exports.b2Color = void 0; /** * Color for debug drawing. Each value has the range [0,1]. */ class b2Color { constructor(r = 0.5, g = 0.5, b = 0.5, a = 1) { this.r = r; this.g = g; this.b = b; this.a = a; } Clone() { return new b2Color(this.r, this.g, this.b, this.a); } Copy(other) { this.r = other.r; this.g = other.g; this.b = other.b; this.a = other.a; return this; } IsEqual(color) { return this.r === color.r && this.g === color.g && this.b === color.b && this.a === color.a; } IsZero() { return this.r === 0 && this.g === 0 && this.b === 0 && this.a === 0; } SetByteRGB(r, g, b) { this.r = r / 0xff; this.g = g / 0xff; this.b = b / 0xff; return this; } SetByteRGBA(r, g, b, a) { this.r = r / 0xff; this.g = g / 0xff; this.b = b / 0xff; this.a = a / 0xff; return this; } SetRGB(r, g, b) { this.r = r; this.g = g; this.b = b; return this; } SetRGBA(r, g, b, a) { this.r = r; this.g = g; this.b = b; this.a = a; return this; } Add(color) { this.r += color.r; this.g += color.g; this.b += color.b; this.a += color.a; return this; } Subtract(color) { this.r -= color.r; this.g -= color.g; this.b -= color.b; this.a -= color.a; return this; } Scale(s) { this.r *= s; this.g *= s; this.b *= s; this.a *= s; return this; } Mix(mixColor, strength) { b2Color.MixColors(this, mixColor, strength); } static Add(colorA, colorB, out) { out.r = colorA.r + colorB.r; out.g = colorA.g + colorB.g; out.b = colorA.b + colorB.b; out.a = colorA.a + colorB.a; return out; } static Subtract(colorA, colorB, out) { out.r = colorA.r - colorB.r; out.g = colorA.g - colorB.g; out.b = colorA.b - colorB.b; out.a = colorA.a - colorB.a; return out; } static Scale(color, s, out) { out.r = color.r * s; out.g = color.g * s; out.b = color.b * s; out.a = color.a * s; return out; } static MixColors(colorA, colorB, strength) { const dr = strength * (colorB.r - colorA.r); const dg = strength * (colorB.g - colorA.g); const db = strength * (colorB.b - colorA.b); const da = strength * (colorB.a - colorA.a); colorA.r += dr; colorA.g += dg; colorA.b += db; colorA.a += da; colorB.r -= dr; colorB.g -= dg; colorB.b -= db; colorB.a -= da; } } exports.b2Color = b2Color; b2Color.ZERO = new b2Color(0, 0, 0, 0); b2Color.RED = new b2Color(1, 0, 0); b2Color.GREEN = new b2Color(0, 1, 0); b2Color.BLUE = new b2Color(0, 0, 1); b2Color.WHITE = new b2Color(1, 1, 1); b2Color.BLACK = new b2Color(0, 0, 0); exports.debugColors = { badBody: new b2Color(1, 0, 0), disabledBody: new b2Color(0.5, 0.5, 0.3), staticBody: new b2Color(0.5, 0.9, 0.5), kinematicBody: new b2Color(0.5, 0.5, 0.9), sleepingBody: new b2Color(0.6, 0.6, 0.6), body: new b2Color(0.9, 0.7, 0.7), pair: new b2Color(0.3, 0.9, 0.9), aabb: new b2Color(0.9, 0.3, 0.9), joint1: new b2Color(0.7, 0.7, 0.7), joint2: new b2Color(0.3, 0.9, 0.3), joint3: new b2Color(0.9, 0.3, 0.3), joint4: new b2Color(0.3, 0.3, 0.9), joint5: new b2Color(0.4, 0.4, 0.4), joint6: new b2Color(0.5, 0.8, 0.8), joint7: new b2Color(0, 1, 0), joint8: new b2Color(0.8, 0.8, 0.8), rope: new b2Color(0.4, 0.5, 0.7), ropePointG: new b2Color(0.1, 0.8, 0.1), ropePointD: new b2Color(0.7, 0.2, 0.4), };