Exemplo n.º 1
0
        /// <summary>
        /// GridMapに障害物の線を追加
        /// </summary>
        /// <param name="startX"></param>
        /// <param name="startY"></param>
        /// <param name="endX"></param>
        /// <param name="endY"></param>
        /// <param name="size"></param>
        public void DrawLine(int startX, int startY, int endX, int endY, int size)
        {
            LineDelegate f = delegate(GridMap map, int x, int y) {
                if (size == 0)
                {
                    map[x, y] = Grid.Fill;
                }
                else
                {
                    // 太さ(size)分 グリッドを埋める
                    for (int dx = -size; dx < size; ++dx)
                    {
                        for (int dy = -size; dy < size; ++dy)
                        {
                            if (0 < x + dx && x + dx < W && 0 < y + dy && y + dy < H)
                            {
                                map[x + dx, y + dy] = Grid.Fill;
                            }
                        }
                    }
                }
            };

            DrawLine(startX, startY, endX, endY, f);
        }
Exemplo n.º 2
0
        public void DrawLine(int startX, int startY, int endX, int endY, LineDelegate f)
        {
            int deltaX = 2 * (endX - startX);
            int deltaY = 2 * (endY - startY);
            int stepX  = deltaX < 0 ? -1 : 1;
            int stepY  = deltaY < 0 ? -1 : 1;
            int nextX  = startX;
            int nextY  = startY;
            int fraction;

            deltaX = Math.Abs(deltaX);
            deltaY = Math.Abs(deltaY);

            f(this, startX, startY);

            if (deltaX > deltaY)
            {
                fraction = deltaY - deltaX / 2;
                while (nextX != endX)
                {
                    if (fraction >= 0)
                    {
                        nextY    += stepY;
                        fraction -= deltaX;
                        f(this, nextX, nextY);
                    }
                    nextX    += stepX;
                    fraction += deltaY;
                    //処理
                    f(this, nextX, nextY);
                }
            }
            else
            {
                fraction = deltaX - deltaY / 2;
                while (nextY != endY)
                {
                    if (fraction >= 0)
                    {
                        nextX    += stepX;
                        fraction -= deltaY;
                        f(this, nextX, nextY);
                    }
                    nextY    += stepY;
                    fraction += deltaX;
                    //処理
                    f(this, nextX, nextY);
                }
            }
        }
        internal static void DrawCapsuleFast(Vector3 point1, Vector3 point2, float radius, Vector3 axis, Vector3 crossA, Vector3 crossB, LineDelegate lineDelegate)
        {
            //Circles
            DrawCircleFast(point1, axis, crossB, radius, lineDelegate);
            DrawCircleFast(point2, axis, crossB, radius, lineDelegate);

            //Caps
            DrawArc(point1, crossB, crossA, radius, 180, lineDelegate, 25);
            DrawArc(point1, crossA, crossB, radius, -180, lineDelegate, 25);

            DrawArc(point2, crossB, crossA, radius, -180, lineDelegate, 25);
            DrawArc(point2, crossA, crossB, radius, 180, lineDelegate, 25);

            //Joining Lines
            Vector3 a = crossA * radius;
            Vector3 b = crossB * radius;

            lineDelegate.Invoke(point1 + a, point2 + a, 0);
            lineDelegate.Invoke(point1 - a, point2 - a, 0);
            lineDelegate.Invoke(point1 + b, point2 + b, 0);
            lineDelegate.Invoke(point1 - b, point2 - b, 0);
        }
        internal static void DrawCapsule2DFast(Vector2 offset, DrawCapsuleStructure2D capsuleStructure2D, LineDelegate lineDelegate)
        {
            Vector2 r1 = offset + capsuleStructure2D.VerticalOffset;
            Vector2 r2 = offset - capsuleStructure2D.VerticalOffset;

            DrawArc2D(r1, capsuleStructure2D.Left, capsuleStructure2D.Radius, 180, lineDelegate);
            DrawArc2D(r2, capsuleStructure2D.Left, capsuleStructure2D.Radius, -180, lineDelegate);
            lineDelegate(r1 + capsuleStructure2D.ScaledLeft, r2 + capsuleStructure2D.ScaledLeft, 0);
            lineDelegate(r1 + capsuleStructure2D.ScaledRight, r2 + capsuleStructure2D.ScaledRight, 0);
        }
        internal static void DrawArc2D(Vector2 center, Vector2 startDirection, float radius, float totalAngle, LineDelegate lineDelegate, int segmentCount = 50)
        {
            Vector2 direction = startDirection * radius;
            Vector2 lastPos   = center + direction;

            GetRotationCoefficients(1 / (float)segmentCount * totalAngle, out var s, out var c);

            Vector2 currentDirection = direction;

            for (int i = 1; i <= segmentCount; i++)
            {
                currentDirection = RotateFast(currentDirection, s, c);
                Vector2 nextPos = center + currentDirection;
                lineDelegate(lastPos, nextPos, (i - 1) / (float)segmentCount);
                lastPos = nextPos;
            }
        }
        internal static void DrawArc(Vector3 center, Vector3 normal, Vector3 startDirection, float radius, float totalAngle, LineDelegate lineDelegate, int segmentCount = 50)
        {
            Vector3    direction       = startDirection * radius;
            Vector3    lastPos         = center + direction;
            Quaternion rotation        = Quaternion.AngleAxis(1 / (float)segmentCount * totalAngle, normal);
            Quaternion currentRotation = rotation;

            for (int i = 1; i <= segmentCount; i++)
            {
                Vector3 nextPos = center + currentRotation * direction;
                lineDelegate(lastPos, nextPos, (i - 1) / (float)segmentCount);
                currentRotation = rotation * currentRotation;
                lastPos         = nextPos;
            }
        }
        internal static void DrawCircleFast(Vector3 center, Vector3 normal, Vector3 cross, float radius, LineDelegate lineDelegate, int segmentCount = 100)
        {
            Vector3    direction       = cross * radius;
            Vector3    lastPos         = center + direction;
            Quaternion rotation        = Quaternion.AngleAxis(1 / (float)segmentCount * 360, normal);
            Quaternion currentRotation = rotation;

            for (int i = 1; i <= segmentCount; i++)
            {
                Vector3 nextPos = center + currentRotation * direction;
                lineDelegate(lastPos, nextPos, (i - 1) / (float)segmentCount);
                currentRotation = rotation * currentRotation;
                lastPos         = nextPos;
            }
        }
