Example #1
0
        public void DrawLine(Vector3 start, Vector3 end, Color color = default, float duration = 0.0f, bool depthTest = true)
        {
            var cmd = new DebugDrawLine {
                Start = start, End = end, Color = color == default ? PrimitiveColor : color
            };
            var msg = new DebugRenderable(ref cmd, depthTest ? DebugRenderableFlags.DepthTest : 0)
            {
                Lifetime = duration
            };

            PushMessage(ref msg);
        }
Example #2
0
        public void Draw()
        {
            if (_debugEffect == null)
            {
                _debugEffect = new BasicEffect(Engine.Device, null);
            }

            _debugEffect.View       = Engine.Camera.View;
            _debugEffect.World      = Matrix.Identity;
            _debugEffect.Projection = Engine.Camera.Projection;;
            DebugRenderable debugRenderable = Scene.GetDebugRenderable();

            Engine.Device.VertexDeclaration = new VertexDeclaration(Engine.Device, VertexPositionColor.VertexElements);
            _debugEffect.Begin();

            foreach (EffectPass pass in _debugEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                if (debugRenderable.PointCount > 0)
                {
                    DebugPoint[] debugPoints = debugRenderable.GetDebugPoints();
                    Engine.Device.DrawUserPrimitives <DebugPoint>(PrimitiveType.PointList, debugPoints, 0, debugPoints.Length);
                }
                if (debugRenderable.LineCount > 0)
                {
                    DebugLine[]           debugLines = debugRenderable.GetDebugLines();
                    VertexPositionColor[] vertexData = new VertexPositionColor[debugRenderable.LineCount * 2];
                    for (int i = 0; i < debugRenderable.LineCount; i++)
                    {
                        DebugLine line = debugLines[i];
                        vertexData[i * 2]       = new VertexPositionColor(line.Point0, Color.White);
                        vertexData[(i * 2) + 1] = new VertexPositionColor(line.Point1, Color.White);
                    }
                    Engine.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertexData, 0, debugLines.Length);
                }
                if (debugRenderable.TriangleCount > 0)
                {
                    DebugTriangle[]       debugTriangles = debugRenderable.GetDebugTriangles();
                    VertexPositionColor[] colorArray2    = new VertexPositionColor[debugRenderable.TriangleCount * 3];
                    for (int j = 0; j < debugRenderable.TriangleCount; j++)
                    {
                        DebugTriangle triangle = debugTriangles[j];
                        colorArray2[j * 3]       = new VertexPositionColor(triangle.Point0, Color.White);
                        colorArray2[(j * 3) + 1] = new VertexPositionColor(triangle.Point1, Color.White);
                        colorArray2[(j * 3) + 2] = new VertexPositionColor(triangle.Point2, Color.White);
                    }
                    Engine.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, colorArray2, 0, debugTriangles.Length);
                }
                pass.End();
            }
            _debugEffect.End();
        }
Example #3
0
 /// <summary>
 /// デバッグ描画
 /// </summary>
 public void debugDrawWorld()
 {
     lock (this.scene)
     {
         using (DebugRenderable data = this.scene.GetDebugRenderable())
         {
             if (drawer != null)
             {
                 DrawDebug(data);
             }
         }
     }
 }
Example #4
0
        /// <summary>
        /// デバッグ描画
        /// </summary>
        void DrawDebug(DebugRenderable data)
        {
            if (data.PointCount > 0)
            {
                var points = data.GetDebugPoints();

                for (int i = 0; i < data.LineCount; i++)
                {
                    var     point = points[i];
                    Vector3 v0    = point.Point.As <Vector3>();
                    drawer.draw(v0.X, v0.Y - 1f, v0.Z, v0.X, v0.Y + 1f, v0.Z);
                }
            }

            if (data.LineCount > 0)
            {
                var lines = data.GetDebugLines();

                for (int x = 0; x < data.LineCount; x++)
                {
                    DebugLine line = lines[x];
                    Vector3   v0   = line.Point0.As <Vector3>();
                    Vector3   v1   = line.Point1.As <Vector3>();
                    drawer.draw(v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z);
                }
            }

            if (data.TriangleCount > 0)
            {
                var triangles = data.GetDebugTriangles();

                for (int x = 0; x < data.TriangleCount; x++)
                {
                    DebugTriangle triangle = triangles[x];
                    Vector3       v0       = triangle.Point0.As <Vector3>();
                    Vector3       v1       = triangle.Point1.As <Vector3>();
                    Vector3       v2       = triangle.Point2.As <Vector3>();
                    drawer.draw(v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z);
                    drawer.draw(v2.X, v2.Y, v2.Z, v1.X, v1.Y, v1.Z);
                    drawer.draw(v0.X, v0.Y, v0.Z, v2.X, v2.Y, v2.Z);
                }
            }
        }
