示例#1
0
        public static Segment FromString(string segmentString)
        {
            Segment returnSegment = new Segment();

            string[] parts = segmentString.Split(',');

            returnSegment.Position.X = float.Parse(parts[0]);
            returnSegment.Position.Y = float.Parse(parts[1]);
            returnSegment.Position.Z = float.Parse(parts[2]);

            returnSegment.Normal.X = float.Parse(parts[3]);
            returnSegment.Normal.Y = float.Parse(parts[4]);
            returnSegment.Normal.Z = float.Parse(parts[5]);

            returnSegment.Offset.X = float.Parse(parts[6]);
            returnSegment.Offset.Y = float.Parse(parts[7]);
            returnSegment.Offset.Z = float.Parse(parts[8]);

            returnSegment.Size.X = float.Parse(parts[9]);
            returnSegment.Size.Y = float.Parse(parts[10]);

            returnSegment.TextureName = parts[11];

            returnSegment.Tint.X = float.Parse(parts[12]);
            returnSegment.Tint.Y = float.Parse(parts[13]);
            returnSegment.Tint.Z = float.Parse(parts[14]);

            returnSegment.TrackSurface = (SurfaceType)int.Parse(parts[15]); ;

            returnSegment.AboveOffset.X = float.Parse(parts[16]);
            returnSegment.AboveOffset.Y = float.Parse(parts[17]);
            returnSegment.AboveOffset.Z = float.Parse(parts[18]);

            returnSegment.AboveSize.X = float.Parse(parts[19]);
            returnSegment.AboveSize.Y = float.Parse(parts[20]);

            returnSegment.AboveTextureName = parts[21];

            returnSegment.AboveTint.X = float.Parse(parts[22]);
            returnSegment.AboveTint.Y = float.Parse(parts[23]);
            returnSegment.AboveTint.Z = float.Parse(parts[24]);

            returnSegment.LeftOffset.X = float.Parse(parts[25]);
            returnSegment.LeftOffset.Y = float.Parse(parts[26]);
            returnSegment.LeftOffset.Z = float.Parse(parts[27]);

            returnSegment.LeftSize.X = float.Parse(parts[28]);
            returnSegment.LeftSize.Y = float.Parse(parts[29]);

            returnSegment.LeftTextureName = parts[30];

            returnSegment.LeftTint.X = float.Parse(parts[31]);
            returnSegment.LeftTint.Y = float.Parse(parts[32]);
            returnSegment.LeftTint.Z = float.Parse(parts[33]);

            returnSegment.LeftScenery = (SceneryType)int.Parse(parts[34]);

            returnSegment.RightOffset.X = float.Parse(parts[35]);
            returnSegment.RightOffset.Y = float.Parse(parts[36]);
            returnSegment.RightOffset.Z = float.Parse(parts[37]);

            returnSegment.RightSize.X = float.Parse(parts[38]);
            returnSegment.RightSize.Y = float.Parse(parts[39]);

            returnSegment.RightTextureName = parts[40];

            returnSegment.RightTint.X = float.Parse(parts[41]);
            returnSegment.RightTint.Y = float.Parse(parts[42]);
            returnSegment.RightTint.Z = float.Parse(parts[43]);

            returnSegment.RightScenery = (SceneryType)int.Parse(parts[44]);

            return returnSegment;
        }
示例#2
0
        public void Rebuild(List<Vector3> controlPoints)
        {
            TrackSegments.Clear();

            for (int num = 0; num < controlPoints.Count; num++)
            {
                // Get the 4 required points for the catmull rom spline
                Vector3 p1 = controlPoints[num - 1 < 0 ? controlPoints.Count - 1 : num - 1];
                Vector3 p2 = controlPoints[num];
                Vector3 p3 = controlPoints[(num + 1) % controlPoints.Count];
                Vector3 p4 = controlPoints[(num + 2) % controlPoints.Count];

                // Calculate number of iterations we use here based
                // on the distance of the 2 points we generate new points from.
                float distance = Vector3.Distance(p2, p3);
                int numberOfIterations =
                    (int)(SEGMENTS_PER100M * (distance / 100.0f));
                if (numberOfIterations <= 0)
                    numberOfIterations = 1;

                for (int iter = 0; iter < numberOfIterations; iter++)
                {
                    Vector3 newVertex = Vector3.CatmullRom(p1, p2, p3, p4, iter / (float)numberOfIterations);

                    Segment s = new Segment();
                    s.Position = newVertex;
                    TrackSegments.Add(s);
                } // for (iter)


            } // for (num)

            for (int i = TrackSegments.Count - 1; i >= 0; i--)
            {
                int pos = i;
                int prevpos = i - 1;
                if (pos >= TrackSegments.Count) pos = pos - (TrackSegments.Count);
                if (prevpos >= TrackSegments.Count) prevpos = prevpos - TrackSegments.Count;
                if (prevpos < 0) prevpos = TrackSegments.Count + prevpos;

                Vector3 normal = TrackSegments[prevpos].Position - TrackSegments[pos].Position;
                normal.Normalize();
                TrackSegments[i].Normal = normal;

                TrackSegments[i].Paint(i, RoadBrush.Road, AboveBrush.None, SceneryBrush.None, SceneryBrush.None);
            }
            TrackSegments[0].Paint(0, RoadBrush.Road, AboveBrush.StartGrid, SceneryBrush.None, SceneryBrush.None);

            Length = TrackSegments.Count;
        }