Esempio n. 1
0
 /// <summary>
 /// Fills a Rectangle.
 /// </summary>
 /// <param name="color">The Color.</param>
 /// <param name="rectangle">The Rectangle.</param>
 public void FillRectangle(Color color, Rectangle rectangle)
 {
     var line = new Line(_direct3D9Device) {Antialias = true, Width = rectangle.Height};
     line.Begin();
     line.Draw(
         DirectXHelper.ConvertToVertex(new Vector2(rectangle.X, rectangle.Center.Y),
             new Vector2(rectangle.X + rectangle.Width, rectangle.Center.Y)),
         DirectXHelper.ConvertColor(color));
     line.End();
 }
Esempio n. 2
0
        /// <summary>
        /// Hook for IDirect3DDevice9.EndScene
        /// </summary>
        /// <param name="devicePtr">Pointer to the IDirect3DDevice9 instance. Note: object member functions always pass "this" as the first parameter.</param>
        /// <returns>The HRESULT of the original EndScene</returns>
        /// <remarks>Remember that this is called many times a second by the Direct3D application - be mindful of memory and performance!</remarks>
        int EndSceneHook(IntPtr devicePtr)
        {
            using (Device device = Device.FromPointer(devicePtr))
            {
                // If you need to capture at a particular frame rate, add logic here decide whether or not to skip the frame
                try
                {
                    #region Screenshot Request
                    // Is there a screenshot request? If so lets grab the backbuffer
                    lock (_lockRenderTarget)
                    {
                        if (Request != null)
                        {
                            _lastRequestTime = DateTime.Now;
                            DateTime start = DateTime.Now;
                            try
                            {
                                // First ensure we have a Surface to the render target data into
                                if (_renderTarget == null)
                                {
                                    // Create offscreen surface to use as copy of render target data
                                    using (SwapChain sc = device.GetSwapChain(0))
                                    {
                                        _renderTarget = Surface.CreateOffscreenPlain(device, sc.PresentParameters.BackBufferWidth, sc.PresentParameters.BackBufferHeight, sc.PresentParameters.BackBufferFormat, Pool.SystemMemory);
                                    }
                                }

                                #region Prepare lines for overlay
                                if (this.Request.RegionToCapture.Width == 0)
                                {
                                    _lineVectors = new SlimDX.Vector2[] { 
                                        new SlimDX.Vector2(0, 0),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(0, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, 0),
                                        new SlimDX.Vector2(0, 0),
                                        new SlimDX.Vector2(0, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, 0),
                                    };
                                }
                                else
                                {
                                    _lineVectors = new SlimDX.Vector2[] { 
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Y),
                                    };
                                }
                                #endregion

                                using (Surface backBuffer = device.GetBackBuffer(0, 0))
                                {
                                    // Create a super fast copy of the back buffer on our Surface
                                    device.GetRenderTargetData(backBuffer, _renderTarget);

                                    // We have the back buffer data and can now work on copying it to a bitmap
                                    ProcessRequest();
                                }
                            }
                            finally
                            {
                                // We have completed the request - mark it as null so we do not continue to try to capture the same request
                                // Note: If you are after high frame rates, consider implementing buffers here to capture more frequently
                                //         and send back to the host application as needed. The IPC overhead significantly slows down 
                                //         the whole process if sending frame by frame.
                                Request = null;
                            }
                            DateTime end = DateTime.Now;
                            this.DebugMessage("EndSceneHook: Capture time: " + (end - start).ToString());
                            _lastScreenshotTime = (end - start);
                        }
                    }
                    #endregion

                    #region Example: Draw Overlay (after screenshot so we don't capture overlay as well)

                    if (this.ShowOverlay)
                    {
                        #region Draw fading lines based on last screencapture request
                        if (_lastRequestTime != null && _lineVectors != null)
                        {
                            TimeSpan timeSinceRequest = DateTime.Now - _lastRequestTime.Value;
                            if (timeSinceRequest.TotalMilliseconds < 1000.0)
                            {
                                using (Line line = new Line(device))
                                {
                                    _lineAlpha = (float)((1000.0 - timeSinceRequest.TotalMilliseconds) / 1000.0); // This is our fade out
                                    line.Antialias = true;
                                    line.Width = 1.0f;
                                    line.Begin();
                                    line.Draw(_lineVectors, new SlimDX.Color4(_lineAlpha, 0.5f, 0.5f, 1.0f));
                                    line.End();
                                }
                            }
                            else
                            {
                                _lineVectors = null;
                            }
                        }
                        #endregion

                        #region Draw frame rate
                        using (SlimDX.Direct3D9.Font font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Times New Roman", 16.0f)))
                        {
                            if (_lastFrame != null)
                            {
                                font.DrawString(null, String.Format("{0:N1} fps", (1000.0 / (DateTime.Now - _lastFrame.Value).TotalMilliseconds)), 100, 100, System.Drawing.Color.Red);
                            }
                            _lastFrame = DateTime.Now;
                        }
                        #endregion
                    }

                    #endregion
                }
                catch(Exception e)
                {
                    // If there is an error we do not want to crash the hooked application, so swallow the exception
                    this.DebugMessage("EndSceneHook: Exeception: " + e.GetType().FullName + ": " + e.Message);
                }

                // EasyHook has already repatched the original EndScene - so calling EndScene against the SlimDX device will call the original
                // EndScene and bypass this hook. EasyHook will automatically reinstall the hook after this hook function exits.
                return device.EndScene().Code;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Draws a Rectangle.
        /// </summary>
        /// <param name="pen">The Pen.</param>
        /// <param name="rectangle">The Rectangle.</param>
        public void DrawRectangle(Pen pen, Rectangle rectangle)
        {
            var dxPen = pen.Instance as DirectXPen;
            if (dxPen == null) throw new ArgumentException("DirectX9 expects a DirectXPen as resource.");

            var line = new Line(_direct3D9Device) {Antialias = true, Width = dxPen.Width};
            line.Begin();

            line.Draw(
                DirectXHelper.ConvertToVertex(
                    new Vector2(rectangle.X, rectangle.Y),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y),
                    new Vector2(rectangle.X, rectangle.Y + rectangle.Height),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height),
                    new Vector2(rectangle.X, rectangle.Y),
                    new Vector2(rectangle.X, rectangle.Y + rectangle.Height),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height)),
                DirectXHelper.ConvertColor(dxPen.Color));

            line.End();
        }