Example #5
0
        private void Draw()
        {
            this.GraphicsDevice.OutputMerger.SetTargets(_depthBuffer, _backBuffer);

            this.GraphicsDevice.ClearRenderTargetView(_backBuffer, new Color4(0.27f, 0.51f, 0.71f));
            this.GraphicsDevice.ClearDepthStencilView(_depthBuffer, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0);
            this.GraphicsDevice.Rasterizer.SetViewports(Camera.Viewport);

            using (DebugRenderable data = this.Scene.GetDebugRenderable())
            {
                DrawDebug(data);
            }

            if (OnDraw != null)
            {
                OnDraw(this, null);
            }

            _swapChain.Present(0, PresentFlags.None);
        }
Example #6
0
 private void PushMessage(ref DebugRenderable msg)
 {
     if (msg.Lifetime > 0.0f)
     {
         renderMessagesWithLifetime.Add(msg);
         // drop one old message if the tail size has been reached
         if (renderMessagesWithLifetime.Count > MaxPrimitivesWithLifetime)
         {
             renderMessagesWithLifetime.RemoveAt(renderMessagesWithLifetime.Count - 1);
         }
     }
     else
     {
         renderMessages.Add(msg);
         // drop one old message if the tail size has been reached
         if (renderMessages.Count > MaxPrimitives)
         {
             renderMessages.RemoveAt(renderMessages.Count - 1);
         }
     }
 }
Example #7
0
        private void DrawDebug(DebugRenderable data)
        {
            var pass = _visualizationEffect.RenderScenePass0;

            _visualizationEffect.World.SetMatrix(Matrix.Identity);
            _visualizationEffect.View.SetMatrix(this.Camera.View);
            _visualizationEffect.Projection.SetMatrix(this.Camera.Projection);

            this.GraphicsDevice.InputAssembler.SetInputLayout(_inputLayout);

            pass.Apply();

            if (data.PointCount > 0)
            {
                var points = data.GetDebugPoints();

                var vertices = new VertexPositionColor[points.Length];
                for (int i = 0; i < data.PointCount; i++)
                {
                    var point = points[i];

                    vertices[i * 2 + 0] = new VertexPositionColor(point.Point.As <Vector3>(), Color.FromArgb(point.Color));
                }

                DrawVertices(vertices, PrimitiveTopology.PointList);
            }

            if (data.LineCount > 0)
            {
                var lines = data.GetDebugLines();

                var vertices = new VertexPositionColor[data.LineCount * 2];
                for (int x = 0; x < data.LineCount; x++)
                {
                    DebugLine line = lines[x];

                    vertices[x * 2 + 0] = new VertexPositionColor(line.Point0.As <Vector3>(), Color.FromArgb(line.Color));
                    vertices[x * 2 + 1] = new VertexPositionColor(line.Point1.As <Vector3>(), Color.FromArgb(line.Color));
                }

                DrawVertices(vertices, PrimitiveTopology.LineList);
            }

            if (data.TriangleCount > 0)
            {
                var triangles = data.GetDebugTriangles();

                var vertices = new VertexPositionColor[data.TriangleCount * 3];
                for (int x = 0; x < data.TriangleCount; x++)
                {
                    DebugTriangle triangle = triangles[x];

                    vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0.As <Vector3>(), Color.FromArgb(triangle.Color));
                    vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1.As <Vector3>(), Color.FromArgb(triangle.Color));
                    vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2.As <Vector3>(), Color.FromArgb(triangle.Color));
                }

                DrawVertices(vertices, PrimitiveTopology.TriangleList);
            }

            // World axis
            {
                var vertices = new[]
                {
                    // X
                    new VertexPositionColor(new Vector3(0, 0, 0), new Color(1, 0, 0)),
                    new VertexPositionColor(new Vector3(5, 0, 0), new Color(1, 0, 0)),

                    // Y
                    new VertexPositionColor(new Vector3(0, 0, 0), new Color(0, 1, 0)),
                    new VertexPositionColor(new Vector3(0, 5, 0), new Color(0, 1, 0)),

                    // Z
                    new VertexPositionColor(new Vector3(0, 0, 0), new Color(0, 0, 1)),
                    new VertexPositionColor(new Vector3(0, 0, 5), new Color(0, 0, 1)),
                };

                DrawVertices(vertices, PrimitiveTopology.LineList);
            }
        }
