Пример #1
0
 public void SetVertices(LineVertex a, LineVertex b)
 {
     _VertexFrom = a;
     _VertexTo   = b;
     if (_VertexFrom.isRed)
     {
         _Effect = transform.Find("Effect").gameObject;
     }
     RecalculateLine();
 }
Пример #2
0
        public void DrawLine(float x1, float y1, float z1, float x2, float y2, float z2, Color color) //Draw simple colored 3d line
        {
            LineVertex[] lineData = new LineVertex[2];

            lineData[0].Position = new Vector3(x1, y1, z1);
            lineData[0].Color    = color.ToArgb();
            lineData[1].Position = new Vector3(x2, y2, z2);
            lineData[1].Color    = color.ToArgb();

            device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
            device.DrawUserPrimitives <LineVertex>(PrimitiveType.LineList, 0, lineData.Length / 2, lineData);
        }
Пример #3
0
        /// <summary>
        /// Draw a colored line.
        /// </summary>
        /// <param name="a">Vector A.</param>
        /// <param name="b">Vector B.</param>
        /// <param name="color">The color of the quad.</param>
        /// <param name="device">The direct3D device.</param>
        private void DrawLine(Vector3 a, Vector3 b, Color color, Device device)
        {
            LineVertex[] lineData = new LineVertex[2];

            lineData[0].Position = a;
            lineData[0].Color    = color.ToArgb();
            lineData[1].Position = b;
            lineData[1].Color    = color.ToArgb();

            device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
            device.DrawUserPrimitives <LineVertex>(PrimitiveType.LineList, 0, lineData.Length / 2, lineData);
        }
Пример #4
0
 public void Add(Vector3 from, Vector3 to, Color color)
 {
     isDirty = true;
     if (vertexCount + 2 >= vertices.Length)
     {
         int c = 16;
         while (c <= capacity)
             c <<= 1;
         capacity = c;
         vertices = new LineVertex[capacity * 2];
     }
     vertices[vertexCount + 0] = new LineVertex(from, color);
     vertices[vertexCount + 1] = new LineVertex(to, color);
     vertexCount += 2;
 }
Пример #5
0
        public void DrawBox(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, Color color) //Draw simple colored filled box
        {
            LineVertex[] lineData = new LineVertex[4];

            lineData[0].Position = new Vector3(x1, y1, z1);
            lineData[0].Color    = color.ToArgb();
            lineData[1].Position = new Vector3(x2, y2, z2);
            lineData[1].Color    = color.ToArgb();

            lineData[2].Position = new Vector3(x3, y3, z3);
            lineData[2].Color    = color.ToArgb();
            lineData[3].Position = new Vector3(x4, y4, z4);
            lineData[3].Color    = color.ToArgb();

            device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
            device.DrawUserPrimitives <LineVertex>(PrimitiveType.TriangleFan, 0, lineData.Length / 2, lineData);
        }
Пример #6
0
        /// <summary>
        /// Draw simple colored filled box.
        /// </summary>
        /// <param name="a">Vector A.</param>
        /// <param name="b">Vector B.</param>
        /// <param name="c">Vector C.</param>
        /// <param name="d">Vector D.</param>
        /// <param name="color">The color of the quad.</param>
        /// <param name="device">The direct3D device.</param>
        private void DrawBox(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color color, Device device)
        {
            LineVertex[] lineData = new LineVertex[4];

            lineData[0].Position = a;
            lineData[0].Color    = color.ToArgb();
            lineData[1].Position = b;
            lineData[1].Color    = color.ToArgb();

            lineData[2].Position = c;
            lineData[2].Color    = color.ToArgb();
            lineData[3].Position = d;
            lineData[3].Color    = color.ToArgb();

            device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
            device.DrawUserPrimitives <LineVertex>(PrimitiveType.TriangleFan, 0, lineData.Length / 2, lineData);
        }
        public void Initialize(List <GameLine> lines)
        {
            Clear();
            LineVertex[] vertices = new LineVertex[lines.Count * linesize];
            var          redverts = new AutoArray <GenericVertex>((lines.Count / 2) * 3);

            System.Threading.Tasks.Parallel.For(0, lines.Count, (idx) =>
            {
                var line      = (StandardLine)lines[idx];
                var lineverts = CreateDecorationLine(line, line.Color);
                for (int i = 0; i < lineverts.Length; i++)
                {
                    vertices[idx * 6 + i] = lineverts[i];
                }
            });
            var dict = _linebuffer.AddLines(lines, vertices);

            _lines = dict;
        }
