public static void DrawTriangles(PrimitiveBatch primitiveBatch, Vector2 position, Vector2[] outVertices, int[] outIndices, Color color, bool outline = true) { if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } //int count = vertices.Length; //if (count == 2) //{ // DrawPolygon(position, vertices, color); // return; //} Color colorFill = color * (outline ? 0.5f : 1.0f); //Vector2[] outVertices; //int[] outIndices; //Triangulator.Triangulate(vertices, WindingOrder.CounterClockwise, out outVertices, out outIndices); //var position = Vector2.Zero; for (int i = 0; i < outIndices.Length - 2; i += 3) { primitiveBatch.AddVertex(new Vector2(outVertices[outIndices[i]].X + position.X, outVertices[outIndices[i]].Y + position.Y), colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(new Vector2(outVertices[outIndices[i + 1]].X + position.X, outVertices[outIndices[i + 1]].Y + position.Y), colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(new Vector2(outVertices[outIndices[i + 2]].X + position.X, outVertices[outIndices[i + 2]].Y + position.Y), colorFill, PrimitiveType.TriangleList); } //if (outline) // DrawPolygon(position, vertices, color); }
public static void DrawSolidPolygon(PrimitiveBatch primitiveBatch, Vector2[] vertices, int count, Color color, bool outline) { if (!primitiveBatch.IsReady()) throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); if (count == 2) { DrawPolygon(primitiveBatch, vertices, count, color); return; } Color colorFill = color * (outline ? 0.5f : 1.0f); for (int i = 1; i < count - 1; i++) { primitiveBatch.AddVertex(vertices[0], colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(vertices[i], colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(vertices[i + 1], colorFill, PrimitiveType.TriangleList); } if (outline) { DrawPolygon(primitiveBatch, vertices, count, color); } }
/// <summary> /// /// </summary> /// <param name="pDevice"></param> public void Render(GraphicsDevice pDevice) { if (this.mPoints.Count == 0) { return; } // Draw lines mPrimitiveBatch.Begin(PrimitiveType.LineList); for (int i = 0; i < this.mPoints.Count - 1; i++) { mPrimitiveBatch.AddVertex(this.mPoints[i], this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i + 1], this.mColor); //batch.AddVertex(this.mPoints[(i + 1) % transformedVertices.Length], ShapeColor); } mPrimitiveBatch.End(); // Draw Nodes for (int i = 0; i < this.mPoints.Count; i++) { mPrimitiveBatch.Begin(PrimitiveType.LineList); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, cHalfRadiusNodes), this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, cHalfRadiusNodes), this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, cHalfRadiusNodes), this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, cHalfRadiusNodes), this.mColor); mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor); mPrimitiveBatch.End(); } }
public void ShowGUI(List <GUIItem> GUIItems) { foreach (var option in GUIItems) { LinkedList <Vector2> optionDisplay; //Figures out if it is a title or not then makes the display item if (option.IsTitle) { optionDisplay = MyFont.GetWord(titleFontScaleSize, option.TextToDisplay); } else { optionDisplay = MyFont.GetWord(regularFontScaleSize, option.TextToDisplay); } foreach (Vector2 v2 in optionDisplay) { pb.AddVertex(v2 + option.Position, option.Color); } if (option.MenuItem) { itemPositionList.Add(option.Position); } } }
public void Draw(GraphicsDevice device) { if (material == null) { Warm(device); } material.Projection = proj; material.View = view; material.World = Matrix.Identity; material.CurrentTechnique.Passes[0].Apply(); PrimitiveBatch instance = PrimitiveBatch.GetInstance(device); instance.Begin(Primitive.Line); instance.SetColor(color); for (int p = 1; p < points.Length; p++) { instance.AddVertex(points[p - 1]); instance.AddVertex(points[p - 0]); } instance.AddVertex(points[points.Length - 1]); instance.AddVertex(points[0]); instance.End(); }
public static void DrawSegment(PrimitiveBatch primitiveBatch, Vector2 start, Vector2 end, Color color) { if (!primitiveBatch.IsReady()) throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); primitiveBatch.AddVertex(start, color, PrimitiveType.LineList); primitiveBatch.AddVertex(end, color, PrimitiveType.LineList); }
public void DrawLaserCollision() { LinkedList <Line2D> collision = ConvertLaserLine2D(); foreach (Line2D line in collision) { pb.AddVertex(new Vector2(line.StartX, line.StartY), Color.Coral); pb.AddVertex(new Vector2(line.EndX, line.EndY), Color.Coral); } }
public void End() { if (!has_begun) { throw new InvalidOperationException("Begin must be called before End can be called."); } if (primitivebatch == null || material == null) { Warm(device); } material.Parameters["TextureEnabled"].SetValue(true); material.Parameters["World"].SetValue(Matrix.Identity); material.Parameters["View"].SetValue(camera.view); material.Parameters["Projection"].SetValue(camera.projection); foreach (Texture2D texture in particles.Keys) { List <ParticleInfo> list = particles[texture]; if (list.Count <= 0) { continue; } material.Parameters["Texture"].SetValue(texture); material.CurrentTechnique.Passes[0].Apply(); primitivebatch.Begin(Primitive.Quad); float texture_pixel_width = 1.0f / texture.Width; float texture_pixel_height = 1.0f / texture.Height; for (int i = 0; i < list.Count; i++) { ParticleInfo particle = list[i]; TextureRegion region = particle.region; primitivebatch.SetTransform(ref particle.transform); primitivebatch.SetColor(particle.color); primitivebatch.SetTextureCoords(region.u * texture_pixel_width, region.v * texture_pixel_height); primitivebatch.AddVertex(-0.5f, 0.5f, 0, 0, 0); primitivebatch.AddVertex(-0.5f, -0.5f, 0, 0, region.height * texture_pixel_height); primitivebatch.AddVertex(0.5f, -0.5f, 0, region.width * texture_pixel_width, region.height * texture_pixel_height); primitivebatch.AddVertex(0.5f, 0.5f, 0, region.width * texture_pixel_width, 0); } primitivebatch.End(); list.Clear(); } has_begun = false; }
public override void Draw(GameTime gameTime) { pb.Begin(PrimitiveType.LineList); foreach (Vector2 v2 in land) { pb.AddVertex(v2, landColor); } foreach (Vector2 v2 in landingPads) { pb.AddVertex(v2, padColor); } pb.End(); base.Draw(gameTime); }
public static void DrawPolygon(PrimitiveBatch primitiveBatch, Vector2[] vertices, int count, Color color) { if (!primitiveBatch.IsReady()) throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); for (int i = 0; i < count - 1; i++) { primitiveBatch.AddVertex(vertices[i], color, PrimitiveType.LineList); primitiveBatch.AddVertex(vertices[i + 1], color, PrimitiveType.LineList); } primitiveBatch.AddVertex(vertices[count - 1], color, PrimitiveType.LineList); primitiveBatch.AddVertex(vertices[0], color, PrimitiveType.LineList); }
private void DrawBox(Vector2[] lineList, bool selected) { var colour = (selected ? Color.Blue : Color.White); lineList[0].X -= 1; lineList[0].Y -= 1; lineList[1].X += 1; lineList[1].Y -= 1; lineList[2].X += 1; lineList[2].Y += 1; lineList[3].X -= 1; lineList[3].Y += 1; primitiveBatch.Begin(PrimitiveType.LineList, Camera.get_Transformation(GraphicsDevice)); primitiveBatch.AddVertex(lineList[0], colour); primitiveBatch.AddVertex(lineList[1], colour); primitiveBatch.AddVertex(lineList[1], colour); primitiveBatch.AddVertex(lineList[2], colour); primitiveBatch.AddVertex(lineList[2], colour); primitiveBatch.AddVertex(lineList[3], colour); primitiveBatch.AddVertex(lineList[3], colour); primitiveBatch.AddVertex(lineList[0], colour); primitiveBatch.End(); }
private void DrawLander() { foreach (Vector2 v2 in LanderValues.FillLanderLines()) { float Xrotated = center.X + (v2.X - center.X) * (float)Math.Cos(rotation) - (v2.Y - center.Y) * (float)Math.Sin(rotation); float Yrotated = center.Y + (v2.X - center.X) * (float)Math.Sin(rotation) + (v2.Y - center.Y) * (float)Math.Cos(rotation); pb.AddVertex((new Vector2(Xrotated, Yrotated) * scale) + position, Color.White);//Color of the lander } }
private void ShowMenuOptions() { float yStart = (GlobalValues.ScreenCenter.Y - (GlobalValues.FontYSpacer * 2)); LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Map Select"); LinkedList <Vector2> mainMenuOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Main Menu"); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Map Select", true).X, 100); Vector2 mainMenuOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Main Menu", false).X, GlobalValues.ScreenCenter.Y - (GlobalValues.FontYSpacer * 3)); foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in mainMenuOption) { pb.AddVertex(v2 + mainMenuOptionPos, Color.White); } LinkedList <Vector2> option = new LinkedList <Vector2>(); Vector2 optionPos = new Vector2(); List <Vector2> positions = new List <Vector2>() { mainMenuOptionPos }; int mapNum = 0; foreach (string map in mapNames) { option = MyFont.GetWord(GlobalValues.FontScaleSize, map); optionPos = new Vector2(GlobalValues.GetWordCenterPos(map, false).X, yStart + (GlobalValues.FontYSpacer * mapNum)); foreach (Vector2 v2 in option) { pb.AddVertex(v2 + optionPos, Color.White); } positions.Add(optionPos); mapNum++; } ShowSelectedIcon(positions); }
private void ShowMenuOptions() { float xPos = GlobalValues.ScreenCenter.X - ("Restart".Length * (GlobalValues.FontScaleSize * 2)); float yStart = GlobalValues.ScreenCenter.Y; LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Pause"); LinkedList <Vector2> continueOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Continue"); LinkedList <Vector2> restartOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Restart"); LinkedList <Vector2> mainMenuOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Main Menu"); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Pause", true).X, 100); Vector2 continueOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Continue", false).X, GlobalValues.ScreenCenter.Y - GlobalValues.FontYSpacer); Vector2 restartOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Restart", false).X, GlobalValues.ScreenCenter.Y); Vector2 mainMenuOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Main Menu", false).X, GlobalValues.ScreenCenter.Y + GlobalValues.FontYSpacer); List <Vector2> positions = new List <Vector2>() { continueOptionPos, restartOptionPos, mainMenuOptionPos }; ShowSelectedIcon(positions); #region Foreach foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in continueOption) { pb.AddVertex(v2 + continueOptionPos, Color.White); } foreach (Vector2 v2 in restartOption) { pb.AddVertex(v2 + restartOptionPos, Color.White); } foreach (Vector2 v2 in mainMenuOption) { pb.AddVertex(v2 + mainMenuOptionPos, Color.White); } #endregion }
private void DisplayKeys() { LinkedList <Vector2> display = MyFont.GetWord(GlobalValues.FontScaleSize, $"Press Space to continue or wait {5 - elapsedTime.Seconds} seconds"); Vector2 displayPos = GlobalValues.GetWordCenterPos("Press Space to continue or wait 5 seconds", false) + new Vector2(-50, 300); foreach (Vector2 v2 in display) { pb.AddVertex(v2 + displayPos, Color.White); } }
public static void ShowEntireFont(PrimitiveBatch pb) { int scaleForFontDisplay = 8; LinkedList <Vector2> row1 = new LinkedList <Vector2>(); LinkedList <Vector2> row2 = new LinkedList <Vector2>(); LinkedList <Vector2> row3 = new LinkedList <Vector2>(); LinkedList <Vector2> row4 = new LinkedList <Vector2>(); Vector2 row1Position = new Vector2(10, 50); Vector2 row2Position = new Vector2(10, 100); Vector2 row3Position = new Vector2(10, 150); Vector2 row4Position = new Vector2(10, 200); row1 = MyFont.GetWord(scaleForFontDisplay, "a b c d e f g h i j"); row2 = MyFont.GetWord(scaleForFontDisplay, "k l m n o p q r s t"); row3 = MyFont.GetWord(scaleForFontDisplay, "u v w x y z 1 2 3 4"); row4 = MyFont.GetWord(scaleForFontDisplay, "5 6 7 8 9 0 ."); pb.Begin(PrimitiveType.LineList); foreach (Vector2 v2 in row1) { pb.AddVertex(v2 + row1Position, Color.White); } foreach (Vector2 v2 in row2) { pb.AddVertex(v2 + row2Position, Color.White); } foreach (Vector2 v2 in row3) { pb.AddVertex(v2 + row3Position, Color.White); } foreach (Vector2 v2 in row4) { pb.AddVertex(v2 + row4Position, Color.White); } pb.End(); }
public override void Draw(GameTime gameTime) { pb.Begin(PrimitiveType.LineList); foreach (Vector2 x in terrain.terrainList) { pb.AddVertex(x, Color.White); } foreach (Vector2 x in terrain.padsList) { pb.AddVertex(x, Color.Green); } foreach (Vector2 x in fuelWord.sentence) { pb.AddVertex(x + new Vector2(10, 10), Color.White); } if (terInt || padsInt) { if (terInt) { StateManager.graphicsDevice.Clear(Color.DarkRed); } if (padsInt) { StateManager.graphicsDevice.Clear(Color.DarkGreen); } } lander.Draw(gameTime); pb.End(); spriteBatch.Begin(); AllTheWords(); spriteBatch.End(); }
private void ShowMenu() { LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Resolution"); LinkedList <Vector2> notImplemented = MyFont.GetWord(GlobalValues.FontScaleSize, "Not implemented"); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Resolution", true).X, 100); Vector2 notImplementedPos = new Vector2(GlobalValues.GetWordCenterPos("Not implemented", false).X, GlobalValues.ScreenCenter.Y); #region Foreach foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in notImplemented) { pb.AddVertex(v2 + notImplementedPos, Color.White); } #endregion }
public void Draw3D(PrimitiveBatch primitiveBatch, Matrix world, Matrix projection, Matrix view, Vector3 where) { // the sun is made from 4 lines in a circle. primitiveBatch.Begin(PrimitiveType.LineList, world, projection, view); // draw the vertical and horizontal lines primitiveBatch.AddVertex(where + new Vector3(0, LIGHT_SIZE, 0), Color.White); primitiveBatch.AddVertex(where + new Vector3(0, -LIGHT_SIZE, 0), Color.White); primitiveBatch.AddVertex(where + new Vector3(LIGHT_SIZE, 0, 0), Color.White); primitiveBatch.AddVertex(where + new Vector3(-LIGHT_SIZE, 0, 0), Color.White); // to know where to draw the diagonal lines, we need to use trig. // cosine of pi / 4 tells us what the x coordinate of a circle's radius is // at 45 degrees. the y coordinate normally would come from sin, but sin and // cos 45 are the same, so we can reuse cos for both x and y. float sunSizeDiagonal = (float)Math.Cos(MathHelper.PiOver4); // since that trig tells us the x and y for a unit circle, which has a // radius of 1, we need scale that result by the sun's radius. sunSizeDiagonal *= LIGHT_SIZE; primitiveBatch.AddVertex( where + new Vector3(-sunSizeDiagonal, sunSizeDiagonal, 0), Color.Gray); primitiveBatch.AddVertex( where + new Vector3(sunSizeDiagonal, -sunSizeDiagonal, 0), Color.Gray); primitiveBatch.AddVertex( where + new Vector3(sunSizeDiagonal, sunSizeDiagonal, 0), Color.Gray); primitiveBatch.AddVertex( where + new Vector3(-sunSizeDiagonal, -sunSizeDiagonal, 0), Color.Gray); primitiveBatch.End(); }
private void ShowMenuOptions() { LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Main Menu"); LinkedList <Vector2> playOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Play"); LinkedList <Vector2> optionsOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Options"); LinkedList <Vector2> creatorOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Map Creator"); LinkedList <Vector2> creditsOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Credits"); LinkedList <Vector2> exitOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Exit"); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Main Menu", true).X, 100); Vector2 playOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Play", false).X, GlobalValues.ScreenCenter.Y - GlobalValues.FontYSpacer); Vector2 optionsOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Options", false).X, GlobalValues.ScreenCenter.Y); Vector2 creatorOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Map Creator", false).X, GlobalValues.ScreenCenter.Y + GlobalValues.FontYSpacer); Vector2 creditsOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Credits", false).X, GlobalValues.ScreenCenter.Y + (GlobalValues.FontYSpacer * 2)); Vector2 exitOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Exit", false).X, GlobalValues.ScreenCenter.Y + (GlobalValues.FontYSpacer * 3)); List <Vector2> positions = new List <Vector2>() { playOptionPos, optionsOptionPos, creatorOptionPos, creditsOptionPos, exitOptionPos }; ShowSelectedIcon(positions); #region Foreach foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in playOption) { pb.AddVertex(v2 + playOptionPos, Color.White); } foreach (Vector2 v2 in optionsOption) { pb.AddVertex(v2 + optionsOptionPos, Color.White); } foreach (Vector2 v2 in creatorOption) { pb.AddVertex(v2 + creatorOptionPos, Color.White); } foreach (Vector2 v2 in creditsOption) { pb.AddVertex(v2 + creditsOptionPos, Color.White); } foreach (Vector2 v2 in exitOption) { pb.AddVertex(v2 + exitOptionPos, Color.White); } #endregion }
private void drawHex(PrimitiveBatch primitiveBatch, Hex hex) { primitiveBatch.AddVertex(new Vector2(hex.Points[0].X, hex.Points[0].Y), hex.HexState.BackgroundColor); primitiveBatch.AddVertex(new Vector2(hex.Points[1].X, hex.Points[1].Y), hex.HexState.BackgroundColor); primitiveBatch.AddVertex(new Vector2(hex.Points[2].X, hex.Points[2].Y), hex.HexState.BackgroundColor); primitiveBatch.AddVertex(new Vector2(hex.Points[3].X, hex.Points[3].Y), hex.HexState.BackgroundColor); primitiveBatch.AddVertex(new Vector2(hex.Points[4].X, hex.Points[4].Y), hex.HexState.BackgroundColor); primitiveBatch.AddVertex(new Vector2(hex.Points[5].X, hex.Points[5].Y), hex.HexState.BackgroundColor); }
public override void Draw(GameTime gameTime) { LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Credits"); LinkedList <Vector2> credits = MyFont.GetWord(GlobalValues.FontScaleSize, "Created by: Steven Endres"); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Credits", true).X, 100); Vector2 creditsPos = new Vector2(GlobalValues.GetWordCenterPos("Created By: Steven Endres", false).X, GlobalValues.ScreenCenter.Y); pb.Begin(PrimitiveType.LineList); foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in credits) { pb.AddVertex(v2 + creditsPos, Color.White); } ShowKeys(); pb.End(); }
protected override void Draw(Matrix view, Matrix Projection, RenderHelper render, PrimitiveBatch batch) { if (fill == false) { render.PushRasterizerState(state); } batch.Begin(PrimitiveType.TriangleList,view,Projection); foreach (var item in point) { batch.AddVertex(item, color); } batch.End(); render.PopRasterizerState(); }
public override void Draw(GameTime gameTime) { // TODO: Add your draw code here if (isVisible) { pb.Begin(PrimitiveType.LineList); foreach (Vector2 v in landerCraft) { pb.AddVertex(v, Color.Green); } pb.End(); } base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { //GraphicsDevice.Clear(Color.TransparentBlack); pb.Begin(PrimitiveType.LineList); DrawRocks(); DrawSquare(); DrawRockCollision(); //pb.AddLine(new Vector2(center.X, center.Y - 10), new Vector2(center.X, center.Y + 10), Color.Violet, 5); //pb.AddLine(new Vector2(center.X - 10, center.Y), new Vector2(center.X + 10, center.Y), Color.Violet, 5); pb.AddVertex(new Vector2(position.X, position.Y - 10), Color.Violet); pb.AddVertex(new Vector2(position.X, position.Y + 10), Color.Violet); pb.AddVertex(new Vector2(position.X - 10, position.Y), Color.Violet); pb.AddVertex(new Vector2(position.X + 10, position.Y), Color.Violet); //pb.AddVertex(new Vector2(242.1367f, 275.431f), Color.Violet); //pb.AddVertex(new Vector2(242.1367f, 295.431f), Color.Violet); //pb.AddVertex(new Vector2(300, 375), Color.Violet); //pb.AddVertex(new Vector2(300, 300), Color.Violet); /* * Laser Collision: l1.StartX (242.1367, 275.431) l1.EndX (242.1367, 295.431) * Rock Collision: l2.StartX (300, 375) l2.EndX (300, 300) */ Line2D.Intersects(new Line2D(238.5262f, 283.2247f, 238.5262f, 303.2247f), new Line2D(300, 375, 300, 300)); pb.End(); base.Draw(gameTime); }
protected override void Draw(Matrix view, Matrix Projection, RenderHelper render, PrimitiveBatch batch) { if (fill == false) { render.PushRasterizerState(state); } if (point.Count < 3) { throw new InvalidOperationException("Need at least 3 points to make a triangle strip"); } batch.Begin(PrimitiveType.TriangleStrip,view,Projection); foreach (var item in point) { batch.AddVertex(item, color); } batch.End(); if (fill == false) { render.PopRasterizerState(); } }
private void ShowMenu() { LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Volume"); LinkedList <Vector2> currentVolume = MyFont.GetWord(GlobalValues.FontScaleSize, (volume * 100).ToString()); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Volume", true).X, 100); Vector2 currentVolumePos = new Vector2(GlobalValues.GetWordCenterPos((volume * 100).ToString(), false).X, GlobalValues.ScreenCenter.Y); #region Foreach foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in currentVolume) { pb.AddVertex(v2 + currentVolumePos, Color.White); } #endregion }
public override void Draw(GraphicsDevice device, Camera camera) { if (popped) { return; } material.Parameters["TextureEnabled"].SetValue(true); material.Parameters["World"].SetValue(Matrix.Identity); material.Parameters["View"].SetValue(camera.view); material.Parameters["Projection"].SetValue(camera.projection); material.Parameters["Texture"].SetValue(Resources.bubble_texture); material.CurrentTechnique.Passes[0].Apply(); PrimitiveBatch primitivebatch = PrimitiveBatch.GetInstance(device); primitivebatch.Begin(Primitive.Triangle); primitivebatch.SetColor(new Color(1, 1, 1, alpha)); for (int i = 0; i < vertices.Count - 1; i++) { vertices[i] = body.pointmass_list[i].position; } vertices[vertices.Count - 1] = body.position; int center = vertices.Count - 1; for (short i = 0; i < center; i++) { primitivebatch.AddVertex(vertices[center].X, vertices[center].Y, 0, texture_coords[center].X, texture_coords[center].Y); primitivebatch.AddVertex(vertices[i].X, vertices[i].Y, 0, texture_coords[i].X, texture_coords[i].Y); primitivebatch.AddVertex(vertices[i + 1].X, vertices[i + 1].Y, 0, texture_coords[i + 1].X, texture_coords[i + 1].Y); } primitivebatch.AddVertex(vertices[center].X, vertices[center].Y, 0, texture_coords[center].X, texture_coords[center].Y); primitivebatch.AddVertex(vertices[center - 1].X, vertices[center - 1].Y, 0, texture_coords[center - 1].X, texture_coords[center - 1].Y); primitivebatch.AddVertex(vertices[0].X, vertices[0].Y, 0, texture_coords[0].X, texture_coords[0].Y); primitivebatch.End(); //PhysicsRenderer.GetInstance(device).Draw(body, camera); }
private void DrawCircle(Vector2 center, float radius, Color color) { if (!_primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } const double increment = Math.PI * 2.0 / CircleSegments; double theta = 0.0; for (int i = 0; i < CircleSegments; i++) { Vector2 v1 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); Vector2 v2 = center + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)); _primitiveBatch.AddVertex(v1, color, PrimitiveType.LineList); _primitiveBatch.AddVertex(v2, color, PrimitiveType.LineList); theta += increment; } }
public override void Draw(GameTime gameTime) { if (State == landerState.playing || State == landerState.landed) { pb.Begin(PrimitiveType.LineList); foreach (Vector2 v2 in fullLander.Part) { pb.AddVertex(v2 + fullLander.Position, landerColor); } if (isThrusting) { if (gameTime.ElapsedGameTime.Ticks % 2 == 0) { thrust1.Position = fullLander.Position; foreach (Vector2 v2 in thrust1.Part) { pb.AddVertex(v2 + thrust1.Position, thrustColor); } } else { thrust2.Position = fullLander.Position; foreach (Vector2 v2 in thrust2.Part) { pb.AddVertex(v2 + thrust2.Position, thrustColor); } } } pb.End(); } else { pb.Begin(PrimitiveType.LineList); foreach (Vector2 v2 in manCan.Part) { pb.AddVertex(v2 + manCan.Position, landerColor); } foreach (Vector2 v2 in landerCan.Part) { pb.AddVertex(v2 + landerCan.Position, landerColor); } foreach (Vector2 v2 in legLeft.Part) { pb.AddVertex(v2 + legLeft.Position, landerColor); } foreach (Vector2 v2 in legRight.Part) { pb.AddVertex(v2 + legRight.Position, landerColor); } foreach (Vector2 v2 in thruster.Part) { pb.AddVertex(v2 + thruster.Position, landerColor); } pb.End(); } base.Draw(gameTime); }
public void Draw(PrimitiveBatch batch) { batch.Begin(PrimitiveType.LineList); switch (type) { case DrawType.LineStrip: for (int i = 0; i < transformedVertices.Length -1; i++) { batch.AddVertex(transformedVertices[i], lineColor[i]); batch.AddVertex(transformedVertices[(i + 1)], lineColor[i]); } break; case DrawType.LineLoop: for (int i = 0; i < transformedVertices.Length; i++) { batch.AddVertex(transformedVertices[i], lineColor[i]); batch.AddVertex(transformedVertices[(i + 1) % transformedVertices.Length], lineColor[i]); } break; case DrawType.LineList: for (int i = 0; i < transformedVertices.Length; i++) { batch.AddVertex(transformedVertices[i], lineColor[i]); } break; default: break; } batch.End(); }
private void ShowMenuOptions() { LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Options"); LinkedList <Vector2> mainMenuOption = MyFont.GetWord(GlobalValues.FontScaleSize, "Main Menu"); LinkedList <Vector2> option1Option = MyFont.GetWord(GlobalValues.FontScaleSize, "Manage Maps"); LinkedList <Vector2> option2Option = MyFont.GetWord(GlobalValues.FontScaleSize, "Change Volume"); LinkedList <Vector2> option3Option = MyFont.GetWord(GlobalValues.FontScaleSize, "Change Resolution"); LinkedList <Vector2> option4Option = MyFont.GetWord(GlobalValues.FontScaleSize, "Change Difficulty"); LinkedList <Vector2> option5Option = MyFont.GetWord(GlobalValues.FontScaleSize, "Change Gravity"); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Options", true).X, 100); Vector2 mainMenuOptionPos = new Vector2(GlobalValues.GetWordCenterPos("Main Menu", false).X, GlobalValues.ScreenCenter.Y - (GlobalValues.FontYSpacer * 2)); Vector2 option1OptionPos = new Vector2(GlobalValues.GetWordCenterPos("Manage Maps", false).X, GlobalValues.ScreenCenter.Y - GlobalValues.FontYSpacer); Vector2 option2OptionPos = new Vector2(GlobalValues.GetWordCenterPos("Change Volume", false).X, GlobalValues.ScreenCenter.Y); Vector2 option3OptionPos = new Vector2(GlobalValues.GetWordCenterPos("Change Resolution", false).X, GlobalValues.ScreenCenter.Y + GlobalValues.FontYSpacer); Vector2 option4OptionPos = new Vector2(GlobalValues.GetWordCenterPos("Change Difficulty", false).X, GlobalValues.ScreenCenter.Y + (GlobalValues.FontYSpacer * 2)); Vector2 option5OptionPos = new Vector2(GlobalValues.GetWordCenterPos("Change Gravity", false).X, GlobalValues.ScreenCenter.Y + (GlobalValues.FontYSpacer * 3)); List <Vector2> positions = new List <Vector2>() { mainMenuOptionPos, option1OptionPos, option2OptionPos, option3OptionPos, option4OptionPos, option5OptionPos }; ShowSelectedIcon(positions); #region Foreach foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in mainMenuOption) { pb.AddVertex(v2 + mainMenuOptionPos, Color.White); } foreach (Vector2 v2 in option1Option) { pb.AddVertex(v2 + option1OptionPos, Color.White); } foreach (Vector2 v2 in option2Option) { pb.AddVertex(v2 + option2OptionPos, Color.White); } foreach (Vector2 v2 in option3Option) { pb.AddVertex(v2 + option3OptionPos, Color.White); } foreach (Vector2 v2 in option4Option) { pb.AddVertex(v2 + option4OptionPos, Color.White); } foreach (Vector2 v2 in option5Option) { pb.AddVertex(v2 + option5OptionPos, Color.White); } #endregion }
/// <summary> /// Draws the control, using SpriteBatch, PrimitiveBatch and SpriteFont. /// </summary> protected override void Draw() { Vector2 offset = new Vector2(((GraphicsDevice.Viewport.Width * 0.5f) / Camera.Zoom) - Camera.Pos.X, ((GraphicsDevice.Viewport.Height * 0.5f) / Camera.Zoom) - Camera.Pos.Y); if (!bDoNotDraw) { UpdateTime(); GraphicsDevice.Clear(Color.CornflowerBlue); List <Decal> decalList = STATIC_EDITOR_MODE.levelInstance.DecalManager.DecalList; List <NodeObject> objectsList = STATIC_EDITOR_MODE.levelInstance.ObjectsList; List <ObjectIndex> selectedList = STATIC_EDITOR_MODE.selectedObjectIndices; #region Objects and selection overlay spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.AnisotropicWrap, null, null, null, Camera.get_transformation(new Vector2(this.Width, this.Height))); #region Draw Generics if (levelBackground != null) { spriteBatch.Draw(levelBackground, new Rectangle(-(int)(levelDimensions.X * 0.5f), -(int)(levelDimensions.Y * 0.5f), (int)levelDimensions.X, (int)levelDimensions.Y), new Rectangle(0, 0, (int)this.levelDimensions.X, (int)this.levelDimensions.Y), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 1.0f); } if (!HidePlayerSpawn) { spriteBatch.Draw(devCharacter, STATIC_EDITOR_MODE.levelInstance.PlayerSpawnLocation, null, Color.White, 0.0f, new Vector2(this.devCharacter.Width, this.devCharacter.Height) * 0.5f, 0.43f, SpriteEffects.None, 0.3f); } #endregion #region Draw PhysicsObjects and Decals if (objectsList.Count > 0) { for (int i = objectsList.Count - 1; i >= 0; i--) { objectsList[i].Draw(spriteBatch); } } if (decalList.Count > 0) { for (int i = decalList.Count - 1; i >= 0; i--) { decalList[i].Draw(spriteBatch); } } #endregion #region Draw object overlay if (!HideOverlay) { for (int i = selectedList.Count - 1; i >= 0; i--) { int index = selectedList[i].Index; if (selectedList[i].Type == OBJECT_TYPE.Physics) { spriteBatch.Draw(debugOverlay, objectsList[index].Position, new Rectangle(0, 0, (int)objectsList[index].Width, (int)objectsList[index].Height), Color.Green * 0.3f, 0.0f, new Vector2(objectsList[index].Width, objectsList[index].Height) * 0.5f, 1.0f, SpriteEffects.None, 0.001f); } else { float width = decalList[index].Width * decalList[index].Scale; float height = decalList[index].Height * decalList[index].Scale; spriteBatch.Draw(debugOverlay, decalList[index].Position, new Rectangle(0, 0, (int)width, (int)height), Color.Green * 0.3f, decalList[index].Rotation, new Vector2(width, height) * 0.5f, 1.0f, SpriteEffects.None, 0.001f); } } } #endregion #region Draw Names if (!HideObjectNames) { for (int i = objectsList.Count - 1; i >= 0; i--) { NodeObject obj = objectsList[i]; if (obj.Name != null || obj.Name != "") { Vector2 textOrigin = font.MeasureString(obj.Name) * 0.5f; spriteBatch.DrawString(font, obj.Name, obj.Position, Color.White, 0.0f, textOrigin, 1.5f, SpriteEffects.None, 0.0f); } } } #endregion spriteBatch.End(); #endregion #region Primitives // Primitive batch calls need to be made OUTSIDE of a spriteBatch, // otherwise it causes horrible FPS problems. // Therefore, we'll do it afterwards and apply a basic transform // on their positions using the camera. primBatch.Begin(PrimitiveType.LineList); #region Movement paths if (!HideMovementPath) { for (int i = 0; i < objectsList.Count; i++) { Type t = objectsList[i].GetType(); if (t.BaseType == typeof(DynamicObject)) { DynamicObject dyObj = (DynamicObject)objectsList[i]; primBatch.AddVertex((dyObj.Position + offset) * Camera.Zoom, Color.Red); primBatch.AddVertex((dyObj.EndPosition + offset) * Camera.Zoom, Color.Red); } else if (t == typeof(Rope)) { Rope ropeObj = (Rope)objectsList[i]; primBatch.AddVertex((ropeObj.Position + offset) * Camera.Zoom, Color.Red); primBatch.AddVertex((ropeObj.EndPosition + offset) * Camera.Zoom, Color.Red); } } } #endregion #region Grid if (!HideGrid) { for (int i = 0; i < xLineCount + 2; i++) { primBatch.AddVertex(new Vector2(xOffset + xySpacing * i, 0), Color.White * 0.2f); primBatch.AddVertex(new Vector2(xOffset + xySpacing * i, GraphicsDevice.Viewport.Height), Color.White * 0.2f); } for (int i = 0; i < yLineCount + 2; i++) { primBatch.AddVertex(new Vector2(0, yOffset + xySpacing * i), Color.White * 0.2f); primBatch.AddVertex(new Vector2(GraphicsDevice.Viewport.Width, yOffset + xySpacing * i), Color.White * 0.2f); } } #endregion #region Event Targets if (!HideEventTargets) { NodeObject obj = new NodeObject(); for (int i = 0; i < objectsList.Count; i++) { obj = objectsList[i]; // Check if the object has a name (it can't use events if it doesn't). if (obj.Name != null && obj.Name != "") { // Check it has some events to target. if (obj.EventList.Count > 0) { // For the next part we need to check the name of each target // in the event list and compare it with objects in the objectList for (int j = 0; j < obj.EventList.Count; j++) { for (int x = 0; x < objectsList.Count; x++) { // Check if the name of the object in the objectList matches // the target if (obj.EventList[j].TargetName == objectsList[x].Name) { // It is our target, so draw it. primBatch.AddVertex((obj.Position + offset) * Camera.Zoom, Color.Pink); primBatch.AddVertex((objectsList[x].Position + offset) * Camera.Zoom, Color.Pink); } } } } } } } #endregion primBatch.End(); #endregion #region Screen Rotation Point spriteBatch.Begin(); spriteBatch.Draw(crosshair, new Vector2((GraphicsDevice.Viewport.Width / 2 / Camera.Zoom) - Camera.Pos.X - (crosshair.Width / 2 / Camera.Zoom), (GraphicsDevice.Viewport.Height / 2 / Camera.Zoom) - Camera.Pos.Y - (crosshair.Height / 2 / Camera.Zoom)) * Camera.Zoom, Color.White * 0.2f); spriteBatch.End(); #endregion #region Text Coordinates if (!HideCoordinates) { spriteBatch.Begin(); spriteBatch.DrawString(font, "Level Co-ords: ", new Vector2(0, 0), Color.White); spriteBatch.DrawString(font, worldCoOrds, new Vector2(0, 20), Color.White); spriteBatch.End(); } #endregion } }
public override void Draw(GameTime gameTime) { pb.Begin(PrimitiveType.LineList); #region After Named if (isNamed) { Display(); #region Show Old Lines if (mapTerrain.Count != 0) { foreach (Vector2 v2 in mapTerrain) { pb.AddVertex(v2, Color.White); } } if (mapPads.Count != 0) { foreach (Vector2 v2 in mapPads) { pb.AddVertex(v2, Color.Green); } } #endregion #region Display Line if (makingTerrain) { pb.AddVertex(new Vector2(lineStartLocation.X, lineStartLocation.Y), Color.White); pb.AddVertex(new Vector2(newMouseState.X, newMouseState.Y), Color.White); } if (makingPads) { pb.AddVertex(new Vector2(lineStartLocation.X, lineStartLocation.Y), Color.Green); pb.AddVertex(new Vector2(newMouseState.X, lineStartLocation.Y), Color.Green); } #endregion } #endregion #region Before Named else { LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Map Creator"); Vector2 screenTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Map Creator", true).X, 100); LinkedList <Vector2> mapTitle = MyFont.GetWord(GlobalValues.FontScaleSize, "Map Title"); Vector2 mapTitlePos = new Vector2(GlobalValues.GetWordCenterPos("Map Title", false).X, GlobalValues.GetWordCenterPos(levelName, false).Y - 75); LinkedList <Vector2> userWord = MyFont.GetWord(GlobalValues.FontScaleSize, levelName); Vector2 userWordPos = GlobalValues.GetWordCenterPos(levelName, false); LinkedList <Vector2> continueWord = MyFont.GetWord(GlobalValues.FontScaleSize, "Press Enter to Continue"); Vector2 continueWordPos = new Vector2(GlobalValues.GetWordCenterPos("Press Enter to Continue", false).X, GlobalValues.GetWordCenterPos(levelName, false).Y + 75); #region Foreach foreach (Vector2 v2 in screenTitle) { pb.AddVertex(v2 + screenTitlePos, Color.White); } foreach (Vector2 v2 in mapTitle) { pb.AddVertex(v2 + mapTitlePos, Color.White); } foreach (Vector2 v2 in userWord) { pb.AddVertex(v2 + userWordPos, Color.White); } foreach (Vector2 v2 in continueWord) { pb.AddVertex(v2 + continueWordPos, Color.White); } #endregion } #endregion pb.End(); }
private void DrawGrid(float gridSize) { // where can we put the stars? int screenWidth = graphics.GraphicsDevice.Viewport.Width; int screenHeight = graphics.GraphicsDevice.Viewport.Height; PrimitiveBatch primitiveBatch = new PrimitiveBatch(this.GraphicsDevice); primitiveBatch.Begin(PrimitiveType.LineList); for (float i = gridSize; i < screenWidth; i += gridSize) { //draw line verticaly primitiveBatch.AddVertex(new Vector2(i, 0), Color.White); primitiveBatch.AddVertex(new Vector2(i, screenHeight), Color.White); } for (float i = gridSize; i < screenHeight; i += gridSize) { //draw line verticaly primitiveBatch.AddVertex(new Vector2(0, i), Color.White); primitiveBatch.AddVertex(new Vector2(screenWidth, i), Color.White); } primitiveBatch.End(); }
private void ShowTitle() { LinkedList <Vector2> title = MyFont.GetWord(GlobalValues.FontScaleSize, "Lunar Lander"); Vector2 titlePosition = new Vector2(GlobalValues.GetWordCenterPos("Lunar Lander", false).X, 10); foreach (Vector2 v2 in title) { pb.AddVertex(v2 + titlePosition, Color.White); } }