public void OnCreateDevice(object sender, EventArgs e) { Device dev = (Device)sender; vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 3, dev, 0, CustomVertex.TransformedColored.Format, Pool.Default); GraphicsStream stm = vertexBuffer.Lock(0, 0, 0); CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3]; verts[0].X = 150; verts[0].Y = 50; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Aqua.ToArgb( ); verts[1].X = 250; verts[1].Y = 250; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Brown.ToArgb( ); verts[2].X = 50; verts[2].Y = 250; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.LightPink.ToArgb( ); stm.Write(verts); vertexBuffer.Unlock( ); }
//device.DrawUserPrimitives(PrimitiveType.TriangleList public BeginGameLayer(Player player,GameController controller) { this.controller = controller; this.player = player; this.locksMouse = true; this.locksKeyboard = false; float x = GM.AppWindow.GraphicsParameters.WindowSize.Width / 2; float y = GM.AppWindow.GraphicsParameters.WindowSize.Height - 300; GM.GUIStyleManager.SetCurrentStyle("mystyle"); joinKnights = new GuiButton("Rycerze", new System.Drawing.RectangleF(x - 50, y, 100, 34)); joinAssassins = new GuiButton("Zabójcy", new System.Drawing.RectangleF(x - 50, y + 40, 100, 34)); startGame = new GuiButton("Start", new System.Drawing.RectangleF(x - 80, y, 160, 70)); AddControl(joinKnights); AddControl(joinAssassins); joinKnights.OnClick += new ButtonEventHandler(joinKnights_OnClick); joinAssassins.OnClick += new ButtonEventHandler(joinAssassins_OnClick); startGame.OnClick += new ButtonEventHandler(startGame_OnClick); verts[2]=new CustomVertex.TransformedColored(0, 0, 0, 1, Color.FromArgb(127, 200, 200, 200).ToArgb()); verts[0]=new CustomVertex.TransformedColored(GM.AppWindow.GraphicsParameters.WindowSize.Width, 0, 0, 1, Color.FromArgb(127, 200, 200, 200).ToArgb()); verts[3]=new CustomVertex.TransformedColored(0, GM.AppWindow.GraphicsParameters.WindowSize.Height, 0, 1, Color.FromArgb(127, 200, 200, 200).ToArgb()); verts[1] = new CustomVertex.TransformedColored(GM.AppWindow.GraphicsParameters.WindowSize.Width, GM.AppWindow.GraphicsParameters.WindowSize.Height, 0, 1, Color.FromArgb(127, 200, 200, 200).ToArgb()); System.Windows.Forms.Cursor.Show(); }
public static ShapeDescriptor DrawPolyLine(int width, Color color, bool closed, params Vector2[] points) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4]; ShapeDescriptor[] segments; int col1 = color.ToArgb(); if (closed) { segments = new ShapeDescriptor[points.Length]; for (int i = 0; i < points.Length - 1; i++) { segments[i] = DrawLine(width, color, points[i], points[i + 1]); } segments[points.Length - 1] = DrawLine(width, color, points[points.Length - 1], points[0]); } else { segments = new ShapeDescriptor[points.Length - 1]; for (int i = 0; i < points.Length - 1; i++) { segments[i] = DrawLine(width, color, points[i], points[i + 1]); } } return(ShapeDescriptor.Join(segments)); }
public static ShapeDescriptor DrawLine(float width, Color color, Vector2 v1, Vector2 v2) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4]; int col1 = color.ToArgb(); Vector2 vDir = (v1 - v2); vDir = new Vector2(-vDir.Y, vDir.X); vDir.Normalize(); width /= 2; Vector2 vTopLeft = v1 + (-width * vDir); Vector2 vTopRight = v1 + (width * vDir); Vector2 vBottomLeft = v2 + (-width * vDir); Vector2 vBottomRight = v2 + (width * vDir); vertices[0] = new CustomVertex.TransformedColored(vTopLeft.X, vTopLeft.Y, 0, 1, col1); vertices[1] = new CustomVertex.TransformedColored(vBottomLeft.X, vBottomLeft.Y, 0, 1, col1); vertices[2] = new CustomVertex.TransformedColored(vBottomRight.X, vBottomRight.Y, 0, 1, col1); vertices[3] = new CustomVertex.TransformedColored(vTopRight.X, vTopRight.Y, 0, 1, col1); int[] indices = new int[6]; indices[0] = 0; indices[1] = 2; indices[2] = 1; indices[3] = 2; indices[4] = 0; indices[5] = 3; return(new ShapeDescriptor(2, vertices, indices)); }
public void VertexContainer(object sender, EventArgs e) { Device dev = ( Device )sender; vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 3, dev, 0, CustomVertex.TransformedColored.Format, Pool.Default); GraphicsStream GraphixStream = vertexBuffer.Lock(0, 0, 0); CustomVertex.TransformedColored[] VerticeArray = new CustomVertex.TransformedColored[3]; VerticeArray[0].Position = new Vector4(50, 50, 0.5f, 1); // top left Vertice VerticeArray[0].Color = System.Drawing.Color.Orange.ToArgb(); VerticeArray[1].Position = new Vector4(250, 50, 0.5f, 1); // top right VerticeArray[1].Color = System.Drawing.Color.Yellow.ToArgb(); VerticeArray[2].Position = new Vector4(150, 250, 0.5f, 1); // bottom VerticeArray[2].Color = System.Drawing.Color.Red.ToArgb(); GraphixStream.Write(VerticeArray); vertexBuffer.Unlock(); }
public void OnCreateDevice(object sender, EventArgs e ) { Device dev = (Device)sender; vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored ), 3, dev, 0, CustomVertex.TransformedColored.Format, Pool.Default ) ; GraphicsStream stm = vertexBuffer.Lock( 0, 0, 0 ) ; CustomVertex.TransformedColored[ ] verts = new CustomVertex.TransformedColored[ 3 ] ; verts[0].X = 150 ; verts[0].Y = 50 ; verts[0].Z = 0.5f ; verts[0].Rhw = 1 ; verts[0].Color = System.Drawing.Color.Aqua.ToArgb ( ) ; verts[1].X = 250 ; verts[1].Y = 250 ; verts[1].Z = 0.5f ; verts[1].Rhw = 1 ; verts[1].Color = System.Drawing.Color.Brown.ToArgb ( ) ; verts[2].X = 50 ; verts[2].Y = 250 ; verts[2].Z = 0.5f ; verts[2].Rhw = 1 ; verts[2].Color = System.Drawing.Color.LightPink.ToArgb ( ) ; stm.Write ( verts ) ; vertexBuffer.Unlock ( ) ; }
public static ShapeDescriptor DrawRectangle(Vector2 topLeft, Size size, Color color, ShadingMode shadeMode) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4]; int width = size.Width; int height = size.Height; int[] colors = shadeMode(color); int colorTopLeft = colors[0]; int colorTopRight = colors[1]; int colorBottomleft = colors[2]; int colorBottomRight = colors[3]; vertices[0] = new CustomVertex.TransformedColored(topLeft.X, topLeft.Y, 0, 1, colorTopLeft); vertices[1] = new CustomVertex.TransformedColored(topLeft.X, topLeft.Y + size.Height, 0, 1, colorBottomleft); vertices[2] = new CustomVertex.TransformedColored(topLeft.X + size.Width, topLeft.Y + size.Height, 0, 1, colorBottomRight); vertices[3] = new CustomVertex.TransformedColored(topLeft.X + size.Width, topLeft.Y, 0, 1, colorTopRight); int[] indices = new int[6]; indices[0] = 0; indices[1] = 3; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 1; return(new ShapeDescriptor(2, vertices, indices)); }
public void Render2() { if (device2 == null) //如果device为空则不渲染 { return; } device2.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0); //清除windows界面为深蓝色 device2.BeginScene(); { //在此添加渲染图形代码 CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4];//定义顶点 vertices[0].Position = new Vector4(150f, 400f, 0f, 1f); vertices[0].Color = Color.Yellow.ToArgb(); vertices[1].Position = new Vector4(panel2.Width / 2, 100f, 0f, 1f); vertices[1].Color = Color.Green.ToArgb(); vertices[2].Position = new Vector4(panel2.Width - 150f, 400f, 0f, 1f); vertices[2].Color = Color.Red.ToArgb(); device2.VertexFormat = CustomVertex.TransformedColored.Format; device2.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices); //截取panel2的截图 Surface backbuffer = device2.GetBackBuffer(0, 0, BackBufferType.Mono); SurfaceLoader.Save("Screenshot2.bmp", ImageFileFormat.Bmp, backbuffer); } device2.EndScene(); device2.Present(); }
public void OnCreateVertexBuffer(object sender, EventArgs e) { VertexBuffer vb = (VertexBuffer)sender; GraphicsStream stm = vb.Lock(0, 0, 0); CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[6]; verts[0].X = 250; verts[0].Y = 250; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Black.ToArgb(); verts[1].X = 50; verts[1].Y = 250; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Black.ToArgb(); verts[2].X = 150; verts[2].Y = 50; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.Black.ToArgb(); //verts[0].X=150;verts[0].Y=50;verts[0].Z=0.5f; verts[0].Rhw=1; verts[0].Color = System.Drawing.Color.Brown.ToArgb(); //verts[1].X=350;verts[1].Y=50;verts[1].Z=0.5f; verts[1].Rhw=1; verts[1].Color = System.Drawing.Color.Brown.ToArgb(); //verts[2].X=250;verts[2].Y=250;verts[2].Z=0.5f; verts[2].Rhw=1; verts[2].Color = System.Drawing.Color.Brown.ToArgb(); verts[3].X = 350; verts[3].Y = 50; verts[3].Z = 0.5f; verts[3].Rhw = 1; verts[3].Color = System.Drawing.Color.Brown.ToArgb(); verts[4].X = 250; verts[4].Y = 250; verts[4].Z = 0.5f; verts[4].Rhw = 1; verts[4].Color = System.Drawing.Color.Brown.ToArgb(); verts[5].X = 150; verts[5].Y = 50; verts[5].Z = 0.5f; verts[5].Rhw = 1; verts[5].Color = System.Drawing.Color.Brown.ToArgb(); /* * verts[3].X=150;verts[3].Y=50;verts[3].Z=0.5f; verts[3].Rhw=1; verts[3].Color = System.Drawing.Color.Brown.ToArgb(); * verts[4].X=350;verts[4].Y=50;verts[4].Z=0.5f; verts[4].Rhw=1; verts[4].Color = System.Drawing.Color.Brown.ToArgb(); * verts[5].X=250;verts[5].Y=250;verts[5].Z=0.5f; verts[5].Rhw=1; verts[5].Color = System.Drawing.Color.Brown.ToArgb(); * * verts[3].X=150;verts[3].Y=50;verts[3].Z=0.5f; verts[3].Rhw=1; verts[3].Color = System.Drawing.Color.Brown.ToArgb(); * verts[4].X=350;verts[4].Y=50;verts[4].Z=0.5f; verts[4].Rhw=1; verts[4].Color = System.Drawing.Color.Brown.ToArgb(); * verts[5].X=250;verts[5].Y=250;verts[5].Z=0.5f; verts[5].Rhw=1; verts[5].Color = System.Drawing.Color.Brown.ToArgb(); */ stm.Write(verts); vb.Unlock(); }
/*------------------------------------------------------------------------- * 単色矩形の描画 * フィルされた矩形 * ---------------------------------------------------------------------------*/ public void DrawFillRect(Vector3 pos, Vector2 size, int color) { CustomVertex.TransformedColored[] vb = new CustomVertex.TransformedColored[4]; for (int i = 0; i < 4; i++) { vb[i].Color = color; vb[i].Rhw = 1f; vb[i].Z = pos.Z; } vb[0].X = pos.X; vb[0].Y = pos.Y; vb[1].X = pos.X + size.X; vb[1].Y = pos.Y; vb[2].X = pos.X; vb[2].Y = pos.Y + size.Y; vb[3].X = pos.X + size.X; vb[3].Y = pos.Y + size.Y; base.device.VertexFormat = CustomVertex.TransformedColored.Format; base.device.SetTexture(0, null); base.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vb); }
/// <summary> /// 在场景中加入空心矩形 /// </summary> /// <param name="x">左上顶点的x坐标</param> /// <param name="y">左上顶点的y坐标</param> /// <param name="width">矩形的横向长度(的绝对值)</param> /// <param name="height">矩形的纵向长度(的绝对值)</param> /// <param name="color">矩形的颜色</param> public static void ImportEmptyRect(float x, float y, float width, float height, Color color) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[8]; Vector4 a = new Vector4(x, y, 0, 1); Vector4 b = new Vector4(x + Math.Abs(width), y, 0, 1); Vector4 c = new Vector4(x + Math.Abs(width), y + Math.Abs(height), 0, 1); Vector4 d = new Vector4(x, y + Math.Abs(height), 0, 1); vertices[0].Position = a; vertices[0].Color = color.ToArgb(); vertices[1].Position = b; vertices[1].Color = color.ToArgb(); vertices[2] = vertices[1]; vertices[3].Position = c; vertices[3].Color = color.ToArgb(); vertices[4] = vertices[3]; vertices[5].Position = d; vertices[5].Color = color.ToArgb(); vertices[6] = vertices[5]; vertices[6].Color = color.ToArgb(); vertices[7] = vertices[0]; Device.VertexFormat = CustomVertex.TransformedColored.Format; Device.DrawUserPrimitives(PrimitiveType.LineList, 4, vertices); }
public static void DrawBox(int ulx, int uly, int width, int height, float z, int color, Device device) { CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[4]; verts[0].X = (float) ulx; verts[0].Y = (float) uly; verts[0].Z = z; verts[0].Color = color; verts[1].X = (float) ulx; verts[1].Y = (float) uly + height; verts[1].Z = z; verts[1].Color = color; verts[2].X = (float) ulx + width; verts[2].Y = (float) uly; verts[2].Z = z; verts[2].Color = color; verts[3].X = (float) ulx + width; verts[3].Y = (float) uly + height; verts[3].Z = z; verts[3].Color = color; device.VertexFormat = CustomVertex.TransformedColored.Format; device.TextureState[0].ColorOperation = TextureOperation.Disable; device.DrawUserPrimitives(PrimitiveType.TriangleStrip, verts.Length - 2, verts); }
protected static CustomVertex.TransformedColored[] ConvertSideToTransformedColored(Polygon polygon, Color color) { var verts = new CustomVertex.TransformedColored[3]; if (polygon.Verteces.Count < 3) { return(verts); } verts[0].X = polygon.Verteces[0].X; verts[0].Y = polygon.Verteces[0].Y; verts[0].Z = polygon.Verteces[0].Z; verts[0].Color = color.ToArgb(); verts[1].X = polygon.Verteces[1].X; verts[1].Y = polygon.Verteces[1].Y; verts[1].Z = polygon.Verteces[1].Z; verts[1].Color = color.ToArgb(); verts[2].X = polygon.Verteces[2].X; verts[2].Y = polygon.Verteces[2].Y; verts[2].Z = polygon.Verteces[2].Z; verts[2].Color = color.ToArgb(); return(verts); }
public void Init() { string compilationErrors; try { this.effect = Effect.FromFile(D3DDevice.Instance.Device, "../../../Shaders/Oxygen.fx", null, null, ShaderFlags.None, null, out compilationErrors); } catch (Exception e) { throw new Exception("No pudo cargar el archivo csm"); } if (this.effect == null) { throw new Exception("Errores de compilación oxigen.fx: " + compilationErrors); } this.effect.Technique = "OxygenTechnique"; var black = 0x000000; var green = 0x00FF00; var red = 0xFF0000; var yellow = 0xFFFF00; vertices = new CustomVertex.TransformedColored[6]; vertices[0] = new CustomVertex.TransformedColored(this.MeterX0, this.MeterY0, 0, 1, black); vertices[1] = new CustomVertex.TransformedColored(this.MeterX0 + this.MeterSize, this.MeterY0, 0, 1, red); vertices[2] = new CustomVertex.TransformedColored(this.MeterX0, this.MeterY0 + this.MeterSize, 0, 1, green); vertices[3] = new CustomVertex.TransformedColored(this.MeterX0, this.MeterY0 + this.MeterSize, 0, 1, green); vertices[4] = new CustomVertex.TransformedColored(this.MeterX0 + this.MeterSize, this.MeterY0, 0, 1, red); vertices[5] = new CustomVertex.TransformedColored(this.MeterX0 + this.MeterSize, this.MeterY0 + this.MeterSize, 0, 1, yellow); }
public static void DrawSector(double startdeg, double enddeg, int centerX, int centerY, int radius, float z, int color, Device device) { int prec = 7; CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[prec + 2]; verts[0].X = centerX; verts[0].Y = centerY; verts[0].Z = z; verts[0].Rhw = 0.5f; verts[0].Color = System.Drawing.Color.Red.ToArgb(); // color; double degInc = (double)(enddeg - startdeg) / prec; for (int i = 0; i <= prec; i++) { verts[i + 1].X = (float)Math.Cos((double)(startdeg + degInc * i)) * radius + centerX; verts[i + 1].Y = (float)Math.Sin((double)(startdeg + degInc * i)) * radius * (-1.0f) + centerY; verts[i + 1].Z = z; verts[i + 1].Rhw = 0.5f; verts[i + 1].Color = color; } device.VertexFormat = CustomVertex.TransformedColored.Format; device.TextureState[0].ColorOperation = TextureOperation.Disable; device.DrawUserPrimitives(PrimitiveType.TriangleFan, verts.Length - 2, verts); }
public static void DrawBox(int ulx, int uly, int width, int height, float z, int color, Device device) { CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[4]; verts[0].X = (float)ulx; verts[0].Y = (float)uly; verts[0].Z = z; verts[0].Color = color; verts[1].X = (float)ulx; verts[1].Y = (float)uly + height; verts[1].Z = z; verts[1].Color = color; verts[2].X = (float)ulx + width; verts[2].Y = (float)uly; verts[2].Z = z; verts[2].Color = color; verts[3].X = (float)ulx + width; verts[3].Y = (float)uly + height; verts[3].Z = z; verts[3].Color = color; device.VertexFormat = CustomVertex.TransformedColored.Format; device.TextureState[0].ColorOperation = TextureOperation.Disable; device.DrawUserPrimitives(PrimitiveType.TriangleStrip, verts.Length - 2, verts); }
private void Form2_Paint(object sender, PaintEventArgs e) { float x = (this.ClientSize.Width - 200) / 2; float y = (this.ClientSize.Height - 200) / 2; m_device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(0, 0, 0).ToArgb(), 1.0f, 0); m_device.BeginScene(); m_device.VertexFormat = CustomVertex.TransformedColored.Format; // randomly generate a bunch of vertices List<CustomVertex.TransformedColored[]> drawList = new List<CustomVertex.TransformedColored[]>(); int randX, randY; Random autoRand = new Random(); int randRange = 100; for (int b = 0; b < 10; b++) { int randNumOfVerts = autoRand.Next(5, 15); CustomVertex.TransformedColored[] randVerts = new CustomVertex.TransformedColored[randNumOfVerts]; for (int i = 0; i < randNumOfVerts; i++) { randVerts[i].Position = new Vector4(0, 0, 0, 1.0f); randX = autoRand.Next(b * randRange, b * randRange + randRange);// +(b * randRange); randVerts[i].X = randX; randVerts[i].Color = System.Drawing.Color.FromArgb(autoRand.Next(0, 255), autoRand.Next(0, 255), autoRand.Next(0, 255)).ToArgb(); } for (int k = 0; k < randNumOfVerts; k++) { randY = autoRand.Next(0, 1000); randVerts[k].Y = randY; } drawList.Add(randVerts); } for (int l = 0; l < drawList.Count; l++) { int len = drawList[l].Length; m_device.DrawUserPrimitives(PrimitiveType.LineStrip, len-1, drawList[l]); } int numOfCurveLines = 10; CustomVertex.TransformedColored[] curve = new CustomVertex.TransformedColored[numOfCurveLines]; int startPosX = 1100; int startPosY = 800; for (int t = 0; t < numOfCurveLines; t++) { curve[t].Position = new Vector4(startPosX + (t * 5), startPosY, 0, 1.0f); curve[t].Color = System.Drawing.Color.FromArgb(200, 0, 200).ToArgb(); } rotate(3 * (Math.PI / 180), curve); //CustomVertex.TransformedColored[] textList = new CustomVertex.TransformedColored[10]; m_device.DrawUserPrimitives(PrimitiveType.LineStrip, curve.Length-1, curve); //m_device.DrawUserPrimitives(PrimitiveType.LineStrip, textList.Length, textList); m_device.EndScene(); m_device.Present(); }
/// <summary> /// This methods draws a trapezoid whose 90° angle is in the left side. /// </summary> /// <param name="position">The topLeft point of the trapezoid</param> /// <param name="size">The <b>whole size</b> of the trapezoid</param> /// <param name="triangleWidth">The extra width of the greater base side</param> /// <param name="isTriangleUpside">If the triangle part is to be drawn upside</param> /// <param name="isShaded">If shading is to be applied to the trapezoid polygons</param> /// <param name="color">Color of the trapezoid's inner area. The specified ShadeVertices /// delegate will then proceed to create a shaded version.</param> /// <param name="shadeMode">ShadeVertices delegate used.</param> /// <returns>A Trapezoidal ShapeDescriptor object.</returns> public static ShapeDescriptor DrawLeftTrapezoid(Vector2 position, Size size, int triangleWidth, bool isTriangleUpside, Color color, int borderSize, ShadingMode shadeMode) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[5]; int[] indices = new int[9]; Vector2 topLeft = new Vector2(position.X + triangleWidth, position.Y); Size innerSize = new Size(size.Width - borderSize, size.Height - borderSize); ShapeDescriptor sTrapezoid; int width = innerSize.Width; int height = innerSize.Height; int[] colors = shadeMode(color); int colorTopLeft = colors[0]; int colorTopRight = colors[1]; int colorBottomleft = colors[2]; int colorBottomRight = colors[3]; vertices[0] = new CustomVertex.TransformedColored(topLeft.X + innerSize.Width, topLeft.Y, 0, 1, colorTopRight); vertices[1] = new CustomVertex.TransformedColored(topLeft.X + innerSize.Width, topLeft.Y + innerSize.Height, 0, 1, colorBottomRight); vertices[2] = new CustomVertex.TransformedColored(topLeft.X, topLeft.Y + innerSize.Height, 0, 1, colorBottomleft); vertices[4] = new CustomVertex.TransformedColored(topLeft.X, topLeft.Y, 0, 1, colorTopLeft); if (isTriangleUpside) { vertices[3] = new CustomVertex.TransformedColored(topLeft.X - triangleWidth, topLeft.Y + innerSize.Height, 0, 1, colorBottomleft); } else { vertices[3] = new CustomVertex.TransformedColored(topLeft.X - triangleWidth, topLeft.Y, 0, 1, colorTopLeft); } indices[0] = 0; indices[1] = 2; indices[2] = 4; indices[3] = 0; indices[4] = 1; indices[5] = 2; indices[6] = 3; indices[7] = 4; indices[8] = 2; sTrapezoid = new ShapeDescriptor(3, vertices, indices); return(sTrapezoid); }
public List<CustomVertex.TransformedColored[]> Generator(CustomVertex.TransformedColored[] start, List<CustomVertex.TransformedColored[]> drawList) { Random rand = new Random(); for (int i = 0; i < 30; i++) { CustomVertex.TransformedColored[] newBox = new CustomVertex.TransformedColored[5]; for (int j = 0; j < newBox.Length; j++) { newBox[j].Color = System.Drawing.Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)).ToArgb(); newBox[j].X = start[j].X + (10 * i); newBox[j].Y = start[j].Y + (10 * i); } drawList.Add(newBox); } for (int k = 0; k < 30; k++) { CustomVertex.TransformedColored[] newBox = new CustomVertex.TransformedColored[5]; for (int j = 0; j < newBox.Length; j++) { newBox[j].Color = System.Drawing.Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)).ToArgb(); newBox[j].X = start[j].X - (10 * k); newBox[j].Y = start[j].Y - (10 * k); } drawList.Add(newBox); } for (int m = 0; m < 30; m++) { CustomVertex.TransformedColored[] newBox = new CustomVertex.TransformedColored[5]; for (int j = 0; j < newBox.Length; j++) { newBox[j].Color = System.Drawing.Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)).ToArgb(); newBox[j].X = start[j].X + (10 * m); newBox[j].Y = start[j].Y - (10 * m); } drawList.Add(newBox); } for (int l = 0; l < 30; l++) { CustomVertex.TransformedColored[] newBox = new CustomVertex.TransformedColored[5]; for (int j = 0; j < newBox.Length; j++) { newBox[j].Color = System.Drawing.Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)).ToArgb(); newBox[j].X = start[j].X - (10 * l); newBox[j].Y = start[j].Y + (10 * l); } drawList.Add(newBox); } return drawList; }
/// <summary> /// 在场景中加入点 /// </summary> /// <param name="x">点的x坐标</param> /// <param name="y">点的y坐标</param> /// <param name="color">点的颜色</param> public static void ImportPoint(float x, float y, Color color) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[1]; Vector4 p = new Vector4(x, y, 0, 1); vertices[0].Position = p; vertices[0].Color = color.ToArgb(); Device.VertexFormat = CustomVertex.TransformedColored.Format; Device.DrawUserPrimitives(PrimitiveType.PointList, 1, vertices); }
public void OnCreateVertexBuffer(object sender, EventArgs e) { VertexBuffer vb = (VertexBuffer)sender; GraphicsStream stm = vb.Lock(0, 0, 0); CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3]; verts[0].X = TriangleTopX; verts[0].Y = TriangleTopY; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Tomato.ToArgb(); verts[1].X = TriangleRightX; verts[1].Y = TriangleRightY; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Tomato.ToArgb(); verts[2].X = TriangleLeftX; verts[2].Y = TriangleLeftY; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.Tomato.ToArgb(); stm.Write(verts); vb.Unlock(); }
/// <summary> /// 在场景中加入渐变直线 /// </summary> /// <param name="x1">端点1的x坐标</param> /// <param name="y1">端点1的y坐标</param> /// <param name="x2">端点2的x坐标</param> /// <param name="y2">端点2的y坐标</param> /// <param name="color1">端点1的颜色</param> /// <param name="color2">端点2的颜色</param> public static void ImportLine(float x1, float y1, float x2, float y2, Color color1, Color color2) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[1]; Vector4 a = new Vector4(x1, y1, 0, 1); Vector4 b = new Vector4(x2, y2, 0, 1); vertices[0].Position = a; vertices[0].Color = color1.ToArgb(); vertices[1].Position = b; vertices[1].Color = color2.ToArgb(); Device.VertexFormat = CustomVertex.TransformedColored.Format; Device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices); }
public void OnCreateVertexBuffer(object sender, EventArgs e) { VertexBuffer buffer = (VertexBuffer)sender; CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3]; verts[0].Position = new Vector4(50, 50, 0.5f, 1); verts[0].Color = System.Drawing.Color.Black.ToArgb(); verts[1].Position = new Vector4(250, 50, 0.5f, 1); verts[1].Color = System.Drawing.Color.Black.ToArgb(); verts[2].Position = new Vector4(150, 250, 0.5f, 1); verts[2].Color = System.Drawing.Color.Black.ToArgb(); buffer.SetData(verts, 0, LockFlags.None); }
public DialogBox() { textBig.changeFont(new System.Drawing.Font("Arial Black", 10f)); vertexBuffer = new CustomVertex.TransformedColored[6]; vertexBuffer[0] = new CustomVertex.TransformedColored(0, 0, 0, 1, 0x000000); // Top-Left vertexBuffer[1] = new CustomVertex.TransformedColored(100, 0, 0, 1, 0xFF0000); // Top-Right vertexBuffer[2] = new CustomVertex.TransformedColored(100, 100, 0, 1, 0xFFFF00); // Bottom-Right vertexBuffer[3] = new CustomVertex.TransformedColored(0, 0, 0, 1, 0x000000); // Top-Left vertexBuffer[4] = new CustomVertex.TransformedColored(0, 100, 0, 1, 0x00FF00); // Bottom-Left vertexBuffer[5] = new CustomVertex.TransformedColored(100, 100, 0, 1, 0xFFFF00); // Bottom-Right updater = MainUpdate; renderer = MainRender; }
public void OnCreateVertexBuffer(object sender, EventArgs e) { VertexBuffer vb = (VertexBuffer)sender; GraphicsStream stm = vb.Lock(0, 0, 0); CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[BufferSize]; verts[0].X = 50; verts[0].Y = 50; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Black.ToArgb(); verts[1].X = 250; verts[1].Y = 50; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Black.ToArgb(); verts[2].X = 150; verts[2].Y = 250; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.Black.ToArgb(); stm.Write(verts); vb.Unlock(); }
protected static CustomVertex.TransformedColored[] ConvertEdgeToTransformedColored(Edge edge, Color color) { var verts = new CustomVertex.TransformedColored[2]; verts[0].X = edge.Vertex1.X; verts[0].Y = edge.Vertex1.Y; verts[0].Z = edge.Vertex1.Z; verts[0].Color = color.ToArgb(); verts[1].X = edge.Vertex2.X; verts[1].Y = edge.Vertex2.Y; verts[1].Z = edge.Vertex2.Z; verts[1].Color = color.ToArgb(); return(verts); }
private void DefineTriange() { GraphicsStream stream = buffer.Lock(0, 0, 0); var vert0 = new CustomVertex.TransformedColored { Color = 128, Rhw = 1, X = 150, Y = 50, Z = .5F }; var vert1 = new CustomVertex.TransformedColored { Color = 8192, Rhw = 1, X = 250, Y = 250, Z = .5F }; var vert2 = new CustomVertex.TransformedColored { Color = 327670, Rhw = 1, X = 50, Y = 250, Z = .5F }; stream.Write(new[] { vert0, vert1, vert2 }); buffer.Unlock(); }
private void drawSimplePoint(Device device, float x, float y, Color colorWithAlpha) { CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[1]; verts[0].X = x; verts[0].Y = y; verts[0].Z = 0.1f; verts[0].Color = colorWithAlpha.ToArgb(); float lastSize = device.RenderState.PointSize; device.RenderState.PointSize = 7; device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.PointList, 1, verts); device.RenderState.PointSize = lastSize; }
private static CustomVertex.TransformedColored[] GetTransformedColoredFromVerteces(Vertex Vertex1, Vertex Vertex2, Color color) { var verts = new CustomVertex.TransformedColored[2]; verts[0].X = Vertex1.X; verts[0].Y = Vertex1.Y; verts[0].Z = Vertex1.Z; verts[0].Color = color.ToArgb(); verts[1].X = Vertex2.X; verts[1].Y = Vertex2.Y; verts[1].Z = Vertex2.Z; verts[1].Color = color.ToArgb(); return(verts); }
private void FillRect(RectangleF rect, Color color) { var vertecies = new CustomVertex.TransformedColored[4]; vertecies[0].Position = new Vector4(rect.X, rect.Y + rect.Height, 0, 0.5f); vertecies[1].Position = new Vector4(rect.X, rect.Y, 0, 0.5f); vertecies[2].Position = new Vector4(rect.X + rect.Width, rect.Y + rect.Height, 0, 0.5f); vertecies[3].Position = new Vector4(rect.X + rect.Width, rect.Y, 0, 0.5f); vertecies[0].Color = color.ToArgb(); vertecies[1].Color = color.ToArgb(); vertecies[2].Color = color.ToArgb(); vertecies[3].Color = color.ToArgb(); device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vertecies); }
public void DrawRectangle(float x, float y, float width, float height, Color color) { _device.Device.VertexFormat = CustomVertex.TransformedColored.Format; color = Color.Red; var vertex = new CustomVertex.TransformedColored[4]; vertex[0].Position = new Vector4(x, y, 0f, 0f); vertex[0].Color = color.ToArgb(); vertex[1].Position = new Vector4(x + width, y, 0f, 0f); vertex[1].Color = color.ToArgb(); vertex[2].Position = new Vector4(x, y + height, 0f, 0f); vertex[2].Color = color.ToArgb(); vertex[3].Position = new Vector4(x + width, y + height, 0f, 0f); vertex[3].Color = color.ToArgb(); _device.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vertex); }
/*------------------------------------------------------------------------- * 線の描画 * ---------------------------------------------------------------------------*/ public void DrawLineStrip(Vector3 pos, Vector2[] vec, int color) { CustomVertex.TransformedColored[] vb = new CustomVertex.TransformedColored[vec.Length]; for (int i = 0; i < vec.Length; i++) { vb[i].X = pos.X + vec[i].X; vb[i].Y = pos.Y + vec[i].Y; vb[i].Z = pos.Z; vb[i].Rhw = 1f; vb[i].Color = color; } base.device.VertexFormat = CustomVertex.TransformedColored.Format; base.device.SetTexture(0, null); base.device.DrawUserPrimitives(PrimitiveType.LineStrip, vec.Length - 1, vb); }
public static void DrawLine(Vector2[] linePoints, int color, Device device) { CustomVertex.TransformedColored[] lineVerts = new CustomVertex.TransformedColored[linePoints.Length]; for (int i = 0; i < linePoints.Length; i++) { lineVerts[i].X = linePoints[i].X; lineVerts[i].Y = linePoints[i].Y; lineVerts[i].Z = 0.0f; lineVerts[i].Color = color; } device.TextureState[0].ColorOperation = TextureOperation.Disable; device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.LineStrip, lineVerts.Length - 1, lineVerts); }
public static ShapeDescriptor DrawEquilateralTriangle(Vector2 leftVertex, float sideLength, Color color, bool isShaded, bool isTriangleUpside) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[3]; Color shaded; float heightOffset = (float)(sideLength / 2 * Math.Sqrt(3)); int col1 = color.ToArgb(); int col2; if (isShaded) { shaded = Color.FromArgb(color.A, ColorOperator.Scale(color, darkShadeFactor)); col2 = shaded.ToArgb(); } else { col2 = col1; } vertices[0] = new CustomVertex.TransformedColored(leftVertex.X, leftVertex.Y, 0, 1, col2); vertices[1] = new CustomVertex.TransformedColored(leftVertex.X + sideLength, leftVertex.Y, 0, 1, col2); int[] indices = new int[3]; if (isTriangleUpside) { heightOffset *= -1; indices[0] = 0; indices[1] = 1; indices[2] = 2; } else { indices[0] = 2; indices[1] = 0; indices[2] = 1; } vertices[2] = new CustomVertex.TransformedColored(leftVertex.X + sideLength / 2, leftVertex.Y + heightOffset, 0, 1, col1); return(new ShapeDescriptor(1, vertices, indices)); }
/// <summary> /// Actualizar mesh del recuadro de seleccion /// </summary> public void updateMesh(TGCVector2 min, TGCVector2 max) { //Horizontal arriba vertices[0] = new CustomVertex.TransformedColored(min.X, min.Y, 0, 1, RECT_COLOR); vertices[1] = new CustomVertex.TransformedColored(max.X, min.Y, 0, 1, RECT_COLOR); //Horizontal abajo vertices[2] = new CustomVertex.TransformedColored(min.X, max.Y, 0, 1, RECT_COLOR); vertices[3] = new CustomVertex.TransformedColored(max.X, max.Y, 0, 1, RECT_COLOR); //Vertical izquierda vertices[4] = new CustomVertex.TransformedColored(min.X, min.Y, 0, 1, RECT_COLOR); vertices[5] = new CustomVertex.TransformedColored(min.X, max.Y, 0, 1, RECT_COLOR); //Vertical derecha vertices[6] = new CustomVertex.TransformedColored(max.X, min.Y, 0, 1, RECT_COLOR); vertices[7] = new CustomVertex.TransformedColored(max.X, max.Y, 0, 1, RECT_COLOR); }
public override void Update() { int clrInt = clr.ToArgb(); int clrGrey = Color.Gray.ToArgb(); float progressX = (dimensions.Width / 100f) * progress; clrQuadProgress[0] = new CustomVertex.TransformedColored(origin.X, origin.Y + dimensions.Height, 0, 1, clrInt); clrQuadProgress[1] = new CustomVertex.TransformedColored(origin.X, origin.Y, 0, 1, clrInt); clrQuadProgress[2] = new CustomVertex.TransformedColored(origin.X + progressX, origin.Y + dimensions.Height, 0, 1, clrInt); clrQuadProgress[3] = new CustomVertex.TransformedColored(origin.X + progressX, origin.Y, 0, 1, clrInt); clrQuadEmptyProgress[0] = new CustomVertex.TransformedColored(origin.X + progressX, origin.Y + dimensions.Height, 0, 1, clrGrey); clrQuadEmptyProgress[1] = new CustomVertex.TransformedColored(origin.X + progressX, origin.Y, 0, 1, clrGrey); clrQuadEmptyProgress[2] = new CustomVertex.TransformedColored(origin.X + dimensions.Width, origin.Y + dimensions.Height, 0, 1, clrGrey); clrQuadEmptyProgress[3] = new CustomVertex.TransformedColored(origin.X + dimensions.Width, origin.Y, 0, 1, clrGrey); }
/// <summary> /// Actualizar mesh del recuadro de seleccion /// </summary> public void updateMesh(Vector2 min, Vector2 max) { //Horizontal arriba vertices[0] = new CustomVertex.TransformedColored(min.X, min.Y, 0, 1, RECT_COLOR); vertices[1] = new CustomVertex.TransformedColored(max.X, min.Y, 0, 1, RECT_COLOR); //Horizontal abajo vertices[2] = new CustomVertex.TransformedColored(min.X, max.Y, 0, 1, RECT_COLOR); vertices[3] = new CustomVertex.TransformedColored(max.X, max.Y, 0, 1, RECT_COLOR); //Vertical izquierda vertices[4] = new CustomVertex.TransformedColored(min.X, min.Y, 0, 1, RECT_COLOR); vertices[5] = new CustomVertex.TransformedColored(min.X, max.Y, 0, 1, RECT_COLOR); //Vertical derecha vertices[6] = new CustomVertex.TransformedColored(max.X, min.Y, 0, 1, RECT_COLOR); vertices[7] = new CustomVertex.TransformedColored(max.X, max.Y, 0, 1, RECT_COLOR); }
private void Form4_Paint(object sender, PaintEventArgs e) { List<CustomVertex.TransformedColored[]> drawList = new List<CustomVertex.TransformedColored[]>(); m_device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(0, 0, 0).ToArgb(), 1.0f, 0); m_device.BeginScene(); m_device.VertexFormat = CustomVertex.TransformedColored.Format; int randX, randY; int maxDist = 100; Random rand = new Random(); for (int b = 0; b < 100; b++) { int randNumOfVerts = rand.Next(5, 15); CustomVertex.TransformedColored[] randVerts = new CustomVertex.TransformedColored[randNumOfVerts]; randVerts[0].Position = new Vector4(rand.Next(0, this.ClientSize.Width), rand.Next(0, this.ClientSize.Height), 0, 1.0f); for (int i = 1; i < randNumOfVerts-1; i++) { randVerts[i] = randVerts[0]; randX = rand.Next((int)randVerts[0].X - maxDist, (int)randVerts[0].X + maxDist); randVerts[i].X = randX; randVerts[i].Color = System.Drawing.Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)).ToArgb(); } for (int k = 1; k < randNumOfVerts-1; k++) { randY = rand.Next((int)randVerts[0].Y - maxDist, (int)randVerts[0].Y + maxDist); randVerts[k].Y = randY; } randVerts[randNumOfVerts - 1] = randVerts[0]; drawList.Add(randVerts); } for (int j = 0; j < drawList.Count; j++) { if (j % 2 == 1) m_device.DrawUserPrimitives(PrimitiveType.LineStrip, drawList[j].Length - 1, drawList[j]); else m_device.DrawUserPrimitives(PrimitiveType.TriangleFan, drawList[j].Length - 1, drawList[j]); } m_device.EndScene(); m_device.Present(); }
private void Render() { CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3]; verts[0].Position = new Vector4(renderWindow.Width / 2.0f, 50.0f, 0.5f, 1.0f); verts[0].Color = Color.Red.ToArgb(); verts[1].Position = new Vector4(renderWindow.Width - (renderWindow.Width / 5.0f), renderWindow.Height - (renderWindow.Height / 5.0f), 0.5f, 1.0f); verts[1].Color = Color.Green.ToArgb(); verts[2].Position = new Vector4(renderWindow.Width / 5.0f, renderWindow.Height - (renderWindow.Height / 5.0f), 0.5f, 1.0f); verts[2].Color = Color.Blue.ToArgb(); while (true) { device.Clear(ClearFlags.Target, bgColor, zDepth, 0); device.BeginScene(); device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, verts); device.EndScene(); device.Present(); } }
private static void Automatic(Point pos, Point targ, Color color) { int x1, y1, x2, y2; if (pos.X < targ.X) { x1 = Rand.Next(pos.X, targ.X); x2 = Rand.Next(pos.X, targ.X); } else { x1 = Rand.Next(targ.X, pos.X); x2 = Rand.Next(targ.X, pos.X); } if (pos.X == targ.X) { if (pos.Y < targ.Y) { y1 = Rand.Next(pos.Y, targ.Y); y2 = Rand.Next(pos.Y, targ.Y); } else { y1 = Rand.Next(targ.Y, pos.Y); y2 = Rand.Next(targ.Y, pos.Y); } } else { double a, b; a = (targ.Y - pos.Y) / (1.0 * (targ.X - pos.X)); b = pos.Y - a * pos.X; y1 = (int)(a * x1 + b); y2 = (int)(a * x2 + b); } CustomVertex.TransformedColored[] line = new CustomVertex.TransformedColored[2]; line[0].Position = new Microsoft.DirectX.Vector4(x1, y1, 1, 1); line[0].Color = color.ToArgb(); line[1].Position = new Microsoft.DirectX.Vector4(x2, y2, 1, 1); line[1].Color = color.ToArgb(); Drawing.OurDevice.VertexFormat = CustomVertex.TransformedColored.Format; Drawing.OurDevice.DrawUserPrimitives(PrimitiveType.LineList, 1, line); }
public static void DrawFutureWays() { if ((ConstrPanelControl.ConstrSelected) && (WorkSpace.DX < Mouse.DX) && (WorkSpace.RightBorder.X > Mouse.DX) && (WorkSpace.DY < Mouse.DY) && (WorkSpace.DownBorder.Y > Mouse.DY) && (AIUnits.CanPlace(ConstrPanelControl.SlotType, WorkSpace.Space.X + Mouse.DX - WorkSpace.DX, WorkSpace.Space.Y + Mouse.DY - WorkSpace.DY))) { List<TransWay> ways = AIUnits.GetFutureWays(ConstrPanelControl.SlotType, WorkSpace.Space.X + Mouse.DX - WorkSpace.LeftBorder.Width, WorkSpace.Space.Y + Mouse.DY - WorkSpace.UpBorder.Height); CustomVertex.TransformedColored[] lines = new CustomVertex.TransformedColored[ways.Count * 2]; for (int i = 0; i < ways.Count; i++) { lines[2 * i].Position = new Microsoft.DirectX.Vector4(ways[i].A.X - WorkSpace.Space.X + WorkSpace.DX, ways[i].A.Y - WorkSpace.Space.Y + WorkSpace.DY, 1, 1); lines[2 * i].Color = ways[i].Coloring.ToArgb(); lines[2 * i + 1].Position = new Microsoft.DirectX.Vector4(ways[i].B.X - WorkSpace.Space.X + WorkSpace.DX, ways[i].B.Y - WorkSpace.Space.Y + WorkSpace.DY, 1, 1); lines[2 * i + 1].Color = ways[i].Coloring.ToArgb(); } Drawing.OurSprite.Begin(SpriteFlags.AlphaBlend); Drawing.OurDevice.VertexFormat = CustomVertex.TransformedColored.Format; if (lines.Length > 0) Drawing.OurDevice.DrawUserPrimitives(PrimitiveType.LineList, lines.Length / 2, lines); Drawing.OurSprite.End(); } }
public static void DrawSector(double startAngle, double endAngle, int centerX, int centerY, int radius, float z, int color, Device device) { int prec = 7; CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[prec + 2]; verts[0].X = centerX; verts[0].Y = centerY; verts[0].Z = z; verts[0].Color = color; double angleInc = (double) (endAngle - startAngle)/prec; for (int i = 0; i <= prec; i++) { verts[i + 1].X = (float) Math.Cos((double) (startAngle + angleInc*i))*radius + centerX; verts[i + 1].Y = (float) Math.Sin((double) (startAngle + angleInc*i))*radius*(-1.0f) + centerY; verts[i + 1].Z = z; verts[i + 1].Color = color; } device.VertexFormat = CustomVertex.TransformedColored.Format; device.TextureState[0].ColorOperation = TextureOperation.Disable; device.DrawUserPrimitives(PrimitiveType.TriangleFan, verts.Length - 2, verts); }
// Create the Vertex Buffer, where our Points are stored // along with their position in 3D space in X, Y, and Z coordinates // also any color or texture information public void CreateVertexBuffer(object sender, EventArgs e) { // VertexBuffer buffer = (VertexBuffer)sender; CustomVertex.TransformedColored[] VerticeArray = // Declare a new Array called VerticeArray new CustomVertex.TransformedColored[4]; // Type of Vertices and number of Points // Draw Polygon from Vertice Points in a clockwise direction VerticeArray[0].Position = new Vector4(50, 50, 0.5f, 1); // Top Left Vertice VerticeArray[0].Color = System.Drawing.Color.Purple.ToArgb(); VerticeArray[1].Position = new Vector4(250, 50, 0.5f, 1); // Top Right VerticeArray[1].Color = System.Drawing.Color.Tomato.ToArgb(); VerticeArray[2].Position = new Vector4(250, 250, 0.5f, 1); // Bottom Right VerticeArray[2].Color = System.Drawing.Color.Tomato.ToArgb(); VerticeArray[3].Position = new Vector4(50, 250, 0.5f, 1); // Bottom Left VerticeArray[3].Color = System.Drawing.Color.Purple.ToArgb(); vertexBuffer.SetData(VerticeArray, 0, LockFlags.None); }
public void VertexContainer( object sender, EventArgs e ) { Device dev = ( Device )sender; vertexBuffer = new VertexBuffer( typeof( CustomVertex.TransformedColored ), 3, dev, 0, CustomVertex.TransformedColored.Format, Pool.Default ); GraphicsStream GraphixStream = vertexBuffer.Lock( 0, 0, 0 ); CustomVertex.TransformedColored[] VerticeArray = new CustomVertex.TransformedColored[3]; VerticeArray[0].Position = new Vector4( 50, 50, 0.5f, 1 ); // top left Vertice VerticeArray[0].Color = System.Drawing.Color.Orange.ToArgb(); VerticeArray[1].Position = new Vector4( 250, 50, 0.5f, 1 ); // top right VerticeArray[1].Color = System.Drawing.Color.Yellow.ToArgb(); VerticeArray[2].Position = new Vector4( 150, 250, 0.5f, 1 ); // bottom VerticeArray[2].Color = System.Drawing.Color.Red.ToArgb(); GraphixStream.Write( VerticeArray ); vertexBuffer.Unlock(); }
public void DrawLine(Point src, Point dest, Color color) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[2]; vertices[0].Position = new Vector4(src.X, src.Y, 0.0f, 1.0f); vertices[0].Color = color.ToArgb(); vertices[0].Rhw = 1.0f; vertices[1].Position = new Vector4(dest.X, dest.Y, 0.0f, 1.0f); vertices[1].Color = color.ToArgb(); vertices[1].Rhw = 1.0f; m_pVBLine.SetData(vertices, 0, LockFlags.Discard); m_d3dDevice.SetTexture(0, null); m_d3dDevice.VertexFormat = CustomVertex.TransformedColored.Format; m_d3dDevice.SetStreamSource(0, m_pVBLine, 0); m_d3dDevice.DrawPrimitives(PrimitiveType.LineList, 0, 2); }
private void updateMouseVertices(int x, int y, double cursorWidth, DISPLAY_RANGE range, float height, float yOffset) { if (device == null || functionList == null) return; if (!validMouse) { System.Single yMin = yOffset; System.Single yMax = height + yOffset; // Check if the cursor is in this row bool inRow = false; if (y >= (int)yMin && y <= (int)yMax) inRow = true; // Set the mouse text values mouseTextPos = new Point(x + 2, (int) yMin + 3); mouseNumCalls = functionList.getDataSize( ((double) (x - range.xMin)/(double) (range.xMax - range.xMin))*(range.tMax - range.tMin) + range.tMin, cursorWidth); if (inRow) { // Initialize the vertices verticesMouse = new CustomVertex.TransformedColored[4]; for (int n = 0; n < verticesMouse.Length; n++) verticesMouse[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.0f, 1.0f, Color.FromArgb(0, 255, 0). ToArgb()); // Set the vertice positions int i = 0; verticesMouse[i].X = x + 2; verticesMouse[i].Y = yMin; verticesMouse[i++].Z = 0.4f; verticesMouse[i].X = x + 2; verticesMouse[i].Y = yMax; verticesMouse[i++].Z = 0.4f; verticesMouse[i].X = x - 2; verticesMouse[i].Y = yMin; verticesMouse[i++].Z = 0.4f; verticesMouse[i].X = x - 2; verticesMouse[i].Y = yMax; verticesMouse[i++].Z = 0.4f; }else { // Create the vertex buffer for the current mouse location // Initialize the vertices verticesMouse = new CustomVertex.TransformedColored[2]; for (int n = 0; n < verticesMouse.Length; n++) verticesMouse[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.0f, 1.0f, Color.FromArgb(0, 100, 0). ToArgb()); // Set the vertice positions int i = 0; verticesMouse[i].X = x; verticesMouse[i].Y = yMin; verticesMouse[i++].Z = 0.4f; verticesMouse[i].X = x; verticesMouse[i].Y = yMax; verticesMouse[i++].Z = 0.4f; } // Write the vertex drawing buffers if (vertexBufferMouse != null) vertexBufferMouse.Dispose(); vertexBufferMouse = new VertexBuffer(typeof (CustomVertex.TransformedColored), verticesMouse.Length, device, 0, CustomVertex.TransformedColored.Format, Pool.Default); GraphicsStream stm = vertexBufferMouse.Lock(0, 0, 0); stm.Seek(0, SeekOrigin.Begin); stm.Write(verticesMouse); vertexBufferMouse.Unlock(); validMouse = true; } }
private void updateSelectionVertices(double selectStart, double selectEnd, DISPLAY_RANGE range, float height, float yOffset, bool isSelected) { if (device == null || functionList == null) return; if (!validSelection) { int colour; if (isSelected) { colour = Color.FromArgb(80, 80, 80).ToArgb(); // A bit lighter gray }else { colour = Color.FromArgb(40, 40, 40).ToArgb(); // Very dark gray } // Update the selection vertices verticesSelectionBackground = new CustomVertex.TransformedColored[3*2]; // Two triangles for a box. // General parameters System.Single z = 0.5f; System.Single yMin = yOffset; System.Single yMax = height + yOffset; int i = 0; // Draw the background verticesSelectionBackground[i++] = new CustomVertex.TransformedColored( (float) (((selectStart - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin), yMin, z, 1.0f, colour); verticesSelectionBackground[i++] = new CustomVertex.TransformedColored( (float) (((selectEnd - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin), yMin, z, 1.0f, colour); verticesSelectionBackground[i++] = new CustomVertex.TransformedColored( (float) (((selectEnd - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin), yMax, z, 1.0f, colour); verticesSelectionBackground[i++] = new CustomVertex.TransformedColored( (float) (((selectStart - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin), yMin, z, 1.0f, colour); verticesSelectionBackground[i++] = new CustomVertex.TransformedColored( (float) (((selectStart - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin), yMax, z, 1.0f, colour); verticesSelectionBackground[i++] = new CustomVertex.TransformedColored( (float) (((selectEnd - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin), yMax, z, 1.0f, colour); if (vertexBufferSelectionBackground != null) vertexBufferSelectionBackground.Dispose(); vertexBufferSelectionBackground = new VertexBuffer(typeof (CustomVertex.TransformedColored), verticesSelectionBackground.Length, device, 0, CustomVertex.TransformedColored.Format, Pool.Default); GraphicsStream stm = vertexBufferSelectionBackground.Lock(0, 0, 0); stm.Seek(0, SeekOrigin.Begin); stm.Write(verticesSelectionBackground); vertexBufferSelectionBackground.Unlock(); validSelection = true; } }
public void remove_particle(int index) { if (this.count <= 1) this.alive = false; this.count--; if (this.count - 1 >= 0) { if (index == -1) index = count-1; if (index >= 0) { ParticleInfo[index] = new myownvertexformat(); vert[index] = new CustomVertex.TransformedColored(); //for (int i = index; i < count; i++) //{ // ParticleInfo[i] = ParticleInfo[i + 1]; // vert[i] = vert[i + 1]; //} } } }
public void add_particle(float X, float Y, int color, Vector2 speed,int lifetime) { if (count + 1 < ParticleInfo.Length) { count++; ParticleInfo[count] = new myownvertexformat(); ParticleInfo[count].speed = speed; ParticleInfo[count].lifetime = lifetime; ParticleInfo[count].lifecount = 0; vert[count] = new CustomVertex.TransformedColored(X, Y, 0, 0, color); } }
public void OnCreateVertexBuffer(object sender, EventArgs e) { Color gray = Color.FromArgb(127, Color.Black); CustomVertex.TransformedColored[] points = new CustomVertex.TransformedColored[4] { new CustomVertex.TransformedColored(0,0,0,1,gray.ToArgb()), new CustomVertex.TransformedColored(0,sy,0,1,gray.ToArgb()), new CustomVertex.TransformedColored(sx,0,0,1,gray.ToArgb()), new CustomVertex.TransformedColored(sx,sy,0,1,gray.ToArgb()), }; CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[6] { points[0], points[1], points[3], points[0], points[2], points[3], }; VertexBuffer vb = (VertexBuffer)sender; vb.SetData((object)vertices, 0, LockFlags.None); }
public void OnCreateBillBoard(object sender, EventArgs e) { CustomVertex.TransformedColored[] points = new CustomVertex.TransformedColored[4] { new CustomVertex.TransformedColored(5,5,0,1,Color.FromArgb(50,Color.Blue).ToArgb()), new CustomVertex.TransformedColored(5,105,0,1,Color.FromArgb(50,Color.Magenta).ToArgb()), new CustomVertex.TransformedColored(105,5,0,1,Color.FromArgb(50,Color.MediumBlue).ToArgb()), new CustomVertex.TransformedColored(105,105,0,1,Color.FromArgb(50,Color.Linen).ToArgb()), }; CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[6] { points[0], points[1], points[3], points[0], points[2], points[3], }; VertexBuffer vb = (VertexBuffer)sender; vb.SetData((object)vertices, 0, LockFlags.None); }
private void ResizeFilledRectVB(Rectangle rect, Color colorLT, Color colorRT, Color colorLB, Color colorRB, Texture texture) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4]; vertices[0].Position = new Vector4(rect.X, rect.Y, 0.0f, 1.0f); vertices[0].Color = colorLT.ToArgb(); vertices[0].Rhw = 1.0f; vertices[1].Position = new Vector4(rect.X + rect.Width, rect.Y, 0.0f, 1.0f); vertices[1].Color = colorRT.ToArgb(); vertices[1].Rhw = 1.0f; // [1]? vertices[2].Position = new Vector4(rect.X, rect.Y + rect.Height, 0.0f, 1.0f); vertices[2].Color = colorLB.ToArgb(); vertices[2].Rhw = 1.0f; // [2]? vertices[3].Position = new Vector4(rect.X + rect.Width, rect.Y + rect.Height, 0.0f, 1.0f); vertices[3].Color = colorRB.ToArgb(); vertices[3].Rhw = 1.0f; // [3]? m_pVBFilledRect.SetData(vertices, 0, LockFlags.Discard); }
/// <summary> /// Sets the data for the current vertex buffers. /// </summary> /// <param name="data"></param> /// <param name="device"></param> public void setData(List<oSingleData> data, ref Device device) { if (data == null || device == null) return; // Clear the link vertex arrays vertexBufferLinks = null; vertexLinks = null; // Clear the status of the previous executed functions foreach (int index in executedVertexIndices) { // Clear this vertex colouring vertexFunctions[index].Color = Color.FromArgb(60, 60, 60).ToArgb(); } executedVertexIndices.Clear(); // Clear the vertex function call links vertexLinks = new CustomVertex.TransformedColored[data.Count*2]; vertexLinksCount = 0; if (data.Count > 0) { // Convert the data //Int32[] callArray = (Int32[]) oMemoryFunctions.RawDataToObject(ref data, typeof (Int32[])); //uint[] callArray = oMemoryFunctions.ByteArrayToUintArray(ref data); // Process the new function calls) for (int i = 0; i < data.Count; i++) { // Process this function call // Load the source function address uint sourceFunctionAddress; if (directCallSourcesHash.Contains((uint) data[i].source)) { // We can perform a hash table lookup. This was probably a direct fixed offset call. sourceFunctionAddress = (uint) directCallSourcesHash[(uint) data[i].source]; } else { // We have to do a binary search lookup, this is more expensive computationally. This was probably a PE table call. int n = functionLocationsList.BinarySearch((uint) data[i].source); if (n < 0) n = ~n - 1; if (n < 0) n = 0; sourceFunctionAddress = (uint) functionLocationsList[n]; } // Load the source vertex index, or create a new vertex if needed int sourceVertexIndex; if (functionLocationsHash.Contains(sourceFunctionAddress)) { sourceVertexIndex = (int) functionLocationsHash[sourceFunctionAddress]; } else { // We need to create the vertex for this funciton sourceVertexIndex = moduleManager.addNewFunction(sourceFunctionAddress); } if (sourceVertexIndex >= 0) { // Highlight the source index function vertexFunctions[sourceVertexIndex].Color = Color.FromArgb(255, 255, 50).ToArgb(); executedVertexIndices.Add(sourceVertexIndex); } // Load the destination vertex index, or create a new vertex if needed int destinationVertexIndex; if (functionLocationsHash.Contains((uint) ((oSingleData) data[i]).destination)) { destinationVertexIndex = (int) functionLocationsHash[(uint) data[i].destination]; } else { // We need to create the vertex for this funciton destinationVertexIndex = moduleManager.addNewFunction((uint) data[i].destination); } if (destinationVertexIndex >= 0) { // Highlight the destination index function vertexFunctions[destinationVertexIndex].Color = Color.FromArgb(255, 255, 50).ToArgb(); executedVertexIndices.Add(destinationVertexIndex); } // Draw the link line if (destinationVertexIndex >= 0 && sourceVertexIndex >= 0) { vertexLinks[vertexLinksCount] = new CustomVertex.TransformedColored(vertexFunctions[sourceVertexIndex].X, vertexFunctions[sourceVertexIndex].Y + 1, vertexFunctions[sourceVertexIndex].Z, vertexFunctions[sourceVertexIndex].Rhw, Color.FromArgb(150, 0, 0).ToArgb()); vertexLinks[vertexLinksCount + 1] = new CustomVertex.TransformedColored(vertexFunctions[destinationVertexIndex].X, vertexFunctions[destinationVertexIndex].Y + 1, vertexFunctions[destinationVertexIndex].Z, vertexFunctions[destinationVertexIndex].Rhw, Color.FromArgb(0, 0, 150).ToArgb()); vertexLinksCount += 2; } } } else { vertexLinksCount = 0; } // Write the function vertex buffers if (vertexFunctionsCount > 0) { CustomVertex.TransformedColored[] vertexFunctionsRange = new CustomVertex.TransformedColored[vertexFunctionsCount]; Array.Copy(vertexFunctions, vertexFunctionsRange, vertexFunctionsRange.Length); if (vertexBufferFunctions != null) vertexBufferFunctions.Dispose(); vertexBufferFunctions = new VertexBuffer(typeof (CustomVertex.TransformedColored), vertexFunctionsCount, device, 0, CustomVertex.TransformedColored.Format, Pool.Default); GraphicsStream stm = vertexBufferFunctions.Lock(0, 0, 0); stm.Seek(0, SeekOrigin.Begin); stm.Write(vertexFunctionsRange); vertexBufferFunctions.Unlock(); stm.Dispose(); } // Write the link line vertex buffers if (vertexLinksCount > 0) { CustomVertex.TransformedColored[] vertexLinksRange = new CustomVertex.TransformedColored[vertexLinksCount]; Array.Copy(vertexLinks, vertexLinksRange, vertexLinksRange.Length); if (vertexBufferLinks != null) vertexBufferLinks.Dispose(); vertexBufferLinks = new VertexBuffer(typeof (CustomVertex.TransformedColored), vertexLinksCount, device, 0, CustomVertex.TransformedColored.Format, Pool.Default); GraphicsStream stm = vertexBufferLinks.Lock(0, 0, 0); stm.Seek(0, SeekOrigin.Begin); stm.Write(vertexLinksRange); vertexBufferLinks.Unlock(); stm.Dispose(); } else { vertexBufferLinks = null; } }
private void ResizeRectVB( Rectangle rect, Color colorLT, Color colorRT, Color colorLB, Color colorRB ) { CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[5]; vertices[0].Position = new Vector4(rect.X, rect.Y, 0.0f, 1.0f); vertices[0].Color = colorLT.ToArgb(); vertices[1].Position = new Vector4(rect.X + rect.Width, rect.Y, 0.0f, 1.0f); vertices[1].Color = colorRT.ToArgb(); vertices[2].Position = new Vector4(rect.X + rect.Width, rect.Y + rect.Height, 0.0f, 1.0f); vertices[2].Color = colorRB.ToArgb(); vertices[3].Position = new Vector4(rect.X, rect.Y + rect.Height, 0.0f, 1.0f); vertices[3].Color = colorLB.ToArgb(); vertices[4].Position = new Vector4(rect.X, rect.Y, 0.0f, 2.0f); vertices[4].Color = colorLT.ToArgb(); m_pVBRect.SetData(vertices, 0, LockFlags.Discard); }
public static void generate_rain(int level, ref Device def, int color) { Srbuffer = def; vert = new CustomVertex.TransformedColored[level]; Random rnd = new Random(); lineListIndices = new int[(level * 2)]; for (int i = 0; i < level; i++) { vert[i] = new CustomVertex.TransformedColored(rnd.Next(1000), 0, 0, 0, color); lineListIndices[i * 2] = (int)(i + 1); lineListIndices[(i * 2) + 1] = (int)(i + 2); } lineListIndices[(level * 2) - 1] = 1; }