void CreateGrid() { Utilities.Point[] gridPoints = new Utilities.Point[destructible.nbPoint]; float gridSize = rockSize / nbVoxelPerAxis; int i = 0; for (int z = 0; z < (nbVoxelPerAxis + 1); z++) { for (int y = 0; y < (nbVoxelPerAxis + 1); y++) { for (int x = 0; x < (nbVoxelPerAxis + 1); x++) { Vector3 position = new Vector3(x * gridSize, y * gridSize, z * gridSize); gridPoints[i].pos = position; gridPoints[i].val = -1; if (x % (nbVoxelPerAxis) == 0 || y % (nbVoxelPerAxis) == 0 || z % (nbVoxelPerAxis) == 0) { gridPoints[i].val = 1; } i++; } } } destructible.GridPoints = gridPoints; destructible.UpdateMesh(); destructible.UpdateBound(); }
private void RenderHitMapPolygons(FrameState renderState) { var roomHeightSubPixels = renderState.BackgroundHeightSubPixels; var overlay = renderState.Overlay; for (var i = 0; i < overlay.NumHitMaps; i++) { var color = GetDebugColorForIndex(i); var polyCartesianSubPixels = overlay.HitMapPolygonsCartesianSubPixels[i]; for (var j = 0; j < polyCartesianSubPixels.NumVertices; j++) { var nextIx = j + 1; if (nextIx == polyCartesianSubPixels.NumVertices) { nextIx = 0; } var v1Cartesian = polyCartesianSubPixels.GetVertex(j); var v2Cartesian = polyCartesianSubPixels.GetVertex(nextIx); var v1Screen = new Utilities.Point(v1Cartesian.X, roomHeightSubPixels - v1Cartesian.Y); var v2Screen = new Utilities.Point(v2Cartesian.X, roomHeightSubPixels - v2Cartesian.Y); var v1Pixels = new Utilities.Point(v1Screen.X / PositionComponent.SUBPIXELS_PER_PIXEL, v1Screen.Y / PositionComponent.SUBPIXELS_PER_PIXEL); var v2Pixels = new Utilities.Point(v2Screen.X / PositionComponent.SUBPIXELS_PER_PIXEL, v2Screen.Y / PositionComponent.SUBPIXELS_PER_PIXEL); var v1AfterCamera = new Utilities.Point(v1Pixels.X - overlay.CameraX, v1Pixels.Y - overlay.CameraY); var v2AfterCamera = new Utilities.Point(v2Pixels.X - overlay.CameraX, v2Pixels.Y - overlay.CameraY); DrawLine(v1AfterCamera, v2AfterCamera, color); } } }
private void DrawText(string text, Utilities.Point topLeftScreen) { var fontSprite = Assets.Get(AssetNames.Font); var curPoint = topLeftScreen; foreach (var c in text) { Font.GetBounds(c, out var x, out var y); SpriteBatch.Draw(fontSprite, new Vector2((int)curPoint.X, (int)curPoint.Y), new Rectangle(x, y, Font.CHARACTER_WIDTH, Font.CHARACTER_HEIGHT), Color.White); curPoint = new Utilities.Point(curPoint.X + Font.CHARACTER_WIDTH, curPoint.Y); } }
void CreateGrid() { Utilities.Point[] gridPoints = new Utilities.Point[destructible.nbPoint]; float gridSize = rockSize / nbVoxelPerAxis; int i = 0; for (int z = 0; z < (nbVoxelPerAxis + 1); z++) { for (int y = 0; y < (nbVoxelPerAxis + 1); y++) { for (int x = 0; x < (nbVoxelPerAxis + 1); x++) { Vector3 position = new Vector3(x * gridSize, y * gridSize, z * gridSize); gridPoints[i].pos = position; Vector3 middlePos = Vector3.one * (rockSize / 2); middlePos.y = position.y; float roundValue = Vector3.Distance(position, middlePos) - (rockSize / 4); Vector3 bottomPos = position; bottomPos.y = 0; float heightValue = Vector3.Distance(position, bottomPos) / 4; float value = roundValue + heightValue + Random.Range(0.1f, 0.3f); if (value <= 0 && y == 0) { value = 1f; } gridPoints[i].val = value; i++; } } } destructible.GridPoints = gridPoints; destructible.UpdateMesh(); destructible.UpdateBound(); }
/// <summary> /// Draw a char /// </summary> /// <param name="objList"> /// The list of objects to draw /// </param> protected override void Draw(List<DrawableGameObject> objList) { foreach (DrawableGameObject gameObject in objList) { this.Draw(gameObject); this.lastPosition = new Utilities.Point(gameObject.Position); } this.Draw(new ConsoleBlank(this.lastPositionLastFrame)); this.lastPositionLastFrame = this.lastPosition; }
private void RenderTimingsGraph(FrameState state) { // this is ~1/60th of a second, so we should scale everything such that it's relative to that const double MAX_TICKS_PER_FRAME = TimeSpan.TicksPerMillisecond * 16; const int DESIRED_COLUMN_HEIGHT = 128; const int DESIRED_COLUMN_WIDTH = 4; var overlay = state.Overlay; var timings = overlay.SystemTimings; var totalWidth = timings.NumPointsTracked * DESIRED_COLUMN_WIDTH; // fill in the back, so we can see rough percents DrawRectangle(new Utilities.Point(GameState.WIDTH_HACK - totalWidth, GameState.HEIGHT_HACK - DESIRED_COLUMN_HEIGHT), totalWidth, DESIRED_COLUMN_HEIGHT, DebugColorBlack_HACK); var lastLabelY = GameState.HEIGHT_HACK; var alreadyDrawn = new System.Collections.Generic.HashSet <SystemType>(); for (var pointIx = 0; pointIx < timings.NumPointsTracked; pointIx++) { var columnX = GameState.WIDTH_HACK - totalWidth + pointIx * DESIRED_COLUMN_WIDTH; var heightSoFar = 0; foreach (SystemType system in Enum.GetValues(typeof(SystemType))) { if (system == SystemType.NONE) { continue; } var ix = (int)system; var color = GetDebugColorForIndex(ix); var ticksAtTime = timings.GetTicksForSystem(system)[pointIx]; // I'm ok with using floating point here // because these numbers are potentially quite large // and only for debugging; so FixedPoint isn't a good // fit. var percHeight = ((double)ticksAtTime) / (double)MAX_TICKS_PER_FRAME; var height = (int)Math.Round(DESIRED_COLUMN_HEIGHT * percHeight); if (height <= 0) { continue; } if (alreadyDrawn.Add(system)) { // label the thing var text = system.ToString(); var textX = GameState.WIDTH_HACK - totalWidth - text.Length * Font.CHARACTER_WIDTH; var textY = lastLabelY - Font.CHARACTER_HEIGHT; DrawText(text, new Utilities.Point(textX, textY)); lastLabelY = textY; // draw a dot to illistrate the color var dotX = textX - 2 * Font.CHARACTER_WIDTH / 3; var dotY = textY + Font.CHARACTER_HEIGHT / 3; var dotWidth = Font.CHARACTER_WIDTH / 3; var dotHeight = Font.CHARACTER_HEIGHT / 3; DrawRectangle(new Utilities.Point(dotX, dotY), dotWidth, dotHeight, color); } var topLeft = new Utilities.Point(columnX, GameState.HEIGHT_HACK - heightSoFar - height); DrawRectangle(topLeft, DESIRED_COLUMN_WIDTH, height, color); heightSoFar += height; } } void DrawRectangle(Utilities.Point topLeft, int width, int height, Texture2D color) { SpriteBatch.Draw(color, new Rectangle((int)topLeft.X, (int)topLeft.Y, width, height), Color.White); } }
private void DrawSquare(FrameState renderState, Utilities.Point pt, (int Width, int Height) dims, Texture2D color)
private void DrawText(long num, Utilities.Point topLeftScreen) { var fontSprite = Assets.Get(AssetNames.Font); var curPoint = topLeftScreen; // take care of the negative sign if (num < 0) { DrawText("-", topLeftScreen); curPoint = new Utilities.Point(curPoint.X + Font.CHARACTER_WIDTH, curPoint.Y); num = -num; } // now we move right-to-left var numWidth = MeasureTextWidth(num); curPoint = new Utilities.Point(curPoint.X + numWidth - Font.CHARACTER_WIDTH, curPoint.Y); var numChars = 0; do { // add commas every 3 digits if (numChars % 3 == 0 && numChars > 0) { DrawText(",", curPoint); curPoint = new Utilities.Point(curPoint.X - Font.CHARACTER_WIDTH, curPoint.Y); } // draw the current digit var digit = num % 10; switch (digit) { case 0: DrawText("0", curPoint); break; case 1: DrawText("1", curPoint); break; case 2: DrawText("2", curPoint); break; case 3: DrawText("3", curPoint); break; case 4: DrawText("4", curPoint); break; case 5: DrawText("5", curPoint); break; case 6: DrawText("6", curPoint); break; case 7: DrawText("7", curPoint); break; case 8: DrawText("8", curPoint); break; case 9: DrawText("9", curPoint); break; default: throw new InvalidOperationException($"Unexpected digit: {digit}"); } curPoint = new Utilities.Point(curPoint.X - Font.CHARACTER_WIDTH, curPoint.Y); numChars++; // shift a digit over num /= 10; } while (num > 0); }