Beispiel #1
0
        private bool OnEvent(SDL.SDL_Event sdlEvent)
        {
            bool draw = true;

            switch (sdlEvent.type)
            {
            case SDL.SDL_EventType.SDL_QUIT:
            {
                return(true);
            }

            case SDL.SDL_EventType.SDL_KEYDOWN:
            {
                var    key  = sdlEvent.key;
                string test = SDL.SDL_GetScancodeName(SDL.SDL_GetScancodeFromKey(key.keysym.sym));
                switch (key.keysym.sym)
                {
                case SDL.SDL_Keycode.SDLK_DOWN:
                {
                    ShowConsole();
                }
                break;
                }
            }
            break;

            case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
            {
                // start or stop rendering on left mouse button click
                if (sdlEvent.button.button == SDL.SDL_BUTTON_LEFT)
                {
                    draw         = !draw; // toggle value
                    mouseClicked = true;
                    prevX        = sdlEvent.button.x;
                    prevY        = sdlEvent.button.y;
                }
            }
            break;

            case SDL.SDL_EventType.SDL_MOUSEMOTION:
            {
                if (mouseClicked)
                {
                    int x = sdlEvent.button.x;
                    int y = sdlEvent.button.y;

                    if (BuildPolygon.isPointInsidePolygon(rectangle.Points, rectangle.Points.Length, x, y))
                    {
                        animParams.RectOffsetX += (x - prevX);
                        animParams.RectOffSetY += (y - prevY);
                    }
                    if (BuildPolygon.isPointInsidePolygon(cicle.Points, cicle.Points.Length, x, y))
                    {
                        animParams.CiclOffsetX += (x - prevX);
                        animParams.CiclOffSetY += (y - prevY);
                    }
                }
            }
            break;

            case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
            {
                mouseClicked = false;
            }
            break;
            }

            if (draw)
            {
                OnRender();
                Thread.Sleep(10); // somehow calibrate render loop
            }

            return(false);
        }
Beispiel #2
0
        SDL.SDL_Point[] FindIntersectionPoints(SDL.SDL_Point[] clippingPoints, SDL.SDL_Point[] polygonPoints, bool isRectangle)
        {
            int length = polygonPoints.Length;

            SDL.SDL_Point[]    points       = new SDL.SDL_Point[length];
            bool[]             isInside     = new bool[length];
            bool               isOutside    = false;
            IntersectionPoints pointSercher = new IntersectionPoints();

            int k = 0;

            for (int j = 1; j < polygonPoints.Length; j++)
            {
                points[k]   = polygonPoints[j - 1];
                isInside[k] = BuildPolygon.isPointInsidePolygon(clippingPoints, clippingPoints.Length, points[k].x, points[k].y);
                k++;
                for (int i = 1; i < 4; i++)
                {
                    if (pointSercher.IsSegmentsIntersect(clippingPoints[i - 1], clippingPoints[i], polygonPoints[j], polygonPoints[j - 1]))
                    {
                        isOutside = !(isOutside);
                        length++;
                        Array.Resize(ref points, length);
                        Array.Resize(ref isInside, length);
                        points[k]   = pointSercher.crossingPoint;
                        isInside[k] = false;
                        k++;
                    }
                }

                if (pointSercher.IsSegmentsIntersect(clippingPoints[3], clippingPoints[0], polygonPoints[j], polygonPoints[j - 1]))
                {
                    isOutside = !(isOutside);
                    length++;
                    Array.Resize(ref points, length);
                    Array.Resize(ref isInside, length);
                    points[k]   = pointSercher.crossingPoint;
                    isInside[k] = false;
                    k++;
                }
            }

            points[k]   = polygonPoints[polygonPoints.Length - 1];
            isInside[k] = BuildPolygon.isPointInsidePolygon(clippingPoints, clippingPoints.Length, points[k].x, points[k].y);
            k++;
            for (int i = 1; i < 4; i++)
            {
                if (pointSercher.IsSegmentsIntersect(clippingPoints[i - 1], clippingPoints[i], polygonPoints[polygonPoints.Length - 1], polygonPoints[0]))
                {
                    length++;
                    Array.Resize(ref points, length);
                    Array.Resize(ref isInside, length);
                    points[k]   = pointSercher.crossingPoint;
                    isInside[k] = false;
                    k++;
                }
            }

            if (pointSercher.IsSegmentsIntersect(clippingPoints[3], clippingPoints[0], polygonPoints[polygonPoints.Length - 1], polygonPoints[0]))
            {
                length++;
                Array.Resize(ref points, length);
                Array.Resize(ref isInside, length);
                points[k]   = pointSercher.crossingPoint;
                isInside[k] = false;
                k++;
            }

            if (isRectangle)
            {
                animParams.RectInsideClipWindow = isInside;
            }
            else
            {
                animParams.CiclInsideClipWindow = isInside;
            }
            return(points);
        }