Example #8
0
		public virtual Node.DebugRenderable GetDebugRenderable( Real scaling )
		{
			if (_debugRenderable == null)
			{
				_debugRenderable = new DebugRenderable(this);
			}
			_debugRenderable.Scaling = scaling;
			return _debugRenderable;

		}
Example #9
0
		/// <summary>
		/// Class level dispose method
		/// </summary>
		/// <remarks>
		/// When implementing this method in an inherited class the following template should be used;
		/// protected override void dispose( bool disposeManagedResources )
		/// {
		/// 	if ( !isDisposed )
		/// 	{
		/// 		if ( disposeManagedResources )
		/// 		{
		/// 			// Dispose managed resources.
		/// 		}
		///
		/// 		// There are no unmanaged resources to release, but
		/// 		// if we add them, they need to be released here.
		/// 	}
		///
		/// 	// If it is available, make the call to the
		/// 	// base class's Dispose(Boolean) method
		/// 	base.dispose( disposeManagedResources );
		/// }
		/// </remarks>
		/// <param name="disposeManagedResources">True if Unmanaged resources should be released.</param>
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !this.IsDisposed )
			{
				if ( disposeManagedResources )
				{

					if ( this._debugRenderable != null )
					{
						if ( !this._debugRenderable.IsDisposed )
							this._debugRenderable.Dispose();

						this._debugRenderable = null;
					}

					this.childNodes.Clear();
					this.childNodes = null;
				}

				// There are no unmanaged resources to release, but
				// if we add them, they need to be released here.
			}

			base.dispose( disposeManagedResources );
		}
Example #10
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(DebugRenderable obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Example #11
0
        public override void Draw(GameTime gameTime)
        {
            this.Device.Clear(Color.LightBlue);

            this.Device.VertexDeclaration = new VertexDeclaration(this.Device, VertexPositionColor.VertexElements);

            _visualizationEffect.World      = Matrix.Identity;
            _visualizationEffect.View       = this.Camera.View;
            _visualizationEffect.Projection = this.Camera.Projection;

            DebugRenderable data = this.Scene.GetDebugRenderable();

            _visualizationEffect.Begin();

            foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                if (data.PointCount > 0)
                {
                    DebugPoint[] points = data.GetDebugPoints();

                    this.Device.DrawUserPrimitives <DebugPoint>(PrimitiveType.PointList, points, 0, points.Length);
                }

                if (data.LineCount > 0)
                {
                    DebugLine[] lines = data.GetDebugLines();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2];
                    for (int x = 0; x < data.LineCount; x++)
                    {
                        DebugLine line = lines[x];

                        vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color));
                        vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color));
                    }

                    this.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length);
                }

                if (data.TriangleCount > 0)
                {
                    DebugTriangle[] triangles = data.GetDebugTriangles();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3];
                    for (int x = 0; x < data.TriangleCount; x++)
                    {
                        DebugTriangle triangle = triangles[x];

                        vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color));
                    }

                    this.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length);
                }

                pass.End();
            }

            _visualizationEffect.End();
        }
        public void Render(IXNAGame _game)
        {
            if (!enabled)
            {
                return;
            }
            //game.GraphicsDevice.Clear(Color.LightBlue);

            game.GraphicsDevice.VertexDeclaration            = vertexDecl;
            game.GraphicsDevice.RenderState.AlphaBlendEnable = false;
            _visualizationEffect.World      = Matrix.Identity;
            _visualizationEffect.View       = game.Camera.View;
            _visualizationEffect.Projection = game.Camera.Projection;

            DebugRenderable data = physXScene.GetDebugRenderable();

            _visualizationEffect.Begin();

            foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                if (data.PointCount > 0)
                {
                    DebugPoint[] points = data.GetDebugPoints();

                    game.GraphicsDevice.DrawUserPrimitives <DebugPoint>(PrimitiveType.PointList, points, 0, points.Length);
                }

                if (data.LineCount > 0)
                {
                    DebugLine[] lines = data.GetDebugLines();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2 * 2];
                    for (int x = 0; x < data.LineCount; x++)
                    {
                        DebugLine line = lines[x];

                        vertices[x * 4 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color));
                        vertices[x * 4 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color));

                        vertices[x * 4 + 2] = new VertexPositionColor(new Vector3(line.Point0.X, 0, line.Point0.Z), Color.Black);
                        vertices[x * 4 + 3] = new VertexPositionColor(new Vector3(line.Point1.X, 0, line.Point1.Z), Color.Black);
                    }

                    game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length * 2);
                }

                if (data.TriangleCount > 0)
                {
                    DebugTriangle[] triangles = data.GetDebugTriangles();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3];
                    for (int x = 0; x < data.TriangleCount; x++)
                    {
                        DebugTriangle triangle = triangles[x];

                        vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color));
                    }

                    game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length);
                }

                pass.End();
            }

            _visualizationEffect.End();
        }
