Exemple #1
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
            {
                return;
            }

            if (effect == null)
            {
                effect       = new BasicEffect(graphics.Device);
                effect.World = Microsoft.Xna.Framework.Matrix.Identity;
                effect.VertexColorEnabled = true;
            }

            effect.Projection = graphics.GetEffect().Projection;
            effect.View       = graphics.GetEffect().View;

            pass = effect.CurrentTechnique.Passes[0];
            pass.Apply();

            int pointCount = lines.Count;
            int linesCount = pointCount / 2;

            VertexPositionColor[] linesArray = new VertexPositionColor[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                int color = lines[i].Color;
                linesArray[i].Color    = new Color(color & 0xff, (color & 0xff00) >> 8, (color & 0xff0000) >> 16, 1);
                linesArray[i].Position = MathHelper.Convert(lines[i].Position);
            }
            graphics.Device.DrawUserPrimitives(PrimitiveType.LineList, linesArray, 0, linesCount);
            lines.Clear();
        }
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
            {
                return;
            }

            Vector3[] positionArray = new Vector3[lines.Count];
            int[]     colorArray    = new int[lines.Count];
            int       i;

            for (i = 0; i < lines.Count; i++)
            {
                positionArray[i] = lines[i].Position;
                colorArray[i]    = lines[i].Color;
            }
            lines.Clear();

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);

            GL.VertexPointer(3, VertexPointerType.Float, 0, positionArray);
            GL.ColorPointer(3, ColorPointerType.UnsignedByte, sizeof(int), colorArray);
            GL.DrawArrays(PrimitiveType.Lines, 0, positionArray.Length);

            GL.DisableClientState(ArrayCap.ColorArray);
            GL.DisableClientState(ArrayCap.VertexArray);
        }
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (LineIndex == 0)
            {
                return;
            }

            Vector3[] positionArray = new Vector3[LineIndex];
            int[]     colorArray    = new int[LineIndex];
            int       i;

            for (i = 0; i < LineIndex; i++)
            {
                positionArray[i] = Lines[i].Position;
                colorArray[i]    = Lines[i].Color;
            }
            LineIndex = 0;

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);

            GL.VertexPointer(3, VertexPointerType.Float, 0, positionArray);
            GL.ColorPointer(3, ColorPointerType.UnsignedByte, sizeof(int), colorArray);
            GL.DrawArrays(BeginMode.Lines, 0, positionArray.Length);

            GL.DisableClientState(ArrayCap.ColorArray);
            GL.DisableClientState(ArrayCap.VertexArray);
        }
 public void OnDrawGizmos()
 {
     if (_doDebugDraw && World != null)
     {
         World.DebugDrawWorld();
     }
 }
Exemple #5
0
 public virtual void DrawDebugWorld(DynamicsWorld world)
 {
     device.SetRenderState(RenderState.Lighting, false);
     device.SetTransform(TransformState.World, Matrix.Identity);
     device.VertexFormat = PositionColored.FVF;
     world.DebugDrawWorld();
     device.SetRenderState(RenderState.Lighting, true);
 }
Exemple #6
0
 public void OnDrawGizmos()
 {
     if (m_quitting)
     {
         return;
     }
     if (m_world != null)
     {
         m_world.DebugDrawWorld();
     }
 }
Exemple #7
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();
            if (LineIndex == 0)
                return;

            fixed(PositionColored *p = Lines)
            {
                Device.DrawLines(p, LineIndex / 2);
            }

            LineIndex = 0;
        }
Exemple #8
0
        public override void DrawDebugWorld(DynamicsWorld world)
        {
            int lighting = device.GetRenderState(RenderState.Lighting);

            device.SetRenderState(RenderState.Lighting, false);
            device.SetTransform(TransformState.World, Matrix.Identity);
            device.VertexFormat = PositionColored.FVF;

            world.DebugDrawWorld();
            DrawBuffer();

            device.SetRenderState(RenderState.Lighting, lighting);
        }
Exemple #9
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
            {
                return;
            }

            inputAssembler.InputLayout = inputLayout;

            if (lineArray.Length != lines.Count)
            {
                lineArray = new PositionColored[lines.Count];
                lines.CopyTo(lineArray);

                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                }
                vertexBufferDesc.SizeInBytes = PositionColored.Stride * lines.Count;
                using (var data = new DataStream(vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(lineArray);
                    data.Position = 0;
                    vertexBuffer  = new Buffer(device, data, vertexBufferDesc);
                }
                vertexBufferBinding.Buffer = vertexBuffer;
            }
            else
            {
                lines.CopyTo(lineArray);

                DataStream ds;
                var        map = device.ImmediateContext.MapSubresource(vertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out ds);
                ds.WriteRange(lineArray);
                device.ImmediateContext.UnmapSubresource(vertexBuffer, 0);
            }

            inputAssembler.SetVertexBuffers(0, vertexBufferBinding);
            inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            device.ImmediateContext.VertexShader.Set(vertexShader);
            device.ImmediateContext.PixelShader.Set(pixelShader);
            device.ImmediateContext.Draw(lines.Count, 0);

            lines.Clear();
        }
