Пример #1
0
        public void AddIntersectLines(List <Point> points, int surfaceIndex, Obstacle forObstacle, MovementMechanism forMechanism)
        {
            VolumeTree <ObstacleHitLine> collection = SurfaceObstacleLines[surfaceIndex];

            if (collection == null)
            {
                SimpleVolume surfaceVolume = MyVolume;
                switch (surfaceIndex)
                {
                case 0:
                    surfaceVolume.MaxZ = surfaceVolume.MinZ;
                    break;

                case 1:
                    surfaceVolume.MinZ = surfaceVolume.MaxZ;
                    break;

                case 2:
                    surfaceVolume.MaxY = surfaceVolume.MinY;
                    break;

                case 3:
                    surfaceVolume.MinX = surfaceVolume.MaxX;
                    break;

                case 4:
                    surfaceVolume.MinY = surfaceVolume.MaxY;
                    break;

                case 5:
                    surfaceVolume.MaxX = surfaceVolume.MinX;
                    break;
                }
                collection = new VolumeTree <ObstacleHitLine>(surfaceVolume);
                SurfaceObstacleLines[surfaceIndex] = collection;
            }
            ObstacleHitLineGroup lineGroup = new ObstacleHitLineGroup();

            lineGroup.CausingObstacle = forObstacle;
            lineGroup.Mechanism       = forMechanism;

            lineGroup.SetupPoints(points, collection, SurfaceNormal(surfaceIndex));
        }
Пример #2
0
        public void SetupPoints(List <Point> points, VolumeTree <ObstacleHitLine> collectionToPopulate, Vector surfaceNormal)
        {
            Volume.MaxX = points[0].x;
            Volume.MaxY = points[0].y;
            Volume.MaxZ = points[0].z;
            Volume.MinX = points[0].x;
            Volume.MinY = points[0].y;
            Volume.MinZ = points[0].z;
            hitLines.Add(new HitLineData()
            {
                startPoint = points[0]
            });
            for (int i = 1; i < points.Count; i++)
            {
                //ObstacleHitLine nextLine = new ObstacleHitLine();
                hitLines.Add(new HitLineData()
                {
                    startPoint = points[i]
                });
                Volume.MaxX = Math.Max(Volume.MaxX, points[i].x);
                Volume.MinX = Math.Min(Volume.MinX, points[i].x);
                Volume.MaxY = Math.Max(Volume.MaxY, points[i].y);
                Volume.MinY = Math.Min(Volume.MinY, points[i].y);
                Volume.MaxZ = Math.Max(Volume.MaxZ, points[i].z);
                Volume.MinZ = Math.Min(Volume.MinZ, points[i].z);
            }
            //1 point: no lines. Shouldn't happen?
            //2 points: 1 line.
            //X points: X lines.
            int stop = points.Count;

            if (stop < 3)
            {
                stop--;           //I have no plans currently for this to ever happen but just to keep the logic complete
            }
            for (int i = 0; i < stop; i++)
            {
                ObstacleHitLine nextLine;
                nextLine.owner      = this;
                nextLine.groupIndex = i;
                collectionToPopulate.Add(nextLine);
            }
            if (stop < 4)
            {
                return;           //triangle shapes might stop early, and can never intersect themselves.
            }
            //Find own overlaps. For each line, check collisions with each later line, mark collision on both.
            int minOverlaps = 0;

            StructListStruct <HitLineSetupOverlapData>[] setupOverlaps = new StructListStruct <HitLineSetupOverlapData> [points.Count];
            StructListStruct <int> nextLinesToSkip = default(StructListStruct <int>);

            stop = points.Count - 1; //Skip the last line for the first run - adjacent lines can't run into eachother.
            bool collide;
            HitLineSetupOverlapData newOverlap;
            //Initialize things for i loop
            Point  end             = points[0];
            Vector nextFirstVector = end.VectorTo(points[1]);
            Vector nextLineNormal  = surfaceNormal.CrossProduct(nextFirstVector);

            for (int i = 0; i < points.Count - 2; i++)
            {
                StructListStruct <int> linesToSkip = nextLinesToSkip;
                nextLinesToSkip = default(StructListStruct <int>);
                Point start = end;
                end = points[i + 1];
                Vector firstVector = nextFirstVector;
                Vector lineNormal  = nextLineNormal;
                nextFirstVector = end.VectorTo(points[i + 2]); //These are useful in some cases to know ahead of time.
                nextLineNormal  = surfaceNormal.CrossProduct(nextFirstVector);

                int startIndex = i + 2;
                FindOverlapsInner(startIndex, stop, linesToSkip, surfaceNormal,
                                  start, end, firstVector, lineNormal, nextFirstVector, nextLineNormal,
                                  i, this, setupOverlaps);

                stop = points.Count;
            }
        }