Пример #8
0
        void Circle(float stepScale, Vector3 color, float fx, float fy, float fz, float dx, float dy, float dz,
                    float tx, float ty, float tz)
        {
            //  I don't pay attention to dz
            double a1 = Math.Atan2(-dy, -dx);
            double a2 = Math.Atan2(ty - (fy + dy), tx - (fx + dx));

            if (stepScale > 0 && a2 < a1 + 1e-5)
            {
                a2 += Math.PI * 2;
            }
            if (stepScale < 0 && a2 > a1 - 1e-5)
            {
                a1 += Math.PI * 2;
            }
            double len    = Math.Sqrt(dx * dx + dy * dy);
            int    nSteps = (int)Math.Floor(len * 40 * (a2 - a1) * stepScale);

            if (nSteps < 8)
            {
                nSteps = 8;
            }
            LineVertex lv = new LineVertex();

            lv.pos2.X = fx;
            lv.pos2.Y = fy;
            lv.pos2.Z = fz;
            lv.color1 = color;
            lv.line   = curGenLine - 1;
            for (int i = 1; i <= nSteps; ++i)
            {
                lv.pos1 = lv.pos2;
                lv.pos2 = new Vector3(
                    (float)((fx + dx) + len * Math.Cos(a1 + (a2 - a1) * i / nSteps)),
                    (float)((fy + dy) + len * Math.Sin(a1 + (a2 - a1) * i / nSteps)),
                    (float)(fz + (tz - fz) * (float)i / (float)nSteps));
                parsing.Add(lv);
            }
        }
Пример #9
0
        public static void DrawLineVertex()
        {
            LineVertex[] lineData;
            VertexBuffer vertexBuffer;
            Random       rnd = new Random(DateTime.Now.Millisecond);

            lineData = new LineVertex[100];

            for (int i = 0; i < lineData.Length; i++)
            {
                float x = (float)(rnd.NextDouble() * 2) - 1;
                float y = (float)(rnd.NextDouble() * 2) - 1;
                lineData[i].Position = new Vector3(x, y, 0f);
            }


            D3D.Device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
            D3D.Device.DrawUserPrimitives <LineVertex>(PrimitiveType.LineList,
                                                       0,
                                                       lineData.Length / 2,
                                                       lineData);
        }
Пример #10
0
        public static LineVertex[] CreateLine(Vector2d lnstart, Vector2d lnend, float size, Angle angle, int color = 0)
        {
            LineVertex[] ret   = new LineVertex[6];
            var          start = (Vector2)lnstart;
            var          end   = (Vector2)lnend;
            var          len   = (end - start).Length;

            var l     = Utility.GetThickLine(start, end, angle, size);
            var scale = size / 2;

            ret[0] = new LineVertex()
            {
                Position = l[0], u = 0, v = 0, ratio = size / len, color = color, scale = scale
            };
            ret[1] = new LineVertex()
            {
                Position = l[1], u = 0, v = 1, ratio = size / len, color = color, scale = scale
            };
            ret[2] = new LineVertex()
            {
                Position = l[2], u = 1, v = 1, ratio = size / len, color = color, scale = scale
            };

            ret[3] = new LineVertex()
            {
                Position = l[2], u = 1, v = 1, ratio = size / len, color = color, scale = scale
            };
            ret[4] = new LineVertex()
            {
                Position = l[3], u = 1, v = 0, ratio = size / len, color = color, scale = scale
            };
            ret[5] = new LineVertex()
            {
                Position = l[0], u = 0, v = 0, ratio = size / len, color = color, scale = scale
            };
            return(ret);
        }