Exemple #10
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
            {
                return;
            }

            inputAssembler.InputLayout = inputLayout;

            if (lineArray.Length != lines.Count)
            {
                lineArray = new PositionColored[lines.Count];
                lines.CopyTo(lineArray);

                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                }
                vertexBufferDesc.SizeInBytes = PositionColored.Stride * lines.Count;
                using (var data = new DataStream(vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(lineArray);
                    data.Position = 0;
                    vertexBuffer  = new Buffer(device, data, vertexBufferDesc);
                }
                vertexBufferBinding.Buffer = vertexBuffer;
            }
            else
            {
                lines.CopyTo(lineArray);
                using (var map = vertexBuffer.Map(MapMode.WriteDiscard))
                {
                    map.WriteRange(lineArray);
                }
                vertexBuffer.Unmap();
            }

            inputAssembler.SetVertexBuffers(0, vertexBufferBinding);
            inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            device.Draw(lines.Count, 0);

            lines.Clear();
        }
Exemple #11
0
        /// <summary>
        /// Draw the physical world.
        /// </summary>
        /// <param name="world">World to draw.</param>
        public void DrawDebugWorld(DynamicsWorld world)
        {
            // no camera? skip
            if (Graphics.GraphicsManager.ActiveCamera == null)
            {
                return;
            }

            // create effect if needed
            if (_effect == null)
            {
                _effect = new BasicEffect(_device);
                _effect.VertexColorEnabled = true;
            }

            // set effect properties
            _effect.View       = Graphics.GraphicsManager.ActiveCamera.View;
            _effect.Projection = Graphics.GraphicsManager.ActiveCamera.Projection;

            // set self as the debug drawer
            world.DebugDrawer = this;

            // reset depth stencil and rasterizer states
            RasterizerState   RasterizerState   = new RasterizerState();
            DepthStencilState DepthStencilState = new DepthStencilState();

            RasterizerState.CullMode                 = CullMode.None;
            RasterizerState.DepthClipEnable          = true;
            RasterizerState.FillMode                 = FillMode.Solid;
            DepthStencilState.DepthBufferEnable      = true;
            DepthStencilState.DepthBufferWriteEnable = true;
            Graphics.GraphicsManager.GraphicsDevice.RasterizerState   = RasterizerState;
            Graphics.GraphicsManager.GraphicsDevice.DepthStencilState = DepthStencilState;

            // apply effect
            foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
            {
                // draw current pass
                pass.Apply();

                // draw world
                world.DebugDrawWorld();
            }
        }
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();
            if (lines.Count == 0)
            {
                return;
            }

            int lighting = device.GetRenderState(RenderState.Lighting);

            device.SetRenderState(RenderState.Lighting, false);
            device.SetTransform(TransformState.World, global::SlimDX.Matrix.Identity);
            device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;

            device.DrawUserPrimitives(PrimitiveType.LineList, lines.Count / 2, lines.ToArray());
            lines.Clear();

            device.SetRenderState(RenderState.Lighting, lighting);
        }
        /*
         * protected override void Dispose(bool disposing)
         * {
         *  if (disposing)
         *  {
         *      if (vertexBuffer != null)
         *      {
         *          vertexBuffer.Dispose();
         *          vertexBuffer = null;
         *      }
         *  }
         *
         *  base.Dispose(disposing);
         * }
         */
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (LineIndex == 0)
            {
                return;
            }

            _inputAssembler.InputLayout = _inputLayout;

            if (_vertexCount != LineIndex)
            {
                if (_vertexBuffer != null)
                {
                    _vertexBuffer.Dispose();
                }
                _vertexCount = LineIndex;
                _vertexBufferDesc.SizeInBytes = PositionColored.Stride * _vertexCount;
                using (var data = new DataStream(_vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(Lines, 0, _vertexCount);
                    data.Position = 0;
                    _vertexBuffer = new Buffer(_device, data, _vertexBufferDesc);
                }
                _vertexBufferBinding.Buffer = _vertexBuffer;
            }
            else
            {
                using (var map = _vertexBuffer.Map(MapMode.WriteDiscard))
                {
                    map.WriteRange(Lines, 0, _vertexCount);
                }
                _vertexBuffer.Unmap();
            }

            _inputAssembler.SetVertexBuffers(0, _vertexBufferBinding);
            _inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            _device.Draw(_vertexCount, 0);

            LineIndex = 0;
        }
Exemple #14
0
 public void DrawDebugWorld(DynamicsWorld world)
 {
     world.DebugDrawWorld();
 }
Exemple #15
0
 public void DrawDebugWorld(DynamicsWorld world)
 {
     device.VertexDeclaration = vertexDeclaration;
     world.DebugDrawWorld();
 }