Esempio n. 4
0
        /// <summary>
        /// Fills a Ellipse.
        /// </summary>
        /// <param name="color">The Color.</param>
        /// <param name="ellipse">The Ellipse.</param>
        public void FillEllipse(Color color, Ellipse ellipse)
        {
            var line = new Line(_direct3D9Device) {Antialias = false, Width = 2};
            line.Begin();

            line.Draw(DirectXHelper.ConvertToVertex(ellipse.Points), DirectXHelper.ConvertColor(color));

            line.End();
        }
Esempio n. 5
0
		private void DrawFacialView(ToothGraphic toothGraphic,Matrix defOrient) {
			Matrix toothTrans=Matrix.Identity;
			toothTrans.Translate(GetTransX(toothGraphic.ToothID),
				GetTransYfacial(toothGraphic.ToothID),
				0);
			Matrix rotAndTranUser=ToothRotationAndTranslationMatrix(toothGraphic);
			device.Transform.World=rotAndTranUser*toothTrans*defOrient;
			if(toothGraphic.Visible
				||(toothGraphic.IsCrown && toothGraphic.IsImplant)
				||toothGraphic.IsPontic) 
			{
				DrawTooth(toothGraphic);
			}
			device.RenderState.ZBufferEnable=false;
			device.RenderState.Lighting=false;
			Matrix lineMatrix=ScreenSpaceMatrix();
			Line line=new Line(device);
			line.GlLines=true;
			if(toothGraphic.DrawBigX) {
				//Thickness of line depends on size of window.
				//The line size needs to be slightly larger than in OpenGL because
				//lines are drawn with polygons in DirectX and they are anti-aliased,
				//even when the line.Antialias flag is set.
				line.Width=2.2f*TcData.PixelScaleRatio;
				line.Begin();
				if(ToothGraphic.IsMaxillary(toothGraphic.ToothID)) {
					line.DrawTransform(new Vector3[] {
						new Vector3(-2f,12f,0f),
						new Vector3(2f,-6f,0f),},
						lineMatrix,
						toothGraphic.colorX);
					line.DrawTransform(new Vector3[] {
						new Vector3(2f,12f,0f),
						new Vector3(-2f,-6f,0f),},
						lineMatrix,
						toothGraphic.colorX);
				} 
				else {
					line.DrawTransform(new Vector3[] {
						new Vector3(-2f,6f,0f),
						new Vector3(2f,-12f,0f),},
						lineMatrix,
						toothGraphic.colorX);
					line.DrawTransform(new Vector3[] {
						new Vector3(2f,6f,0f),
						new Vector3(-2f,-12f,0f),},
						lineMatrix,
						toothGraphic.colorX);
				}
				line.End();
			}
			if(toothGraphic.Visible && toothGraphic.IsRCT) {//draw RCT
				//Thickness of lines depend on size of window.
				//The line size needs to be slightly larger than in OpenGL because
				//lines are drawn with polygons in DirectX and they are anti-aliased,
				//even when the line.Antialias flag is set.
				line.Width=2.5f*TcData.PixelScaleRatio;
				line.Begin();
				List<LineSimple> linesSimple=toothGraphic.GetRctLines();
				for(int i=0;i<linesSimple.Count;i++) {
					if(linesSimple[i].Vertices.Count<2){
						continue;//Just to avoid internal errors, even though not likely.
					}
					//Convert each line strip into very simple two point lines so that line extensions can be calculated more easily below.
					//Items in the array are tuples of (2D point,bool indicating end point).
					List <object> twoPointLines=new List<object> ();
					for(int j=0;j<linesSimple[i].Vertices.Count-1;j++){
					  twoPointLines.Add(new Vector3(
							linesSimple[i].Vertices[j  ].X,
							linesSimple[i].Vertices[j  ].Y,
							linesSimple[i].Vertices[j  ].Z));
						twoPointLines.Add(j==0);
					  twoPointLines.Add(new Vector3(
							linesSimple[i].Vertices[j+1].X,
							linesSimple[i].Vertices[j+1].Y,
							linesSimple[i].Vertices[j+1].Z));
						twoPointLines.Add(j==linesSimple[i].Vertices.Count-2);
					}
					//Draw each individual two point line. The lines must be broken down from line strips so that when individual two point
					//line locations are modified they do not affect any other two point lines within the same line strip.
					for(int j=0;j<twoPointLines.Count;j+=4){
					  Vector3 p1=(Vector3)twoPointLines[j];
						bool p1IsEndPoint=(bool)twoPointLines[j+1];
					  Vector3 p2=(Vector3)twoPointLines[j+2];
						bool p2IsEndPoint=(bool)twoPointLines[j+3];
					  Vector3 lineDir=p2-p1;
					  lineDir.Normalize();//Gives the line direction a single unit length.
					  float extSize=0.25f;//The number of units to extend each end of the two point line.
						if(!p1IsEndPoint){//Do not extend the endpoints for the ends of the line strips.
							p1=p1-extSize*lineDir;
						}
						if(!p2IsEndPoint){//Do not extend the endpoints for the ends of the line strips.
							p2=p2+extSize*lineDir;
						}
					  Vector3[] lineVerts=new Vector3[] {p1,p2};
					  line.DrawTransform(lineVerts,lineMatrix,toothGraphic.colorRCT);
					}
				}
				line.End();
			}
			ToothGroup groupBU=toothGraphic.GetGroup(ToothGroupType.Buildup);//during debugging, not all teeth have a BU group yet.
			if(toothGraphic.Visible && groupBU!=null && groupBU.Visible) {//BU or Post
				device.RenderState.ZBufferEnable=false;
				device.RenderState.Lighting=true;
				device.Lights[0].Enabled=false;//Disable the scene light.
				device.Lights[1].Ambient=Color.White;
				device.Lights[1].Enabled=true;
				Color colorBU=toothGraphic.GetGroup(ToothGroupType.Buildup).PaintColor;
				device.VertexFormat=CustomVertex.PositionNormal.Format;
				device.SetStreamSource(0,toothGraphic.vb,0);
				Material material=new Material();
				material.Ambient=colorBU;
				device.Material=material;
				device.Indices=groupBU.facesDirectX;
				device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,toothGraphic.VertexNormals.Count,0,groupBU.NumIndicies/3);
				device.Lights[0].Enabled=true;
				device.Lights[1].Enabled=false;
			}
			if(toothGraphic.IsImplant) {
				DrawImplant(toothGraphic);
			}
			line.Dispose();
			device.RenderState.ZBufferEnable=true;
			device.RenderState.Lighting=true;
		}
