UNPKG

@awayfl/poki-player

Version:

AVM Player for poki games

181 lines (180 loc) 10.3 kB
/* * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ /// Implement and register this class with a b2World to provide debug drawing of physics /// entities in your game. var b2DebugDraw = /** @class */ (function () { function b2DebugDraw() { this.m_drawScale = 1.0; this.m_lineThickness = 1.0; this.m_alpha = 1.0; this.m_fillAlpha = 1.0; this.m_xformScale = 1.0; this.m_drawFlags = 0; } //}; /// Set the drawing flags. b2DebugDraw.prototype.SetFlags = function (flags /** uint */) { this.m_drawFlags = flags; }; /// Get the drawing flags. b2DebugDraw.prototype.GetFlags = function () { return this.m_drawFlags; }; /// Append flags to the current flags. b2DebugDraw.prototype.AppendFlags = function (flags /** uint */) { this.m_drawFlags |= flags; }; /// Clear flags from the current flags. b2DebugDraw.prototype.ClearFlags = function (flags /** uint */) { this.m_drawFlags &= ~flags; }; /// Draw a closed polygon provided in CCW order. b2DebugDraw.prototype.DrawPolygon = function (vertices, vertexCount /** int */, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); for (var i /** int */ = 1; i < vertexCount; i++) { this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale); } this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); }; /// Draw a solid closed polygon provided in CCW order. b2DebugDraw.prototype.DrawSolidPolygon = function (vertices, vertexCount /** int */, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); this.m_sprite.graphics.beginFill(color.color, this.m_fillAlpha); for (var i /** int */ = 1; i < vertexCount; i++) { this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale); } this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); this.m_sprite.graphics.endFill(); }; /// Draw a circle. b2DebugDraw.prototype.DrawCircle = function (center, radius, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.drawCircle(center.x * this.m_drawScale, center.y * this.m_drawScale, radius * this.m_drawScale); }; /// Draw a solid circle. b2DebugDraw.prototype.DrawSolidCircle = function (center, radius, axis, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(0, 0); this.m_sprite.graphics.beginFill(color.color, this.m_fillAlpha); this.m_sprite.graphics.drawCircle(center.x * this.m_drawScale, center.y * this.m_drawScale, radius * this.m_drawScale); this.m_sprite.graphics.endFill(); this.m_sprite.graphics.moveTo(center.x * this.m_drawScale, center.y * this.m_drawScale); this.m_sprite.graphics.lineTo((center.x + axis.x * radius) * this.m_drawScale, (center.y + axis.y * radius) * this.m_drawScale); }; /// Draw a line segment. b2DebugDraw.prototype.DrawSegment = function (p1, p2, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(p1.x * this.m_drawScale, p1.y * this.m_drawScale); this.m_sprite.graphics.lineTo(p2.x * this.m_drawScale, p2.y * this.m_drawScale); }; /// Draw a closed polygon provided in CCW order. b2DebugDraw.prototype.DrawPolyline = function (vertices, vertexCount /** uint */, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); for (var i /** uint */ = 1; i < vertexCount; i++) { this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale); } }; /// Draw a circle arc b2DebugDraw.prototype.DrawCurve = function (p1, p2, center, color) { var s_numSegs = 16; var dx = p1.x - center.x; var dy = p1.y - center.y; var theta1 = Math.atan2(dy, dx); var theta2 = Math.atan2(p2.y - center.y, p2.x - center.x); var r = Math.sqrt(dx * dx + dy * dy); while (theta2 < theta1) theta2 += Math.PI * 2; var dtheta = (theta2 - theta1) / s_numSegs; this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(p1.x * this.m_drawScale, p1.y * this.m_drawScale); for (var theta = theta1; theta <= theta2; theta += dtheta) { this.m_sprite.graphics.lineTo((center.x + r * Math.cos(theta)) * this.m_drawScale, (center.y + r * Math.sin(theta)) * this.m_drawScale); } }; b2DebugDraw.prototype.DrawConcaveArc = function (vertices, vertexCount /** uint */, center, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(vertices[0].x, this.m_drawScale, vertices[0].y * this.m_drawScale); //Draw arc var s_numSegs = 16; var dx = vertices[0].x - center.x; var dy = vertices[0].y - center.y; var theta1 = Math.atan2(dy, dx); var theta2 = Math.atan2(vertices[1].y - center.y, vertices[1].x - center.x); var r = Math.sqrt(dx * dx + dy * dy); while (theta2 > theta1) theta2 -= Math.PI * 2; var dtheta = (theta1 - theta2) / s_numSegs; for (var theta = theta1; theta > theta2; theta -= dtheta) { this.m_sprite.graphics.lineTo((center.x + r * Math.cos(theta)) * this.m_drawScale, (center.y + r * Math.sin(theta)) * this.m_drawScale); } //Draw polyline for (var i /** uint */ = 1; i < vertexCount; i++) { this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale); } this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); }; b2DebugDraw.prototype.DrawSolidConcaveArc = function (vertices, vertexCount /** uint */, center, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); this.m_sprite.graphics.beginFill(color.color, this.m_fillAlpha); //Draw arc var s_numSegs = 16; var dx = vertices[0].x - center.x; var dy = vertices[0].y - center.y; var theta1 = Math.atan2(dy, dx); var theta2 = Math.atan2(vertices[1].y - center.y, vertices[1].x - center.x); var r = Math.sqrt(dx * dx + dy * dy); while (theta2 > theta1) theta2 -= Math.PI * 2; var dtheta = (theta1 - theta2) / s_numSegs; for (var theta = theta1; theta > theta2; theta -= dtheta) { this.m_sprite.graphics.lineTo((center.x + r * Math.cos(theta)) * this.m_drawScale, (center.y + r * Math.sin(theta)) * this.m_drawScale); } //Draw polyline for (var i /** uint */ = 1; i < vertexCount; i++) { this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale); } this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); this.m_sprite.graphics.endFill(); }; /// Draw a transform. Choose your own length scale. /// @param xf a transform. b2DebugDraw.prototype.DrawXForm = function (xf) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, 0xff0000, this.m_alpha); this.m_sprite.graphics.moveTo(xf.position.x * this.m_drawScale, xf.position.y * this.m_drawScale); this.m_sprite.graphics.lineTo((xf.position.x + this.m_xformScale * xf.R.col1.x) * this.m_drawScale, (xf.position.y + this.m_xformScale * xf.R.col1.y) * this.m_drawScale); this.m_sprite.graphics.lineStyle(this.m_lineThickness, 0x00ff00, this.m_alpha); this.m_sprite.graphics.moveTo(xf.position.x * this.m_drawScale, xf.position.y * this.m_drawScale); this.m_sprite.graphics.lineTo((xf.position.x + this.m_xformScale * xf.R.col2.x) * this.m_drawScale, (xf.position.y + this.m_xformScale * xf.R.col2.y) * this.m_drawScale); }; //virtual ~b2DebugDraw() {} //enum //{ b2DebugDraw.e_shapeBit = 0x0001; ///< draw shapes b2DebugDraw.e_jointBit = 0x0002; ///< draw joint connections b2DebugDraw.e_coreShapeBit = 0x0004; ///< draw core (TOI) shapes b2DebugDraw.e_aabbBit = 0x0008; ///< draw axis aligned bounding boxes b2DebugDraw.e_obbBit = 0x0010; ///< draw oriented bounding boxes b2DebugDraw.e_pairBit = 0x0020; ///< draw broad-phase pairs b2DebugDraw.e_centerOfMassBit = 0x0040; ///< draw center of mass frame return b2DebugDraw; }()); export { b2DebugDraw };