コード例 #1
0
ファイル: RenderNav.cs プロジェクト: RoadTrain/Mafia2Toolkit
        public void SelectNode(int Index)
        {
            // TODO: Big problem here - The graphics class isn't aware of the selecting logic here.
            // So we'll one day need to support the graphics class aware of this and deselect this whenever another
            // object has been selected.
            if (SelectedIndex != -1)
            {
                BoundingBoxes[SelectedIndex].Unselect();
            }

            // Move the selection to the new Vertex
            BoundingBoxes[Index].Select();
            SelectedIndex = Index;

            // Render debug work
            OBJData.VertexStruct PathPoint = data.vertices[Index];
            RenderLine           FromA     = CreateConnectionLine(PathPoint, data.vertices[PathPoint.Unk3], System.Drawing.Color.Yellow);
            RenderLine           FromB     = CreateConnectionLine(PathPoint, data.vertices[PathPoint.Unk4], System.Drawing.Color.Brown);
            RenderLine           FromC     = CreateConnectionLine(PathPoint, data.vertices[PathPoint.Unk5], System.Drawing.Color.Red);

            PointConnectionsBatch.ClearObjects();
            PointConnectionsBatch.AddObject(RefManager.GetNewRefID(), FromA);
            PointConnectionsBatch.AddObject(RefManager.GetNewRefID(), FromB);
            PointConnectionsBatch.AddObject(RefManager.GetNewRefID(), FromC);

            foreach (var IncomingPoint in PathPoint.IncomingConnections)
            {
                RenderLine Connection = CreateConnectionLine(PathPoint, IncomingPoint, System.Drawing.Color.Green);
                PointConnectionsBatch.AddObject(RefManager.GetNewRefID(), Connection);
            }

            foreach (var OutgoingPoint in PathPoint.OutgoingConnections)
            {
                RenderLine Connection = CreateConnectionLine(PathPoint, OutgoingPoint, System.Drawing.Color.Blue);
                PointConnectionsBatch.AddObject(RefManager.GetNewRefID(), Connection);
            }

            PointConnectionsBatch.SetIsDirty();
        }
コード例 #2
0
ファイル: Render2DPlane.cs プロジェクト: nptr/MafiaToolkit
        public void Init(ref Vector3[] points, ResourceTypes.Navigation.LaneProperties lane, ResourceTypes.Navigation.RoadFlags roadFlags)
        {
            vertices = new VertexLayouts.BasicLayout.Vertex[points.Length * 2];
            indices  = new ushort[(vertices.Length - 2) * 3];
            int idx = 0;

            for (int i = 0; i < points.Length; i++)
            {
                if (lane.Flags.HasFlag(ResourceTypes.Navigation.LaneTypes.MainRoad) || (lane.Flags.HasFlag(ResourceTypes.Navigation.LaneTypes.IsHighway)))
                {
                    colour = Color.Blue;
                }
                else if (lane.Flags.HasFlag(ResourceTypes.Navigation.LaneTypes.Parking))
                {
                    colour = Color.Green;
                }
                else if (lane.Flags.HasFlag(ResourceTypes.Navigation.LaneTypes.ExcludeImpassible))
                {
                    colour = Color.FromArgb(255, 128, 26, 0);
                }
                else if (lane.Flags.HasFlag(ResourceTypes.Navigation.LaneTypes.ExcludeImpassible) && lane.Flags.HasFlag(ResourceTypes.Navigation.LaneTypes.BackRoad))
                {
                    colour = Color.FromArgb(255, 128, 51, 230);
                }
                else if (lane.Flags.HasFlag(ResourceTypes.Navigation.LaneTypes.BackRoad))
                {
                    colour = Color.FromArgb(255, 128, 51, 230);
                }

                vertices[idx]          = new VertexLayouts.BasicLayout.Vertex();
                vertices[idx].Position = points[i];
                vertices[idx].Colour   = colour.ToArgb();
                Vector2 forward = Vector2.Zero;

                if (i < points.Length - 1)
                {
                    forward += (new Vector2(points[(i + 1) % points.Length].X, points[(i + 1) % points.Length].Y) - new Vector2(points[i].X, points[i].Y));
                }
                if (i > 0)
                {
                    forward += new Vector2(points[i].X, points[i].Y) - new Vector2(points[(i - 1) % points.Length].X, points[(i - 1) % points.Length].Y);
                }

                forward.Normalize();
                Vector3 left = new Vector3(-forward.Y, forward.X, points[i].Z);
                idx++;
                vertices[idx] = new VertexLayouts.BasicLayout.Vertex();

                float x = 0.0f;
                float y = 0.0f;

                if (roadFlags.HasFlag(ResourceTypes.Navigation.RoadFlags.BackwardDirection))
                {
                    x = (points[i].X - left.X * lane.Width);
                    y = (points[i].Y - left.Y * lane.Width);
                }
                else
                {
                    x = (points[i].X + left.X * lane.Width);
                    y = (points[i].Y + left.Y * lane.Width);
                }

                vertices[idx].Position = new Vector3(x, y, points[i].Z);
                vertices[idx].Colour   = colour.ToArgb();
                points[i] = vertices[idx].Position;

                RenderLine line = new RenderLine();
                line.SetUnselectedColour(Color.Blue);
                line.Init(new Vector3[2] {
                    vertices[idx - 1].Position, vertices[idx].Position
                });
                idx++;

                ushort sIdx       = 0;
                int    indIdx     = 0;
                bool   switcheroo = false;
                while (indIdx < indices.Length)
                {
                    if (switcheroo == false)
                    {
                        indices[indIdx]     = sIdx++;
                        indices[indIdx + 1] = sIdx++;
                        indices[indIdx + 2] = sIdx++;
                        switcheroo          = true;
                    }
                    else
                    {
                        indices[indIdx]     = sIdx--;
                        indices[indIdx + 1] = sIdx--;
                        indices[indIdx + 2] = sIdx--;

                        switcheroo = false;
                    }
                    sIdx    = (ushort)(indices[indIdx + 2] + 1);
                    indIdx += 3;
                }
            }
        }