Beispiel #1
0
        public static CadMesh CreateSphere(Vector3d pos, double r, int slices1, int slices2)
        {
            VertexList vl = new VertexList(slices2);

            double d = Math.PI / slices2;


            for (int i = 0; i < slices2; i++)
            {
                double a = i * d;

                double x = Math.Sin(a) * r;
                double y = Math.Cos(a) * r;

                vl.Add(CadVertex.Create(x, y, 0));
            }

            vl.Add(CadVertex.Create(0, -r, 0));


            CadMesh mesh = CreateRotatingBody(
                slices1, Vector3d.Zero, Vector3d.UnitY, vl, false, false, FaceType.TRIANGLE);

            for (int i = 0; i < mesh.VertexStore.Count; i++)
            {
                mesh.VertexStore.Ref(i).vector += pos;
            }

            return(mesh);
        }
Beispiel #2
0
        protected override void InternalCompute()
        {
            TVertex source = default(TVertex);
            TVertex target = default(TVertex);

            var graph = (UndirectedGraph <TVertex, TEdge>)VisitedGraph;

            Contract.Requires(graph != null);

            while (!graph.IsEdgesEmpty)
            {
                List <TEdge> toRemove = new List <TEdge>();

                //Get random edge
                int   rndNum  = rnd.Next(graph.Edges.Count() - 1);
                TEdge rndEdge = graph.Edges.ElementAt(rndNum);

                source = rndEdge.Source;
                target = rndEdge.Target;

                if (graph.AdjacentDegree(rndEdge.Source) > 1)
                {
                    if (!coverSet.Contains(source))
                    {
                        coverSet.Add(source);
                    }
                }

                if (graph.AdjacentDegree(rndEdge.Target) > 1)
                {
                    if (!coverSet.Contains(target))
                    {
                        coverSet.Add(target);
                    }
                }

                if ((graph.AdjacentDegree(rndEdge.Target) == 1) && (graph.AdjacentDegree(rndEdge.Source) == 1))
                {
                    if (!coverSet.Contains(source))
                    {
                        coverSet.Add(source);
                    }
                    IEnumerable <TEdge> toDel = graph.AdjacentEdges(source);
                    graph.RemoveEdges(toDel.ToList());
                }
                else
                {
                    IEnumerable <TEdge> toDel = graph.AdjacentEdges(target).Concat(graph.AdjacentEdges(source));
                    graph.RemoveEdges(toDel.ToList());
                }
            }
        }
        /// <inheritdoc />
        protected override void InternalCompute()
        {
            var graph = new UndirectedGraph <TVertex, TEdge>(
                VisitedGraph.AllowParallelEdges,
                VisitedGraph.EdgeEqualityComparer);

            graph.AddVerticesAndEdgeRange(VisitedGraph.Edges);

            while (!graph.IsEdgesEmpty)
            {
                TEdge[] graphEdges = graph.Edges.ToArray();

                // Get a random edge
                int   randomEdgeIndex = _rng.Next(graphEdges.Length - 1);
                TEdge randomEdge      = graphEdges[randomEdgeIndex];

                TVertex source = randomEdge.Source;
                TVertex target = randomEdge.Target;

                if (graph.AdjacentDegree(randomEdge.Source) > 1 && !_coverSet.Contains(source))
                {
                    _coverSet.Add(source);
                }

                if (graph.AdjacentDegree(randomEdge.Target) > 1 && !_coverSet.Contains(target))
                {
                    _coverSet.Add(target);
                }

                if (graph.AdjacentDegree(randomEdge.Target) == 1 &&
                    graph.AdjacentDegree(randomEdge.Source) == 1)
                {
                    if (!_coverSet.Contains(source))
                    {
                        _coverSet.Add(source);
                    }

                    graph.RemoveEdges(
                        graph.AdjacentEdges(source).ToArray());
                }
                else
                {
                    TEdge[] edgesToRemove = graph.AdjacentEdges(target)
                                            .Concat(graph.AdjacentEdges(source))
                                            .ToArray();

                    graph.RemoveEdges(edgesToRemove);
                }
            }
        }