Esempio n. 6
0
        /// <summary>
        /// Draws a Polygon.
        /// </summary>
        /// <param name="pen">The Pen.</param>
        /// <param name="polygon">The Polygon.</param>
        public void DrawPolygon(Pen pen, Polygon polygon)
        {
            var dxPen = pen.Instance as DirectXPen;
            if (dxPen == null) throw new ArgumentException("DirectX9 expects a DirectXPen as resource.");

            var line = new Line(_direct3D9Device) {Antialias = true, Width = dxPen.Width};
            line.Begin();
            line.Draw(DirectXHelper.ConvertToVertex(polygon.Points), DirectXHelper.ConvertColor(dxPen.Color));
            line.End();
        }
Esempio n. 7
0
		private void DrawDrawingSegments() {
			device.RenderState.Lighting=false;
			device.RenderState.ZBufferEnable=false;
			device.Transform.World=Matrix.Identity;
			Matrix lineMatrix=ScreenSpaceMatrix();
			Line line=new Line(device);
			line.Width=2.2f*TcData.PixelScaleRatio;
			line.Begin();
			for(int s=0;s<TcData.DrawingSegmentList.Count;s++) {				
				string[] pointStr=TcData.DrawingSegmentList[s].DrawingSegment.Split(';');
				List<Vector3> points=new List<Vector3>();
				for(int p=0;p<pointStr.Length;p++) {
					string[] xy=pointStr[p].Split(',');
					if(xy.Length==2) {
						Point point=new Point((int)(float.Parse(xy[0])),(int)(float.Parse(xy[1])));
						//if we set 0,0 to center, then this is where we would convert it back.
						PointF pointMm=TcData.PointDrawingPixToMm(point);
						points.Add(new Vector3(pointMm.X,pointMm.Y,0f));
					}
				}
				//Convert each line strip into very simple two point lines so that line extensions can be calculated more easily below.
				List<Vector3> twoPointLines=new List<Vector3>();
				for(int j=0;j<points.Count-1;j++) {
					twoPointLines.Add(new Vector3(
						points[j].X,
						points[j].Y,
						points[j].Z));
					twoPointLines.Add(new Vector3(
						points[j+1].X,
						points[j+1].Y,
						points[j+1].Z));
				}
				//Draw each individual two point line. The lines must be broken down from line strips so that when individual two point
		    //line locations are modified they do not affect any other two point lines within the same line strip.
				//All lines are expanded on both sides here, because the drawing could end with a loop and the loop must be closed.
		    for(int j=0;j<twoPointLines.Count;j+=2){
		      Vector3 p1=(Vector3)twoPointLines[j];
		      Vector3 p2=(Vector3)twoPointLines[j+1];
		      Vector3 lineDir=p2-p1;
		      lineDir.Normalize();//Gives the line direction a single unit length.
		      float extSize=0.25f;//The number of units to extend each end of the two point line.
					p1=p1-extSize*lineDir;
					p2=p2+extSize*lineDir;
		      Vector3[] lineVerts=new Vector3[] {p1,p2};
					line.DrawTransform(lineVerts,lineMatrix,TcData.DrawingSegmentList[s].ColorDraw);
		    }
				//no filled circle at intersections
			}
			//Draw the points that make up the segment which is currently being drawn
			//but which has not yet been sent to the database.
			for(int p=1;p<TcData.PointList.Count;p++){
				PointF pMm1=TcData.PointPixToMm(TcData.PointList[p]);
				PointF pMm2=TcData.PointPixToMm(TcData.PointList[p-1]);
				line.DrawTransform(new Vector3[] {
						new Vector3(pMm1.X,pMm1.Y,0f),
						new Vector3(pMm2.X,pMm2.Y,0f)},
					lineMatrix,
					TcData.ColorDrawing);
			}
			line.End();
			line.Dispose();
		}