Example #13
0
        /// <summary>
        /// Allows physics to draw itself information, only if DebugMode state is activated
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Draw()
        {
            _camera = CamerasManager.Instance.GetActiveCamera();

            graphicsDevice.VertexDeclaration = new VertexDeclaration(graphicsDevice, VertexPositionColor.VertexElements);


            _visualizationEffect.World      = Matrix.Identity;
            _visualizationEffect.View       = _camera.View;
            _visualizationEffect.Projection = _camera.Projection;

            DebugRenderable data = Scene.GetDebugRenderable();

            _visualizationEffect.Begin();

            foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                if (data.PointCount > 0)
                {
                    DebugPoint[] points = data.GetDebugPoints();

                    graphicsDevice.DrawUserPrimitives(PrimitiveType.PointList, points, 0, points.Length);
                }

                if (data.LineCount > 0)
                {
                    DebugLine[] lines = data.GetDebugLines();

                    var vertices = new VertexPositionColor[data.LineCount * 2];
                    for (int x = 0; x < data.LineCount; x++)
                    {
                        DebugLine line = lines[x];

                        vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color));
                        vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color));
                    }

                    graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, lines.Length);
                }

                if (data.TriangleCount > 0)
                {
                    DebugTriangle[] triangles = data.GetDebugTriangles();

                    var vertices = new VertexPositionColor[data.TriangleCount * 3];
                    for (int x = 0; x < data.TriangleCount; x++)
                    {
                        DebugTriangle triangle = triangles[x];

                        vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color));
                    }

                    graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, triangles.Length);
                }

                pass.End();
            }

            _visualizationEffect.End();
        }