Пример #11
0
        private void DrawLines( LineVertex[] verts )
        {
            Device dev = pn3D.Device;

            dev.RenderState.Lighting = false;

            dev.VertexDeclaration = lineVertDecl;

            if( verts.Length > 2 )
                dev.DrawUserPrimitives( PrimitiveType.LineList, verts.Length / 2, verts );

            dev.RenderState.Lighting = true;
        }
        /// <summary>
        /// Clears the renderer and initializes it with new lines.
        /// </summary>
        public void InitializeTrack(Track track)
        {
            List <GameLine> scenery = new List <GameLine>(track.SceneryLines);
            List <GameLine> phys    = new List <GameLine>(track.BlueLines + track.RedLines);
            var             sorted  = track.GetSortedLines();

            using (_sync.AcquireWrite())
            {
                _lineactions.Clear();
                _physvbo.Clear();
                _sceneryvbo.Clear();
                _decorator.Clear();
                _physlines.Clear();
                _scenerylines.Clear();
                _physlines.Clear();
                RequiresUpdate = true;

                for (int i = 0; i < sorted.Length; i++)
                {
                    var line = sorted[i];
                    if (line.Type == LineType.Scenery)
                    {
                        scenery.Add(line);
                    }
                    else
                    {
                        phys.Add(line);
                    }
                }
                if (scenery.Count != 0)
                {
                    LineVertex[] sceneryverts = new LineVertex[scenery.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, scenery.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(scenery[index], false));
                        foreach (var vert in verts)
                        {
                            sceneryverts[index * linesize + counter++] = vert;
                        }
                    });
                    _scenerylines = _sceneryvbo.AddLines(
                        scenery,
                        sceneryverts);
                }
                if (phys.Count != 0)
                {
                    LineVertex[] physverts = new LineVertex[phys.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, phys.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(phys[index], false));
                        foreach (var vert in verts)
                        {
                            physverts[index * linesize + counter++] = vert;
                        }
                    });
                    _physlines = _physvbo.AddLines(
                        phys,
                        physverts);
                    _decorator.Initialize(phys);
                }
                RequiresUpdate = true;
            }
        }
Пример #13
0
        void ParseLine(string s)
        {
            Registers newRegs = registers;

            Console.WriteLine("Parsing: {0}", s);
            if (ParseLine(s, ref newRegs))
            {
                if (newRegs.relative)
                {
                    newRegs.X += registers.X;
                    newRegs.Y += registers.Y;
                    newRegs.Z += registers.Z;
                }
                Console.WriteLine("{0} {1} {2} -> {3} {4} {5}", registers.X, registers.Y, registers.Z, newRegs.X, newRegs.Y, newRegs.Z);
                //  do movement
                LineVertex lv = new LineVertex();
                lv.pos1.X = registers.X;
                lv.pos1.Y = registers.Y;
                lv.pos1.Z = registers.Z;
                lv.pos2.X = newRegs.X;
                lv.pos2.Y = newRegs.Y;
                lv.pos2.Z = newRegs.Z;
                lv.line   = curGenLine - 1;
                switch (newRegs.G)
                {
                case 0:         //  rapid move
                    lv.color1 = colors[0];
                    break;

                case 1:         //  cut move
                    lv.color1 = colors[1];
                    break;

                case 2:         //  clockwise arc
                    Circle(-1, colors[2], registers.X, registers.Y, registers.Z, newRegs.I, newRegs.J, newRegs.K,
                           newRegs.X, newRegs.Y, newRegs.Z);
                    //  origin
                    lv.color1 = colors[4];
                    lv.pos1.X = registers.X + newRegs.I;
                    lv.pos1.Y = registers.Y + newRegs.J;
                    lv.pos1.Z = registers.Z + newRegs.K;
                    break;

                case 3:         //  counterclockwise arc
                    Circle(1, colors[3], registers.X, registers.Y, registers.Z, newRegs.I, newRegs.J, newRegs.K,
                           newRegs.X, newRegs.Y, newRegs.Z);
                    //  origin
                    lv.color1 = colors[4];
                    lv.pos2.X = registers.X + newRegs.I;
                    lv.pos2.Y = registers.Y + newRegs.J;
                    lv.pos2.Z = registers.Z + newRegs.K;
                    break;

                default:
                    lv.color1 = new Vector3(1, 0, 0);
                    Console.WriteLine("Got movement command with unknown G mode {0}", newRegs.G);
                    break;
                }
                parsing.Add(lv);
            }
            Console.WriteLine("Did {0}", s);
            registers   = newRegs;
            registers.I = 0;
            registers.J = 0;
            registers.K = 0;
        }