Esempio n. 8
0
        void DrawRectangle(float x, float y, float w, int h, Line MenuLine, SlimDX.Direct3D9.Font MenuFont, Color4 MenuLineColor)
        {
            try
            {
                SlimDX.Vector2[] vLine1 = new SlimDX.Vector2[2];
                SlimDX.Vector2[] vLine2 = new SlimDX.Vector2[2];
                SlimDX.Vector2[] vLine3 = new SlimDX.Vector2[2];
                SlimDX.Vector2[] vLine4 = new SlimDX.Vector2[2];

                vLine1[0] = new Vector2();
                vLine1[1] = new Vector2();
                vLine2[0] = new Vector2();
                vLine2[1] = new Vector2();
                vLine3[0] = new Vector2();
                vLine3[1] = new Vector2();
                vLine4[0] = new Vector2();
                vLine4[1] = new Vector2();

                vLine1[0].X = x;
                vLine1[0].Y = y;
                vLine1[1].X = x;
                vLine1[1].Y = y + h;

                vLine2[0].X = x + w;
                vLine2[0].Y = y;
                vLine2[1].X = x + w;
                vLine2[1].Y = y + h;

                vLine3[0].X = x;
                vLine3[0].Y = y;
                vLine3[1].X = x + w;
                vLine3[1].Y = y;

                vLine4[0].X = x;
                vLine4[0].Y = y + h;
                vLine4[1].X = x + w;
                vLine4[1].Y = y + h;

                if (MenuLine != null)
                {
                    MenuLine.Width = 2;
                    MenuLine.Antialias = false;
                    MenuLine.GLLines = false;
                    MenuLine.Begin();

                    MenuLine.Draw(vLine1, MenuLineColor);
                    MenuLine.Draw(vLine2, MenuLineColor);
                    MenuLine.Draw(vLine3, MenuLineColor);
                    MenuLine.Draw(vLine4, MenuLineColor);

                    MenuLine.End();
                }
            }
            catch (Exception ExtInfo)
            {
                Interface.ReportException(ExtInfo);
                return;
            }
        }
