Ejemplo n.º 1
0
        private void DrawDebug(RenderBuffer data)
        {
            var pass = _visualizationEffect.RenderScenePass0;

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

            this.GraphicsDevice.ImmediateContext.InputAssembler.InputLayout = _inputLayout;

            pass.Apply(this.GraphicsDevice.ImmediateContext);

            if (data.NumberOfPoints > 0)
            {
                var vertices = new VertexPositionColor[data.Points.Length];
                for (int i = 0; i < data.Points.Length; i++)
                {
                    var point = data.Points[i];

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

                DrawVertices(vertices, PrimitiveTopology.PointList);
            }

            if (data.NumberOfLines > 0)
            {
                var vertices = new VertexPositionColor[data.Lines.Length * 2];
                for (int x = 0; x < data.Lines.Length; x++)
                {
                    DebugLine line = data.Lines[x];

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

                DrawVertices(vertices, PrimitiveTopology.LineList);
            }

            if (data.NumberOfTriangles > 0)
            {
                var vertices = new VertexPositionColor[data.Triangles.Length * 3];
                for (int x = 0; x < data.Triangles.Length; x++)
                {
                    DebugTriangle triangle = data.Triangles[x];

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

                DrawVertices(vertices, PrimitiveTopology.TriangleList);
            }
        }
Ejemplo n.º 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();
        }
        public void Render()
        {
            if (!Enabled)
            {
                return;
            }

            lineManager.ClearAllLines();

            var data = physXScene.GetDebugRenderable();


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

                for (int x = 0; x < data.LineCount; x++)
                {
                    lineManager.AddCenteredBox(points[x].Point.dx(), 0.01f, Int32ToColor(points[x].Color).dx());
                }
            }

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

                for (int x = 0; x < data.LineCount; x++)
                {
                    DebugLine line = lines[x];

                    Color4 color4 = Int32ToColor(line.Color).dx();
                    color4.Alpha = 255; // Fix alpha
                    lineManager.AddLine(line.Point0.dx(), line.Point1.dx(), color4);
                }
            }

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

                for (int x = 0; x < data.TriangleCount; x++)
                {
                    DebugTriangle triangle = triangles[x];

                    lineManager.AddTriangle(triangle.Point0.dx(), triangle.Point1.dx(), triangle.Point2.dx(), Int32ToColor(triangle.Color).dx());
                }
            }

            game.LineManager3D.Render(lineManager, game.Camera);
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 8
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();
        }