Ejemplo n.º 1
0
 public void BuildVertices()
 {
     if ((Nodes != null) && (Nodes.Count > 0))
     {
         var nc  = Nodes.Count;
         var lc  = nc - 1;
         var lvc = lc * 2;
         var np  = new Vector4[nc];
         var lv  = new VertexTypePC[lvc];
         for (int i = 0; i < nc; i++)
         {
             np[i] = new Vector4(Nodes[i].Position, 1.0f);
             if (i > 0)
             {
                 var l  = i - 1;
                 var li = l * 2;
                 var ni = li + 1;
                 lv[li].Position = Nodes[l].Position;
                 lv[ni].Position = Nodes[i].Position;
                 lv[li].Colour   = (uint)Nodes[l].GetColour();
                 lv[ni].Colour   = (uint)Nodes[i].GetColour();
             }
         }
         NodePositions = np;
         LinkedVerts   = lv;
     }
 }
Ejemplo n.º 2
0
        public void BuildVertices()
        {
            var vlist = new List <VertexTypePC>();
            var v1    = new VertexTypePC();
            var v2    = new VertexTypePC();
            var v3    = new VertexTypePC();
            var v4    = new VertexTypePC();

            foreach (var group in Groups.Values)
            {
                var  hash = JenkHash.GenHash(group.NameLabel.ToLowerInvariant());
                byte cr   = (byte)((hash >> 8) & 0xFF);
                byte cg   = (byte)((hash >> 16) & 0xFF);
                byte cb   = (byte)((hash >> 24) & 0xFF);
                byte ca   = 60;
                uint cv   = (uint)new Color(cr, cg, cb, ca).ToRgba();
                v1.Colour = cv;
                v2.Colour = cv;
                v3.Colour = cv;
                v4.Colour = cv;

                foreach (var box in group.Boxes)
                {
                    var min = box.Box.Minimum;
                    var max = box.Box.Maximum;

                    v1.Position = new Vector3(min.X, min.Y, 0);
                    v2.Position = new Vector3(max.X, min.Y, 0);
                    v3.Position = new Vector3(min.X, max.Y, 0);
                    v4.Position = new Vector3(max.X, max.Y, 0);

                    vlist.Add(v1);
                    vlist.Add(v2);
                    vlist.Add(v3);
                    vlist.Add(v3);
                    vlist.Add(v2);
                    vlist.Add(v4);
                }
            }

            if (vlist.Count > 0)
            {
                TriangleVerts = vlist.ToArray();
            }
            else
            {
                TriangleVerts = null;
            }
        }
Ejemplo n.º 3
0
        public LineShader(Device device)
        {
            byte[] vsbytes = File.ReadAllBytes("Shaders\\LineVS.cso");
            byte[] psbytes = File.ReadAllBytes("Shaders\\LinePS.cso");


            vs = new VertexShader(device, vsbytes);
            ps = new PixelShader(device, psbytes);

            VSSceneVars = new GpuVarsBuffer <LineShaderVSSceneVars>(device);

            layout = VertexTypePC.GetLayout(device, vsbytes);


            vertices = new GpuCBuffer <VertexTypePC>(device, 1000); //should be more than needed....
        }