Esempio n. 9
0
		private void DrawNumbersAndLines() {
			//Draw the center line.
			Line centerLine=new Line(device);
			centerLine.Width=1f*TcData.PixelScaleRatio;
			centerLine.Antialias=false;
			centerLine.Begin();//Must call Line.Begin() in order for Antialias=false to take effect.
			centerLine.Draw(new Vector2[] {
				new Vector2(-1,this.Height/2),
				new Vector2(this.Width,this.Height/2)},
				Color.White);
			centerLine.End();
			//Draw the tooth numbers.
			string tooth_id;
			for(int i=1;i<=52;i++) {
				tooth_id=Tooth.FromOrdinal(i);
				if(TcData.SelectedTeeth.Contains(tooth_id)) {
					DrawNumber(tooth_id,true,0);
				} 
				else {
					DrawNumber(tooth_id,false,0);
				}
			}
			//TimeSpan displayTime=(frameEndTime-frameBeginTime);
			//float fps=1000f/displayTime.Milliseconds;
			//this.PrintString(fps.ToString(),0,0,0,Color.Blue,xfont);
		}
Esempio n. 10
0
		private void DrawNumbersAndLinesPerio(float baseY) {
			device.RenderState.Lighting=false;
			device.RenderState.ZBufferEnable=false;
			//Draw the center line.
			device.Transform.World=Matrix.Identity;
			Matrix lineMatrix=ScreenSpaceMatrix();
			Line centerLine=new Line(device);
			centerLine.Width=2.5f;
			centerLine.Antialias=false;
			centerLine.Begin();//Must call Line.Begin() in order for Antialias=false to take effect.
			centerLine.DrawTransform(new Vector3[] {
				new Vector3(-65f,baseY,0),
				new Vector3(65f,baseY,0)},
				lineMatrix,
				Color.Black);
			centerLine.End();
			//Draw the tooth numbers.
			string tooth_id;
			for(int i=1;i<=32;i++) {
				tooth_id=Tooth.FromOrdinal(i);
				//bool isSelected=TcData.SelectedTeeth.Contains(tooth_id);
				float yOffset=ToothGraphic.IsMaxillary(tooth_id)?30:-29;
				DrawNumber(tooth_id,false,baseY+yOffset);
			}
		}