Example #14
0
		private void DrawDebug(DebugRenderable data)
		{
			var pass = _visualizationEffect.RenderScenePass0;

			_visualizationEffect.World.SetMatrix(Matrix.Identity);
			_visualizationEffect.View.SetMatrix(this.Camera.View);
			_visualizationEffect.Projection.SetMatrix(this.Camera.Projection);

			this.GraphicsDevice.InputAssembler.SetInputLayout(_inputLayout);

			pass.Apply();

			if (data.PointCount > 0)
			{
				var points = data.GetDebugPoints();

				var vertices = new VertexPositionColor[points.Length];
				for (int i = 0; i < data.PointCount; i++)
				{
					var point = points[i];

					vertices[i * 2 + 0] = new VertexPositionColor(point.Point.As<Vector3>(), Color.FromArgb(point.Color));
				}

				DrawVertices(vertices, PrimitiveTopology.PointList);
			}

			if (data.LineCount > 0)
			{
				var lines = data.GetDebugLines();

				var vertices = new VertexPositionColor[data.LineCount * 2];
				for (int x = 0; x < data.LineCount; x++)
				{
					DebugLine line = lines[x];

					vertices[x * 2 + 0] = new VertexPositionColor(line.Point0.As<Vector3>(), Color.FromArgb(line.Color));
					vertices[x * 2 + 1] = new VertexPositionColor(line.Point1.As<Vector3>(), Color.FromArgb(line.Color));
				}

				DrawVertices(vertices, PrimitiveTopology.LineList);
			}

			if (data.TriangleCount > 0)
			{
				var triangles = data.GetDebugTriangles();

				var vertices = new VertexPositionColor[data.TriangleCount * 3];
				for (int x = 0; x < data.TriangleCount; x++)
				{
					DebugTriangle triangle = triangles[x];

					vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0.As<Vector3>(), Color.FromArgb(triangle.Color));
					vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1.As<Vector3>(), Color.FromArgb(triangle.Color));
					vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2.As<Vector3>(), Color.FromArgb(triangle.Color));
				}

				DrawVertices(vertices, PrimitiveTopology.TriangleList);
			}

			// World axis
			{
				var vertices = new[] 
				{
					// X
					new VertexPositionColor(new Vector3(0,0,0), new Color(1, 0, 0)),
					new VertexPositionColor(new Vector3(5,0,0), new Color(1, 0, 0)),

					// Y
					new VertexPositionColor(new Vector3(0,0,0), new Color(0, 1, 0)),
					new VertexPositionColor(new Vector3(0,5,0), new Color(0, 1, 0)),

					// Z
					new VertexPositionColor(new Vector3(0,0,0), new Color(0, 0, 1)),
					new VertexPositionColor(new Vector3(0,0,5), new Color(0, 0, 1)),
				};

				DrawVertices(vertices, PrimitiveTopology.LineList);
			}
		}
Example #15
0
        protected override void DebugDrawn(SceneControl.RenderHelper render, GameTime gt, Cameras.ICamera cam)
        {
            if (BasicEffect == null)
            {
                BasicEffect = new BasicEffect(render.device);
                BasicEffect.VertexColorEnabled = true;
                BasicEffect.TextureEnabled     = false;
            }

            //if (_fetchedResults == false)
            {
                DebugRenderable RenderBuffer = Scene.GetDebugRenderable();
                if (RenderBuffer == null || (RenderBuffer.TriangleCount == 0 && RenderBuffer.LineCount == 0))
                {
                    return;
                }

                Color c = Color.Red;
                if (RenderBuffer.TriangleCount > 0)
                {
                    VertexPositionColor1 = new VertexPositionColor[RenderBuffer.TriangleCount * 3];
                    for (int i = 0, j = 0; i < RenderBuffer.TriangleCount; i += 3, j++)
                    {
                        VertexPositionColor1[i].Color    = c;
                        VertexPositionColor1[i].Position = RenderBuffer.GetDebugTriangles()[j].Point0.AsXNA();

                        VertexPositionColor1[i + 1].Color    = c;
                        VertexPositionColor1[i + 1].Position = RenderBuffer.GetDebugTriangles()[j].Point1.AsXNA();

                        VertexPositionColor1[i + 2].Color    = c;
                        VertexPositionColor1[i + 2].Position = RenderBuffer.GetDebugTriangles()[j].Point2.AsXNA();
                    }
                }

                if (RenderBuffer.LineCount > 0)
                {
                    VertexPositionColor2 = new VertexPositionColor[RenderBuffer.LineCount * 2];
                    for (int i = 0, j = 0; i < RenderBuffer.LineCount; i += 2, j++)
                    {
                        VertexPositionColor2[i].Color    = c;
                        VertexPositionColor2[i].Position = RenderBuffer.GetDebugLines()[j].Point0.AsXNA();

                        VertexPositionColor2[i + 1].Color    = c;
                        VertexPositionColor2[i + 1].Position = RenderBuffer.GetDebugLines()[j].Point1.AsXNA();
                    }
                }
            }

            BasicEffect.View       = cam.View;
            BasicEffect.Projection = cam.Projection;
            BasicEffect.World      = Matrix.Identity;

            if (VertexPositionColor2 != null)
            {
                render.RenderUserPrimitive <VertexPositionColor>(BasicEffect, PrimitiveType.LineList, VertexPositionColor2, 0, VertexPositionColor2.Length / 2);
            }

            if (VertexPositionColor1 != null)
            {
                render.RenderUserPrimitive <VertexPositionColor>(BasicEffect, PrimitiveType.TriangleList, VertexPositionColor1, 0, VertexPositionColor1.Length / 3);
            }
        }