Exemplo n.º 8
0
 public AsciiSendLineAndApplyMethodUnit(string line, string terminator, LineDelegate method)
 {
     _line       = line;
     _terminator = terminator;
     _method     = method;
 }
Exemplo n.º 9
0
        public void DrawLine(int startX, int startY, int endX, int endY, LineDelegate f)
        {
            int deltaX = 2 * (endX - startX);
            int deltaY = 2 * (endY - startY);
            int stepX = deltaX < 0 ? -1 : 1;
            int stepY = deltaY < 0 ? -1 : 1;
            int nextX = startX;
            int nextY = startY;
            int fraction;
            deltaX = Math.Abs(deltaX);
            deltaY = Math.Abs(deltaY);

            f(this, startX, startY);

            if (deltaX > deltaY) {
                fraction = deltaY - deltaX / 2;
                while (nextX != endX) {
                    if (fraction >= 0) {
                        nextY += stepY;
                        fraction -= deltaX;
                        f(this, nextX, nextY);
                    }
                    nextX += stepX;
                    fraction += deltaY;
                    //処理
                    f(this, nextX, nextY);
                }
            } else {
                fraction = deltaX - deltaY / 2;
                while (nextY != endY) {
                    if (fraction >= 0) {
                        nextX += stepX;
                        fraction -= deltaY;
                        f(this, nextX, nextY);
                    }
                    nextY += stepY;
                    fraction += deltaX;
                    //処理
                    f(this, nextX, nextY);
                }
            }
        }