Esempio n. 11
0
 public static void DrawRectangle(System.Drawing.Rectangle rect, long color, bool fill)
 {
     if (fill)
       {
     System.Drawing.Rectangle[] regions = new System.Drawing.Rectangle[1]
     {
       rect
     };
     GUIGraphicsContext.DX9Device.Clear(ClearFlags.Target, (int)color, 1f, 0, regions);
       }
       else
       {
     Vector2[] vertexList = new Vector2[2];
     vertexList[0].X = (float)rect.Left;
     vertexList[0].Y = (float)rect.Top;
     vertexList[1].X = (float)(rect.Left + rect.Width);
     vertexList[1].Y = (float)rect.Top;
     using (Line line = new Line(GUIGraphicsContext.DX9Device))
     {
       line.Begin();
       line.Draw(vertexList, (int)color);
       vertexList[0].X = (float)(rect.Left + rect.Width);
       vertexList[0].Y = (float)rect.Top;
       vertexList[1].X = (float)(rect.Left + rect.Width);
       vertexList[1].Y = (float)(rect.Top + rect.Height);
       line.Draw(vertexList, (int)color);
       vertexList[0].X = (float)(rect.Left + rect.Width);
       vertexList[0].Y = (float)(rect.Top + rect.Width);
       vertexList[1].X = (float)rect.Left;
       vertexList[1].Y = (float)(rect.Top + rect.Height);
       line.Draw(vertexList, (int)color);
       vertexList[0].X = (float)rect.Left;
       vertexList[0].Y = (float)(rect.Top + rect.Height);
       vertexList[1].X = (float)rect.Left;
       vertexList[1].Y = (float)rect.Top;
       line.Draw(vertexList, (int)color);
       line.End();
     }
       }
 }
Esempio n. 12
0
 public static void DrawLine(int x1, int y1, int x2, int y2, long color)
 {
     Vector2[] vertexList = new Vector2[2];
       vertexList[0].X = (float)x1;
       vertexList[0].Y = (float)y1;
       vertexList[1].X = (float)x2;
       vertexList[1].Y = (float)y2;
       using (Line line = new Line(GUIGraphicsContext.DX9Device))
       {
     line.Begin();
     line.Draw(vertexList, (int)color);
     line.End();
       }
 }
Esempio n. 13
0
        /// <summary>
        /// 
        /// </summary>
        private void DrawOrigin()
        {
            this.dxDevice.Transform.World = Matrix.Translation(0, 0, 0);
            Matrix lineMatrix = this.dxDevice.Transform.World * this.dxDevice.Transform.View * this.dxDevice.Transform.Projection;

            using (Line myLine = new Line(this.dxDevice))
            {
                // Set the width
                myLine.Width = 1;

                // Should they be antialiased?
                myLine.Antialias = true;

                // Draw the line
                myLine.Begin();
                myLine.DrawTransform(this.vtrOrigin, lineMatrix, Color.WhiteSmoke);
                myLine.End();

            } // End of using block
        }
Esempio n. 14
0
 public static void DrawLine(int x1, int y1, int x2, int y2, long color)
 {
   Vector2[] vec = new Vector2[2];
   vec[0].X = x1;
   vec[0].Y = y1;
   vec[1].X = x2;
   vec[1].Y = y2;
   using (Line line = new Line(GUIGraphicsContext.DX9Device))
   {
     line.Begin();
     line.Draw(vec, (int)color);
     line.End();
   }
 }