Beispiel #4
0
        private void addVertex(Vector3 point, Vector2 uv1, float sunLight, Color localLight)
        {
            //VertexList.Add(new VertexPositionTextureLight(point, uv1, sunLight, localLight.ToVector3()));
            //VertexList.Add(new VertexPositionNormalTexture(point, Vector3.Forward, uv1));

            VertexList.Add(new VertexPositionColorTextureNormal(point, localLight, uv1, Vector3.Forward));
        }
Beispiel #5
0
        /// <summary>
        /// Delete all vertexes and edges that have no <see cref="Part"/> associated with them.
        /// </summary>
        public void DeleteArtificialVertexes()
        {
            VertexList dummies = new VertexList();

            foreach (V n in this.Vertexes)
            {
                if (n.Node == null)
                {
                    dummies.Add(n);
                }
            }
            foreach (V n in dummies)
            {
                DeleteVertex(n);
            }
            EdgeList dummies2 = new EdgeList();

            foreach (E l in this.Edges)
            {
                if (l.Link == null)
                {
                    dummies2.Add(l);
                }
            }
            foreach (E l in dummies2)
            {
                DeleteEdge(l);
            }
        }
Beispiel #6
0
        // Add a new line into the simple layout struct, new vertices and a new edge

        public void AddEdge(PointF WorldFrom, PointF WorldTo, int Width, int Height)
        {
            int nextindex = FindNextIndex();

            Vertex vP1 = new Vertex();

            vP1.Index = nextindex++;
            vP1.X     = WorldFrom.X;
            vP1.Y     = WorldFrom.Y;
            VertexList.Add(vP1);

            Vertex vP2 = new Vertex();

            vP2.Index = nextindex++;
            vP2.X     = WorldTo.X;
            vP2.Y     = WorldTo.Y;
            VertexList.Add(vP2);

            // Now add a segment

            Edge oEdge = new Edge();

            oEdge.Height      = 30;
            oEdge.Width       = 10;
            oEdge.p1          = vP1.Index;
            oEdge.p2          = vP2.Index;
            oEdge.ID          = "";
            oEdge.HoleGroupID = "";

            EdgeList.Add(oEdge);
        }
Beispiel #7
0
            public Geometry(Collada document, string geometryname, List <Triangle> triangles)
                : base(ns + "geometry", geometryname)
            {
                this.Symbol = geometryname;
                Dictionary <string, List <Triangle> > trilists = new Dictionary <string, List <Triangle> >();

                this.VertexList = new List <Vertex>();
                this.Materials  = new List <Material>();
                Dictionary <object, int> vtxrevindex = new Dictionary <object, int>();

                foreach (Triangle triangle in triangles)
                {
                    if (!trilists.ContainsKey(triangle.Texture.Name))
                    {
                        trilists[triangle.Texture.Name] = new List <Triangle>();
                        Material material = document.GetOrCreateMaterial(triangle.Texture);
                        Materials.Add(material);
                    }
                    trilists[triangle.Texture.Name].Add(triangle);
                    foreach (Vertex vertex in new Vertex[] { triangle.A, triangle.B, triangle.C })
                    {
                        if (!vtxrevindex.ContainsKey(vertex))
                        {
                            vtxrevindex[vertex] = VertexList.Count;
                            VertexList.Add(vertex);
                        }
                    }
                }

                PositionSource = new Source(geometryname + "_pos", "POSITION", VertexList.Select(v => v.Position), VertexList.Count);
                TexcoordSource = new TexCoordSource(geometryname + "_tex", "TEXCOORD", VertexList.Select(v => v.TexCoord), VertexList.Count, Materials);
                NormalSource   = VertexList[0].Normal != Vector4.Zero ? new Source(geometryname + "_normal", "NORMAL", VertexList.Select(v => v.Normal), VertexList.Count) : null;
                TangentSource  = VertexList[0].Tangent != Vector4.Zero ? new Source(geometryname + "_tangent", "TANGENT", VertexList.Select(v => v.Tangent), VertexList.Count) : null;
                BinormalSource = VertexList[0].Binormal != Vector4.Zero ? new Source(geometryname + "_binormal", "BINORMAL", VertexList.Select(v => v.Binormal), VertexList.Count) : null;
                VertexSource   = new VerticesSource(geometryname + "_vtx", "VERTEX", PositionSource, NormalSource, TangentSource, BinormalSource);

                this.Add(
                    new XElement(ns + "mesh",
                                 PositionSource,
                                 TexcoordSource,
                                 NormalSource,
                                 TangentSource,
                                 BinormalSource,
                                 VertexSource,
                                 Materials.Select(m =>
                                                  new XElement(ns + "triangles",
                                                               new XAttribute("count", trilists[m.Effect.Image.Texture.Name].Count),
                                                               new XAttribute("material", m.ID),
                                                               VertexSource.GetInput(0),
                                                               TexcoordSource.GetInput(1, m),
                                                               new XElement(ns + "p",
                                                                            "\n",
                                                                            String.Join("\n", trilists[m.Effect.Image.Texture.Name].Select(t => String.Join("  ", new Vertex[] { t.A, t.B, t.C }.Select(v => String.Format("{0} {0}", vtxrevindex[v]))))),
                                                                            "\n"
                                                                            )
                                                               )
                                                  )
                                 )
                    );
            }