Пример #14
0
        /// <summary>
        /// Clears the renderer and initializes it with new lines.
        /// </summary>
        public void InitializeTrack(Track track)
        {
            AutoArray <GameLine> scenery = new AutoArray <GameLine>(track.SceneryLines);

            scenery.UnsafeSetCount(track.SceneryLines);
            AutoArray <GameLine> phys  = new AutoArray <GameLine>(track.BlueLines);
            AutoArray <GameLine> accel = new AutoArray <GameLine>(track.RedLines);
            var sorted = track.GetSortedLines();

            using (_sync.AcquireWrite())
            {
                _lineactions.Clear();
                _physvbo.Clear();
                _sceneryvbo.Clear();
                _accelvbo.Clear();
                _bluedecorator.Clear();
                _acceldecorator.Clear();
                _physlines.Clear();
                _scenerylines.Clear();
                _accellines.Clear();
                RequiresUpdate = true;

                int scenerycount = 0;
                for (int i = 0; i < sorted.Length; i++)
                {
                    var line = sorted[i];

                    switch (line.Type)
                    {
                    case LineType.Scenery:
                        scenery.unsafe_array[scenery.Count - (1 + scenerycount++)] = line;
                        break;

                    case LineType.Blue:
                        phys.Add(line);
                        break;

                    case LineType.Red:
                        accel.Add(line);
                        break;
                    }
                }

                Debug.Assert(scenerycount == scenery.Count,
                             "Predicted scenery count was not accurate");
                if (scenery.Count != 0)
                {
                    LineVertex[] sceneryverts = new LineVertex[scenery.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, scenery.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(scenery[index], false));
                        foreach (var vert in verts)
                        {
                            sceneryverts[index * linesize + counter++] = vert;
                        }
                    });
                    _scenerylines = _sceneryvbo.AddLines(
                        scenery,
                        sceneryverts);
                }
                if (phys.Count != 0)
                {
                    LineVertex[] physverts = new LineVertex[phys.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, phys.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(phys[index], false));
                        foreach (var vert in verts)
                        {
                            physverts[index * linesize + counter++] = vert;
                        }
                    });
                    _physlines = _physvbo.AddLines(
                        phys,
                        physverts);
                    _bluedecorator.Initialize(phys);
                }
                if (accel.Count != 0)
                {
                    LineVertex[] accelverts = new LineVertex[accel.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, accel.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(accel[index], false));
                        foreach (var vert in verts)
                        {
                            accelverts[index * linesize + counter++] = vert;
                        }
                    });
                    _accellines = _accelvbo.AddLines(
                        accel,
                        accelverts);
                    _acceldecorator.Initialize(accel);
                }
                RequiresUpdate = true;
            }
        }
Пример #15
0
        /// <summary>
        /// Draw a colored line.
        /// </summary>
        /// <param name="a">Vector A.</param>
        /// <param name="b">Vector B.</param>
        /// <param name="color">The color of the quad.</param>
        /// <param name="device">The direct3D device.</param>
        private void DrawLine(Vector3 a, Vector3 b, Color color, Device device)
        {
            LineVertex[] lineData = new LineVertex[2];

            lineData[0].Position = a;
            lineData[0].Color = color.ToArgb();
            lineData[1].Position = b;
            lineData[1].Color = color.ToArgb();

            device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
            device.DrawUserPrimitives<LineVertex>(PrimitiveType.LineList, 0, lineData.Length / 2, lineData);
        }
Пример #16
0
        /// <summary>
        /// Draw simple colored filled box.
        /// </summary>
        /// <param name="a">Vector A.</param>
        /// <param name="b">Vector B.</param>
        /// <param name="c">Vector C.</param>
        /// <param name="d">Vector D.</param> 
        /// <param name="color">The color of the quad.</param>
        /// <param name="device">The direct3D device.</param>
        private void DrawBox(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color color, Device device)
        {
            LineVertex[] lineData = new LineVertex[4];

            lineData[0].Position = a;
            lineData[0].Color = color.ToArgb();
            lineData[1].Position = b;
            lineData[1].Color = color.ToArgb();

            lineData[2].Position = c;
            lineData[2].Color = color.ToArgb();
            lineData[3].Position = d;
            lineData[3].Color = color.ToArgb();

            device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
            device.DrawUserPrimitives<LineVertex>(PrimitiveType.TriangleFan, 0, lineData.Length / 2, lineData);
        }
Пример #17
0
 void Add(Vector3 from, Vector3 to, Color color)
 {
     vertices[vertexCount + 0] = new LineVertex(from, color);
     vertices[vertexCount + 1] = new LineVertex(to, color);
     vertexCount += 2;
 }