Ejemplo n.º 4
0
        private void UpdateJunctionTriangleVertices()
        {
            //build triangles for the junctions bytes display....

            int vc = 0;

            if (Junctions != null)
            {
                foreach (var j in Junctions)
                {
                    var d = j.Heightmap;
                    if (d == null)
                    {
                        continue;
                    }
                    vc += d.CountX * d.CountY * 6;
                }
            }

            List <VertexTypePC> verts = new List <VertexTypePC>(vc);
            VertexTypePC        v0    = new VertexTypePC();
            VertexTypePC        v1    = new VertexTypePC();
            VertexTypePC        v2    = new VertexTypePC();
            VertexTypePC        v3    = new VertexTypePC();

            if (Nodes != null)
            {
                foreach (var node in Nodes)
                {
                    if (node.Junction == null)
                    {
                        continue;
                    }
                    var j = node.Junction;
                    var d = j.Heightmap;
                    if (d == null)
                    {
                        continue;
                    }

                    float maxz = j.MaxZ / 32.0f;
                    float minz = j.MinZ / 32.0f;
                    float rngz = maxz - minz;
                    float posx = j.PositionX / 4.0f;
                    float posy = j.PositionY / 4.0f;

                    Vector3 pos = new Vector3(posx, posy, 0.0f);
                    Vector3 siz = new Vector3(d.CountX, d.CountY, 0.0f) * 2.0f;
                    //Vector3 siz = new Vector3(jx, jy, 0.0f);
                    Vector3 cnr = pos;// - siz * 0.5f;
                    //Vector3 inc = new Vector3(1.0f/jx)

                    cnr.Z = minz;                      // + 2.0f;

                    for (int y = 1; y < d.CountY; y++) //rows progress up the Y axis.
                    {
                        var   row0 = d.Rows[y - 1];
                        var   row1 = d.Rows[y];
                        float offy = y * 2.0f;

                        for (int x = 1; x < d.CountX; x++) //values progress along the X axis.
                        {
                            var   val0 = row0.Values[x - 1] / 255.0f;
                            var   val1 = row0.Values[x] / 255.0f;
                            var   val2 = row1.Values[x - 1] / 255.0f;
                            var   val3 = row1.Values[x] / 255.0f;
                            float offx = x * 2.0f;
                            v0.Position = cnr + new Vector3(offx - 2.0f, offy - 2.0f, val0 * rngz);
                            v1.Position = cnr + new Vector3(offx + 0.0f, offy - 2.0f, val1 * rngz);
                            v2.Position = cnr + new Vector3(offx - 2.0f, offy + 0.0f, val2 * rngz);
                            v3.Position = cnr + new Vector3(offx + 0.0f, offy + 0.0f, val3 * rngz);
                            v0.Colour   = (uint)new Color4(val0, 1.0f - val0, 0.0f, 1.0f).ToRgba();
                            v1.Colour   = (uint)new Color4(val1, 1.0f - val1, 0.0f, 1.0f).ToRgba();
                            v2.Colour   = (uint)new Color4(val2, 1.0f - val2, 0.0f, 1.0f).ToRgba();
                            v3.Colour   = (uint)new Color4(val3, 1.0f - val3, 0.0f, 1.0f).ToRgba();
                            verts.Add(v0);
                            verts.Add(v1);
                            verts.Add(v2);
                            verts.Add(v2);
                            verts.Add(v1);
                            verts.Add(v3);
                        }
                    }
                }
            }

            if (verts.Count > 0)
            {
                TriangleVerts = verts.ToArray();
            }
            else
            {
                TriangleVerts = null;
            }
        }