Esempio n. 15
0
		///<summary>Draws a line strip extending the two point lines which to not include endpoints. 
		///Set extendEndPoints to true to extend the endpoints of the line.</summary>
		private void DrawExtended3dLine(Vector3[] points,float extendDist,bool extendEndPoints,Color color,float lineWidth,Matrix transform){
			//Convert each line strip into very simple two point lines so that line extensions can be calculated more easily below.
			//Items in the array are tuples of (2D point,bool indicating end point).
			List<object> twoPointLines=new List<object>();
			for(int p=0;p<points.Length-1;p++) {
				twoPointLines.Add(points[p]);
				twoPointLines.Add(p==0);
				twoPointLines.Add(points[p+1]);
				twoPointLines.Add(p==points.Length-2);
			}
			Line line=new Line(device);
			line.Antialias=false;
			line.Width=lineWidth;
			line.Begin();
			//Draw each individual two point line. The lines must be broken down from line strips so that when individual two point
			//line locations are modified they do not affect any other two point lines within the same line strip.
			for(int j=0;j<twoPointLines.Count;j+=4) {
				Vector3 p1=(Vector3)twoPointLines[j];
				bool p1IsEndPoint=(bool)twoPointLines[j+1];
				Vector3 p2=(Vector3)twoPointLines[j+2];
				bool p2IsEndPoint=(bool)twoPointLines[j+3];
				Vector3 lineDir=p2-p1;
				lineDir.Normalize();//Gives the line direction a single unit length.
				//Do not extend the endpoints for the ends of the line strips unless extendEndPoints=true.
				if(!p1IsEndPoint || extendEndPoints) {
					p1=p1-extendDist*lineDir;
				}
				//Do not extend the endpoints for the ends of the line strips unless extendEndPoints=true.
				if(!p2IsEndPoint || extendEndPoints) {
					p2=p2+extendDist*lineDir;
				}
				Vector3[] lineVerts=new Vector3[] { p1,p2 };
				line.DrawTransform(lineVerts,transform,color);
			}
			line.End();
			line.Dispose();
		}
Esempio n. 16
0
    public static void DrawRectangle(Rectangle rect, long color, bool fill)
    {
      if (fill)
      {
        Rectangle[] rects = new Rectangle[1];
        rects[0] = rect;
        GUIGraphicsContext.DX9Device.Clear(ClearFlags.Target, (int)color, 1.0f, 0, rects);
      }
      else
      {
        Vector2[] vec = new Vector2[2];
        vec[0].X = rect.Left;
        vec[0].Y = rect.Top;
        vec[1].X = rect.Left + rect.Width;
        vec[1].Y = rect.Top;
        using (Line line = new Line(GUIGraphicsContext.DX9Device))
        {
          line.Begin();
          line.Draw(vec, (int)color);

          vec[0].X = rect.Left + rect.Width;
          vec[0].Y = rect.Top;
          vec[1].X = rect.Left + rect.Width;
          vec[1].Y = rect.Top + rect.Height;
          line.Draw(vec, (int)color);

          vec[0].X = rect.Left + rect.Width;
          vec[0].Y = rect.Top + rect.Width;
          vec[1].X = rect.Left;
          vec[1].Y = rect.Top + rect.Height;
          line.Draw(vec, (int)color);


          vec[0].X = rect.Left;
          vec[0].Y = rect.Top + rect.Height;
          vec[1].X = rect.Left;
          vec[1].Y = rect.Top;
          line.Draw(vec, (int)color);
          line.End();
        }
      }
    }
Esempio n. 17
0
        public void DrawLine(float fx, float fy, float tx, float ty, Color color)
        {
            using (Line l = new Line(Devices.D3DDev))
            {
                Vector2[] vects = new Vector2[2];
                vects[0] = new Vector2(fx, fy);
                vects[1] = new Vector2(tx, ty);
                l.Begin();
                l.Draw(vects, color);
                l.End();
            }
            //int w, h;
            //w = Devices.D3DDev.PresentationParameters.BackBufferWidth;
            //h = Devices.D3DDev.PresentationParameters.BackBufferHeight;

            //fx -= w / 2;
            //tx -= w / 2;
            //fy -= h / 2;
            //ty -= h / 2;

            //fy = 0 - fy;
            //ty = 0 - ty;

            //CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[2];
            //verts[0] = new CustomVertex.PositionColored(fx, fy, 0, color.ToArgb());
            //verts[1] = new CustomVertex.PositionColored(tx, ty, 0, color.ToArgb());

            //Devices.D3DDev.VertexFormat = CustomVertex.PositionColored.Format;
            //Devices.D3DDev.DrawUserPrimitives(PrimitiveType.LineList, 1, verts);

            //vb = new VertexBuffer(typeof(CustomVertex.PositionColored), 2, Devices.D3DDev, Usage.None, CustomVertex.PositionColored.Format, Pool.Managed);
            //vb.SetData(verts, 0, LockFlags.None);
            //Devices.D3DDev.SetStreamSource(0, vb, 0);
            //Devices.D3DDev.DrawPrimitives(PrimitiveType.LineList, 0, 1);
        }