Beispiel #8
0
        /*
         +  +  +  +
         |
         |   v  +  +  +  +
         | vcnt:3 |
         +--+--+--+
         |          u
         |       ucnt:4
         */
        public static VertexList CreateFlatControlPoints(int ucnt, int vcnt, Vector3d uunit, Vector3d vunit)
        {
            VertexList vl = new VertexList(ucnt * vcnt);

            Vector3d ud = ((double)(ucnt - 1) / 2.0) * uunit;
            Vector3d vd = ((double)(vcnt - 1) / 2.0) * vunit;

            Vector3d p = Vector3d.Zero;

            p -= ud;
            p -= vd;

            Vector3d lp = p;

            for (int v = 0; v < vcnt; v++)
            {
                p = lp;

                for (int u = 0; u < ucnt; u++)
                {
                    vl.Add(new CadVertex(p));
                    p += uunit;
                }

                lp += vunit;
            }

            return(vl);
        }
Beispiel #9
0
        public void Eval(VertexList vl)
        {
            double u;
            double v;

            for (int j = 0; j <= VBSpline.DivCnt; ++j)
            {
                v = j * VBSpline.Step + VBSpline.LowKnot;
                if (v >= VBSpline.HighKnot)
                {
                    v = VBSpline.HighKnot - BSpline.Epsilon;
                }

                for (int i = 0; i <= UBSpline.DivCnt; ++i)
                {
                    u = i * UBSpline.Step + UBSpline.LowKnot;
                    if (u >= UBSpline.HighKnot)
                    {
                        u = UBSpline.HighKnot - BSpline.Epsilon;
                    }

                    vl.Add(new CadVertex(CalcPoint(u, v)));
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Calculates and returns the shortest path between the specified vertices in the specified graph.
        /// </summary>
        /// <param name="startVertex">The start Vertex.</param>
        /// <param name="endVertex">The end vertex.</param>
        /// <returns>A graph that's updated with the calculated shortest paths.</returns>
        public VertexList <Vertex> GetShortestPath(Vertex startVertex, Vertex endVertex)
        {
            if (!_calculated)
            {
                CalculateShortestPaths();
            }

            VertexList <Vertex> path = new VertexList <Vertex>();

            if (_graph != null && _graph.VertexExists(startVertex) && _graph.VertexExists(endVertex))
            {
                Vertex currentVertex = endVertex;
                while (currentVertex != null)
                {
                    if (_graph.VertexExists(currentVertex))
                    {
                        path.Add(currentVertex);
                        currentVertex = currentVertex.Previous;
                    }
                    else
                    {
                        path.Clear();
                        break;
                    }
                }
                path.Reverse();
            }
            return(path);
        }
Beispiel #11
0
        public override void Undo(CadObjectDB db)
        {
            CadLayer  layer = db.GetLayer(LayerID);
            CadFigure fig   = db.GetFigure(FigureID);

            if (fig == null)
            {
                return;
            }

            int idx = PointIndex;
            int i   = 0;

            if (mPointList == null)
            {
                mPointList = new VertexList();
            }

            mPointList.Clear();

            for (; i < InsertNum; i++)
            {
                mPointList.Add(fig.GetPointAt(idx + i));
            }

            fig.RemovePointsRange(idx, InsertNum);
        }
Beispiel #12
0
        public eOperationStatus AppendEdge(int Width, int Height, int DeltaX, int DeltaY)
        {
            if (MostRecentlySelectedVertex == null)
            {
                return(eOperationStatus.NoVertexSelected);
            }

            // Add a new point
            int nextindex = FindNextIndex();

            Vertex vP = new Vertex();

            vP.Index = nextindex;
            vP.X     = MostRecentlySelectedVertex.X + DeltaX;
            vP.Y     = MostRecentlySelectedVertex.Y + DeltaY;
            VertexList.Add(vP);

            // Add an edge

            Edge oEdge = new Edge();

            oEdge.Height      = Height;
            oEdge.Width       = Width;
            oEdge.p1          = MostRecentlySelectedVertex.Index;
            oEdge.p2          = vP.Index;
            oEdge.ID          = "";
            oEdge.HoleGroupID = "";

            EdgeList.Add(oEdge);

            return(eOperationStatus.OK);
        }
Beispiel #13
0
        protected override void InternalCompute()
        {
            var      cancelManager = this.Services.CancelManager;
            EdgeHeap edgeHeap      = new EdgeHeap(this);
            //var edgeSortedList = new SortedList<double, TEdge>();
            TEdge   nextEdge;
            TVertex nextVertex;
            VertexList <TVertex> visited = new VertexList <TVertex>();
            TVertex start = VisitedGraph.Vertices.GetEnumerator().Current;

            TreeVertex(start);
            visited.Add(start);
            // adding all the outgoing edges to the sorted list
            foreach (var edge in VisitedGraph.Edges.Where(e => e.Source.Equals(start)))
            {
                edgeHeap.Add(edge);
            }

            if (cancelManager.IsCancelling)
            {
                return;
            }

            nextEdge   = edgeHeap.GetSmallest();
            nextVertex = nextEdge.Target;
            TreeVertex(nextVertex);
            TreeEdge(nextEdge);
            visited.Add(start);

            // adding one edge and one vertex untill tree is complete
            for (int i = 1; i <= VisitedGraph.VertexCount - 1; i++)
            {
                edgeHeap.RemoveAllTargetingVertex(nextVertex);

                var edges = VisitedGraph.Edges.Where(e => e.Source.Equals(nextVertex) && !visited.Contains(e.Target));
                foreach (var edge in edges)
                {
                    edgeHeap.Add(edge);
                }

                nextEdge   = edgeHeap.GetSmallest();
                nextVertex = nextEdge.Target;
                TreeVertex(nextVertex);
                TreeEdge(nextEdge);
                visited.Add(start);
            }
        }
Beispiel #14
0
 public Connection(Project project, Vertex a, Vertex b, params Vertex[] args)
     : this(project, a, b)
 {
     foreach (var vertex in args)
     {
         VertexList.Add(vertex);
     }
 }
Beispiel #15
0
 private void AddVertex(string vertex)
 {
     if (!VertexContains(vertex))
     {
         VertexList.Add(new Vertex(index, vertex));
         index++;
     }
 }
Beispiel #16
0
        public static List <VertexList <T> > Compute(Graph <T> graph, Vertex <T> startingVertex)
        {
            iteratorList = new VertexList <T>();
            allPathWitAStartingVertex = new List <VertexList <T> >();
            iteratorList.Add(startingVertex);
            DepthFirstSearch(startingVertex);

            return(allPathWitAStartingVertex.OrderBy(x => x.Count).ToList());
        }
Beispiel #17
0
        private void insertVertexToSameSenseEdge(Face Fa, int Bounds, int Edge, Vertex3d V)
        {
            EdgeLoop EL        = Fa.Bounds[Bounds];
            Edge     E         = EL[Edge];
            Face     Neigbhbor = null;
            int      outloop   = -1;
            double   d         = Face.GetDualEdge(Fa, Bounds, Edge + 0.5, ref outloop, ref Neigbhbor);
            EdgeLoop DualEL    = Neigbhbor.Bounds[outloop];

            int  DualEdge = (int)d;
            Edge F        = DualEL[DualEdge];
            // Zuerst die neue Kante

            Edge NewEdge = new Edge();

            EdgeList.Add(NewEdge);
            NewEdge.SameSense = true;
            NewEdge.EdgeStart = E.EdgeStart;
            NewEdge.EdgeEnd   = V;
            Line3D L = new Line3D(NewEdge.EdgeStart.Value, V.Value);

            EdgeCurveList.Add(L);
            L.Neighbors       = new Face[2];
            L.Neighbors[0]    = E.EdgeCurve.Neighbors[0];
            L.Neighbors[1]    = E.EdgeCurve.Neighbors[1];
            NewEdge.EdgeCurve = L;

            VertexList.Add(V);

            E.EdgeStart   = V;
            E.EdgeCurve.A = V.Value;

            EL.Insert(Edge, NewEdge);



            // Duale



            NewEdge           = new Edge();
            NewEdge.SameSense = false;
            EdgeList.Add(NewEdge);
            if (DualEdge + 1 < DualEL.Count)
            {
                DualEL.Insert(DualEdge + 1, NewEdge);
            }
            else
            {
                DualEL.Insert(0, NewEdge);
            }
            NewEdge.EdgeStart = V;
            NewEdge.EdgeEnd   = F.EdgeEnd;
            F.EdgeEnd         = V;
            NewEdge.EdgeCurve = L;
        }
Beispiel #18
0
        public object BeginLoad(XmlElementReader element)
        {
            switch (element.Attribute("style").Text)
            {
            case "solid":
            default:
                Style = ConnectionStyle.Solid;
                break;

            case "dashed":
                Style = ConnectionStyle.Dashed;
                break;
            }
            switch (element.Attribute("flow").Text)
            {
            case "twoWay":
            default:
                Flow = ConnectionFlow.TwoWay;
                break;

            case "oneWay":
                Flow = ConnectionFlow.OneWay;
                break;
            }
            StartText = element.Attribute("startText").Text;
            MidText   = element.Attribute("midText").Text;
            EndText   = element.Attribute("endText").Text;
            if (element.Attribute("color").Text != "")
            {
                ConnectionColor = ColorTranslator.FromHtml(element.Attribute("color").Text);
            }

            var vertexElementList = new List <XmlElementReader>();

            vertexElementList.AddRange(element.Children);
            vertexElementList.Sort((a, b) => a.Attribute("index").ToInt().CompareTo(b.Attribute("index").ToInt()));

            foreach (var vertexElement in vertexElementList)
            {
                if (vertexElement.HasName("point"))
                {
                    var vertex = new Vertex();
                    vertex.Position = new Vector(vertexElement.Attribute("x").ToFloat(), vertexElement.Attribute("y").ToFloat());
                    VertexList.Add(vertex);
                }
                else if (vertexElement.HasName("dock"))
                {
                    var vertex = new Vertex();
                    // temporarily leave this vertex as a positional vertex;
                    // we can't safely dock it to a port until EndLoad().
                    VertexList.Add(vertex);
                }
            }

            return(vertexElementList);
        }
Beispiel #19
0
        public static CadMesh CreateCylinder(int circleDiv, int slices, double r, double len)
        {
            VertexList vl = new VertexList();

            double sl = slices;

            double dl = len / sl;
            double y  = len / 2;

            for (double i = 0; i < sl; i++)
            {
                vl.Add(new CadVertex(r, y - (i * dl), 0));
            }

            vl.Add(new CadVertex(r, -len / 2, 0));

            return(CreateRotatingBody(
                       circleDiv, Vector3d.Zero, Vector3d.UnitY, vl, true, true, FaceType.TRIANGLE));
        }
Beispiel #20
0
        public static VertexList <T> Compute(Graph <T> graph, Vertex <T> startNode)
        {
            list      = new VertexList <T>();
            checkList = new VertexList <T>();

            checkList.Add(startNode);
            Search(startNode);

            return(list);
        }
Beispiel #21
0
        /// <summary>
        /// Returns a list containing all of the vertices in this Graph.
        /// </summary>
        /// <returns>A list containing all of the vertices in this Graph.</returns>
        public VertexList <VertexType> GetVertices()
        {
            VertexList <VertexType> vertices = new VertexList <VertexType>();

            foreach (VertexType vertex in _adjacentEdges.Keys)
            {
                vertices.Add(vertex);
            }
            return(vertices);
        }
        public eOperationStatus SplitMostRecentlySelectedEdge(float RelativeDistance)
        {
            if (EdgeList.Count == 0)
            {
                return(eOperationStatus.NoEdgesDefined);
            }

            if (MostRecentlySelectedEdge == null)
            {
                return(eOperationStatus.NoEdgeSelected);
            }

            Vertex v1 = FindVertexFromIndex(MostRecentlySelectedEdge.p1);
            Vertex v2 = FindVertexFromIndex(MostRecentlySelectedEdge.p2);

            SVector2 f = new SVector2(v1.X, v1.Y);
            SVector2 t = new SVector2(v2.X, v2.Y);

            SVector2 interpolatedVector = SVector2.Interpolate(f, t, RelativeDistance);

            /*
             * Get the point at the at this distance mark
             */
            PointF InterpolatedPoint = new PointF(interpolatedVector.X, interpolatedVector.Y);

            // Add the interpolated point as a new vertex
            Vertex vInterpolated = new Vertex();

            vInterpolated.Index = FindNextIndex();
            vInterpolated.X     = InterpolatedPoint.X;
            vInterpolated.Y     = InterpolatedPoint.Y;

            VertexList.Add(vInterpolated);

            // Create a new edge with two points, the interpolated point and the current p2

            Edge newEdge = new Edge();

            newEdge.Width       = MostRecentlySelectedEdge.Width;
            newEdge.Height      = MostRecentlySelectedEdge.Height;
            newEdge.ID          = "";
            newEdge.HoleGroupID = "";
            newEdge.p1          = vInterpolated.Index;
            newEdge.p2          = MostRecentlySelectedEdge.p2;

            EdgeList.Add(newEdge);

            // update the current edge, set its 'p2' point to the interpolated point. This will trim it
            // Also, clear out any holes, the split edge requires a reset

            MostRecentlySelectedEdge.p2          = vInterpolated.Index;
            MostRecentlySelectedEdge.HoleGroupID = "";

            return(eOperationStatus.OK);
        }
Beispiel #23
0
        public static VertexList VertexListFromMp(List <MpVertex_v1002> list)
        {
            VertexList ret = new VertexList(list.Count);

            for (int i = 0; i < list.Count; i++)
            {
                ret.Add(list[i].Restore());
            }

            return(ret);
        }
Beispiel #24
0
 public static void AddToCollision(Form_AreaEditor @base, VertexList vlist, Vertex[] vs, TriangleList tlist, Triangle[] ts)
 {
     foreach (Vertex v in vs)
     {
         vlist.Add(v);
     }
     foreach (Triangle t in ts)
     {
         tlist.Add(t);
     }
     @base.maps.ReloadCollisionInOpenGL();
 }
Beispiel #25
0
        public void DrawPoint(Angle lat, Angle lon)
        {
            //if (World.Settings.CurrentWwTool != this.drawTool)
            //    return;

            if (!isOn)
            {
                return;
            }
            #region state

            if (State == DrawState.Idle || State == DrawState.Complete)
            {
                if (!this.Initialized)
                {
                    this.Initialize(this.drawArgs);
                }
                State = DrawState.Drawing;
            }

            #endregion

            if (State == DrawState.Drawing && this.Initialized)
            {
                if (Angle.IsNaN(lat))
                {
                    return;
                }

                Point3d pickPt = new Point3d();
                pickPt.X = lon.Degrees;
                pickPt.Y = lat.Degrees;
                pickPt.Z = (useTerrain) ? getElevation(lat.Degrees, lon.Degrees) : defaultElev;

                if (PointList.Count > 0)
                {
                    List <CustomVertex.PositionColored> newVertexes = getCurveFromPoints(PointList[PointList.Count - 1], pickPt, lineColor);
                    VertexList.AddRange(newVertexes.GetRange(1, newVertexes.Count - 1));
                }
                else
                {
                    VertexList.Add(Point3d2PositionColored(pickPt, lineColor));
                }
                PointList.Add(pickPt);

                //虽然我也不知道为什么但是不加这一段整个三维球界面都会变黑
                movingPt.IsNaN = false;
                movingPt.X     = pickPt.X;
                movingPt.Y     = pickPt.Y;
                movingPt.Z     = pickPt.Z;
                UpdateTrackVertexList();
            }
        }
Beispiel #26
0
        public static VertexList GetExpandList(
            VertexList src,
            int curveSplitNum)
        {
            int cnt = src.Count;

            VertexList ret = new VertexList(curveSplitNum * ((cnt + 1) / 2));

            ForEachPoints <Object>(src, curveSplitNum, (v, d) => { ret.Add(v); }, null);

            return(ret);
        }
Beispiel #27
0
        protected Vertex NewVertex(float X, float Y)
        {
            Vertex vNew = new Vertex();

            vNew.Index = FindNextIndex();
            vNew.X     = X;
            vNew.Y     = Y;

            VertexList.Add(vNew);

            return(vNew);
        }
Beispiel #28
0
        public void Eval(VertexList vl)
        {
            for (int p = 0; p <= BSplineP.DivCnt; ++p)
            {
                double t = p * BSplineP.Step + BSplineP.LowKnot;
                if (t >= BSplineP.HighKnot)
                {
                    t = BSplineP.HighKnot - BSpline.Epsilon;
                }

                vl.Add(new CadVertex(CalcPoint(t)));
            }
        }
Beispiel #29
0
        public void TestVertexList()
        {
            VertexList <Vertex> vl = new VertexList <Vertex>();

            Assert.AreEqual(vl.Count, 0);
            Vertex v0 = new Vertex();
            Vertex v1 = new Vertex();

            vl.Add(0, v0);
            vl.Add(1, v1);

            foreach (KeyValuePair <int, Vertex> pair in vl)
            {
                Assert.IsNotNull(pair);
                Assert.IsNotNull(pair.Value);
            }

            Assert.AreEqual(vl.Count, 2);
            Assert.IsTrue(vl.ContainsKey(0));
            Assert.IsTrue(vl.ContainsKey(1));
            Assert.IsTrue(vl.Contains(new KeyValuePair <int, Vertex>(0, v0)));
            Assert.IsTrue(vl.Contains(new KeyValuePair <int, Vertex>(1, v1)));

            Vertex re = null;

            Assert.IsTrue(vl.TryGetValue(0, out re));
            Assert.AreEqual(re, v0);
            re = null;
            Assert.IsFalse(vl.TryGetValue(2, out re));
            Assert.IsNull(re);

            Assert.IsTrue(vl.Remove(new KeyValuePair <int, Vertex>(0, v0)));
            Assert.IsTrue(vl.ContainsKey(0));
            Assert.IsFalse(vl.ContainsKey(1));
            Assert.AreEqual(vl[0], v1);
            Assert.IsTrue(vl.Remove(0));
            Assert.AreEqual(vl.Count, 0);
        }
Beispiel #30
0
        private int AddVertexToMesh(Vector3 point, Color color, Vector3 normal)
        {
            //Make it into a vertex
            VertexPositionColorNormal v = new VertexPositionColorNormal(point, color, normal);

            //Check if vertex already exists
            //if (VertexList.Contains(v))
            //return VertexList.IndexOf(v);
            //else
            {
                VertexList.Add(v);
                return(VertexList.Count - 1);
            }
        }
Beispiel #31
0
        static void HandleTree(VertexList<SceneryVertex> sceneryVertexList, TileData td, ref IntVector3 pos)
        {
            SymbolID symbol;
            Color color;

            switch (td.ID)
            {
                case TileID.Tree:
                    switch (td.MaterialID)
                    {
                        case MaterialID.Fir:
                            symbol = SymbolID.ConiferousTree;
                            break;

                        case MaterialID.Pine:
                            symbol = SymbolID.ConiferousTree2;
                            break;

                        case MaterialID.Birch:
                            symbol = SymbolID.DeciduousTree;
                            break;

                        case MaterialID.Oak:
                            symbol = SymbolID.DeciduousTree2;
                            break;

                        default:
                            throw new Exception();
                    }
                    break;

                case TileID.Sapling:
                    switch (td.MaterialID)
                    {
                        case MaterialID.Fir:
                            symbol = SymbolID.ConiferousSapling;
                            break;

                        case MaterialID.Pine:
                            symbol = SymbolID.ConiferousSapling2;
                            break;

                        case MaterialID.Birch:
                            symbol = SymbolID.DeciduousSapling;
                            break;

                        case MaterialID.Oak:
                            symbol = SymbolID.DeciduousSapling2;
                            break;

                        default:
                            throw new Exception();
                    }
                    break;

                case TileID.DeadTree:
                    symbol = SymbolID.DeadTree;
                    break;

                default:
                    throw new Exception();
            }

            color = Color.ForestGreen;

            sceneryVertexList.Add(new SceneryVertex(pos.ToVector3(), Color.LightGreen, (uint)symbol));
        }
Beispiel #32
0
        void CreateCube(IntVector3 p, Direction visibleFaces,
			ref FaceTexture baseTexture, ref FaceTexture topTexture, VertexList<TerrainVertex> vertexList,
			Direction sliceFaces)
        {
            var offset = p - this.ChunkOffset;

            int sides = (int)visibleFaces;

            for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1)
            {
                if ((sides & 1) == 0)
                    continue;

                var vertices = s_cubeFaceInfo[side].Vertices;

                IntVector3 v0, v1, v2, v3;

                v0 = vertices[0] + offset;
                v1 = vertices[1] + offset;
                v2 = vertices[2] + offset;
                v3 = vertices[3] + offset;

                Direction dir = (Direction)(1 << side);

                bool isSliceFace = (sliceFaces & dir) != 0;

                int occ0, occ1, occ2, occ3;

                if (isSliceFace)
                {
                    occ0 = occ1 = occ2 = occ3 = 0;
                }
                else
                {
                    GetOcclusionsForFace(p, (DirectionOrdinal)side,
                        out occ0, out occ1, out occ2, out occ3);
                }

                var tex = side == (int)DirectionOrdinal.PositiveZ ? topTexture : baseTexture;
                byte sliceHack = isSliceFace ? (byte)1 : (byte)0;

                var vd = new TerrainVertex(v0, v1, v2, v3, occ0, occ1, occ2, occ3,
                    tex, sliceHack);
                vertexList.Add(vd);
            }
        }
Beispiel #33
0
        void CreateUndefinedChunk(ref IntGrid3 viewGrid, ref IntGrid3 chunkGrid, VertexList<TerrainVertex> vertexList,
			Direction visibleChunkFaces)
        {
            // Faces that are visible due to viewgrid
            Direction sliceFaces = GetGridSliceDirections(ref chunkGrid, ref viewGrid) & visibleChunkFaces;

            // Only faces revealed by viewgrid are visible
            Direction visibleFaces = sliceFaces;

            if (visibleFaces == 0)
                return;

            int sides = (int)visibleFaces;

            FaceTexture tex = Chunk.UndefinedFaceTexture;

            const int occlusion = 0;
            var offset = chunkGrid.Corner1 - this.ChunkOffset;
            var size = new IntVector3(chunkGrid.Size.Width, chunkGrid.Size.Height, chunkGrid.Size.Depth);

            // All faces are revealed by viewgrid
            byte sliceHack = (byte)1;

            if (Chunk.UseBigUnknownChunk)
            {
                /* Note: Using chunk sized quads causes t-junction problems */

                for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1)
                {
                    if ((sides & 1) == 0)
                        continue;

                    var vertices = s_cubeFaceInfo[side].Vertices;

                    IntVector3 v0 = vertices[0] * size + offset;
                    IntVector3 v1 = vertices[1] * size + offset;
                    IntVector3 v2 = vertices[2] * size + offset;
                    IntVector3 v3 = vertices[3] * size + offset;

                    var vd = new TerrainVertex(v0, v1, v2, v3, occlusion, occlusion, occlusion, occlusion, tex, sliceHack);
                    vertexList.Add(vd);
                }
            }
            else
            {
                for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1)
                {
                    if ((sides & 1) == 0)
                        continue;

                    int d0 = side / 2;
                    int d1 = (d0 + 1) % 3;
                    int d2 = (d0 + 2) % 3;

                    bool posFace = (side & 1) == 1;

                    var vertices = s_cubeFaceInfo[side].Vertices;

                    IntVector3 v0 = vertices[0] + offset;
                    IntVector3 v1 = vertices[1] + offset;
                    IntVector3 v2 = vertices[2] + offset;
                    IntVector3 v3 = vertices[3] + offset;

                    var vec1 = new IntVector3();
                    vec1[d1] = 1;

                    var vec2 = new IntVector3();
                    vec2[d2] = 1;

                    for (int v = 0; v < size[d1]; ++v)
                        for (int u = 0; u < size[d2]; ++u)
                        {
                            var off = vec1 * v + vec2 * u;
                            if (posFace)
                                off[d0] = size[d0] - 1;

                            var vd = new TerrainVertex(v0 + off, v1 + off, v2 + off, v3 + off,
                                occlusion, occlusion, occlusion, occlusion, tex, sliceHack);
                            vertexList.Add(vd);
                        }
                }
            }
        }