Ejemplo n.º 5
0
        private void UpdateLinkTriangleVertices()
        {
            //build triangles for the path links display


            int vc = 0;

            if (Links != null)
            {
                vc = Links.Length * 6;
            }

            List <VertexTypePC> verts = new List <VertexTypePC>(vc);
            VertexTypePC        v0    = new VertexTypePC();
            VertexTypePC        v1    = new VertexTypePC();
            VertexTypePC        v2    = new VertexTypePC();
            VertexTypePC        v3    = new VertexTypePC();

            if ((Links != null) && (Nodes != null))
            {
                foreach (var node in Nodes)
                {
                    foreach (var link in node.Links)
                    {
                        var p0   = link.Node1?.Position ?? Vector3.Zero;
                        var p1   = link.Node2?.Position ?? Vector3.Zero;
                        var diff = p1 - p0;
                        var dir  = Vector3.Normalize(diff);
                        var ax   = Vector3.Cross(dir, Vector3.UnitZ);


                        float lanestot = link.LaneCountForward + link.LaneCountBackward;
                        //float backfrac = Math.Min(Math.Max(link.LaneCountBackward / lanestot, 0.1f), 0.9f);
                        //float lanewidth = 7.0f;
                        //float inner = totwidth*(backfrac-0.5f);
                        //float outer = totwidth*0.5f;

                        float lanewidth = node.IsPedNode ? 0.5f : 5.5f;
                        float inner     = link.LaneOffset * lanewidth;// 0.0f;
                        float outer     = inner + Math.Max(lanewidth * link.LaneCountForward, 0.5f);

                        float totwidth  = lanestot * lanewidth;
                        float halfwidth = totwidth * 0.5f;
                        if (link.LaneCountBackward == 0)
                        {
                            inner -= halfwidth;
                            outer -= halfwidth;
                        }
                        if (link.LaneCountForward == 0)
                        {
                            inner += halfwidth;
                            outer += halfwidth;
                        }


                        v0.Position = p1 + ax * inner;
                        v1.Position = p0 + ax * inner;
                        v2.Position = p1 + ax * outer;
                        v3.Position = p0 + ax * outer;
                        var c = (uint)link.GetColour().ToRgba();
                        v0.Colour = c;
                        v1.Colour = c;
                        v2.Colour = c;
                        v3.Colour = c;
                        verts.Add(v0);
                        verts.Add(v1);
                        verts.Add(v2);
                        verts.Add(v2);
                        verts.Add(v1);
                        verts.Add(v3);
                    }
                }
            }


            if (verts.Count > 0)
            {
                TriangleVerts = verts.ToArray();
            }
            else
            {
                TriangleVerts = null;
            }
        }
Ejemplo n.º 6
0
        public void UpdateTriangleVertices()
        {
            if (Nav == null)
            {
                return;
            }
            if (Nav.Polys == null)
            {
                return;
            }
            if (Nav.Vertices == null)
            {
                return;
            }

            //need position and colour for each vertex.
            //render as a triangle list... (no indices needed)

            //go through the nav mesh polys and generate verts to render...

            if ((Vertices == null) || (Vertices.Count == 0))
            {
                return;
            }
            if ((Indices == null) || (Indices.Count == 0))
            {
                return;
            }
            if ((Polys == null) || (Polys.Count == 0))
            {
                return;
            }


            int vc = Vertices.Count;

            List <VertexTypePC> rverts = new List <VertexTypePC>();

            foreach (var ypoly in Polys)
            {
                var poly      = ypoly.RawData;
                var colour    = ypoly.GetColour();
                var colourval = (uint)colour.ToRgba();

                var ic      = poly.IndexCount;
                var startid = poly.IndexID;
                var endid   = startid + ic;
                if (startid >= Indices.Count)
                {
                    continue;
                }
                if (endid > Indices.Count)
                {
                    continue;
                }


                if (ic < 3)
                {
                    continue;
                }            //not enough verts to make a triangle...

                if (ic > 15)
                {
                }


                VertexTypePC p0 = new VertexTypePC();
                VertexTypePC p1 = new VertexTypePC();
                VertexTypePC p2 = new VertexTypePC();
                p0.Colour = colourval;
                p1.Colour = colourval;
                p2.Colour = colourval;

                var startind = Indices[startid];
                if (startind >= vc)
                {
                    continue;
                }

                p0.Position = Vertices[startind];

                //build triangles for the poly.
                int tricount = ic - 2;
                for (int t = 0; t < tricount; t++)
                {
                    int tid  = startid + t;
                    int ind1 = Indices[tid + 1];
                    int ind2 = Indices[tid + 2];
                    if ((ind1 >= vc) || (ind2 >= vc))
                    {
                        continue;
                    }

                    p1.Position = Vertices[ind1];
                    p2.Position = Vertices[ind2];

                    rverts.Add(p0);
                    rverts.Add(p1);
                    rverts.Add(p2);
                }
            }

            TriangleVerts = rverts.ToArray();
        }