示例#1
0
        public override void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            ViewScreenPos = matrix.Transform(WorldPosition.X, WorldPosition.Y);//sets the zoom position.
            var camerapoint = camera.CameraViewCoordinate();

            _drawPoints = new SDL.SDL_Point[2];


            /*
             * var translated = matrix.Transform(_translateStartPoint.X, _translateStartPoint.Y);
             * int x = (int)(ViewScreenPos.x + translated.x + camerapoint.x);
             * int y = (int)(ViewScreenPos.y + translated.y + camerapoint.y);
             * _drawPoints[0] = new SDL.SDL_Point() { x = x, y = y };
             */

            var translated = matrix.Transform(_currentPosition.X, _currentPosition.Y);
            int x          = (int)(ViewScreenPos.x + translated.x + camerapoint.x);
            int y          = (int)(ViewScreenPos.y + translated.y + camerapoint.y);

            _drawPoints[0] = new SDL.SDL_Point()
            {
                x = x, y = y
            };

            translated     = matrix.Transform(_translateEndPoint.X, _translateEndPoint.Y);
            x              = (int)(ViewScreenPos.x + translated.x + camerapoint.x);
            y              = (int)(ViewScreenPos.y + translated.y + camerapoint.y);
            _drawPoints[1] = new SDL.SDL_Point()
            {
                x = x, y = y
            };
        }
示例#2
0
        public void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            _departIcon.OnFrameUpdate(matrix, camera);
            if (_arriveIcon != null)
            {
                _arriveIcon.OnFrameUpdate(matrix, camera);

                var camerapoint = camera.CameraViewCoordinate();

                _linePoints = new SDL_Point[2];

                var depart = matrix.Transform(_departIcon.WorldPosition.X, _departIcon.WorldPosition.Y);
                _linePoints[0] = new SDL_Point()
                {
                    x = (depart.x + camerapoint.x),
                    y = (depart.y + camerapoint.y)
                };

                var arrive = matrix.Transform(_arriveIcon.WorldPosition.X, _arriveIcon.WorldPosition.Y);
                _linePoints[1] = new SDL_Point()
                {
                    x = (arrive.x + camerapoint.x),
                    y = (arrive.y + camerapoint.y)
                };
            }
        }
示例#3
0
        public override void Draw(IntPtr rendererPtr, Camera camera)
        {
            PhysicsUpdate();
            base.Draw(rendererPtr, camera);
            byte oR, oG, oB, oA;

            SDL.SDL_GetRenderDrawColor(rendererPtr, out oR, out oG, out oB, out oA);
            SDL.SDL_BlendMode blendMode;
            SDL.SDL_GetRenderDrawBlendMode(rendererPtr, out blendMode);
            SDL.SDL_SetRenderDrawBlendMode(rendererPtr, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);


            //get matrix transformations for zoom
            Matrix matrix = new Matrix();

            matrix.Scale(camera.ZoomLevel);

            int index            = _index;
            var camerapoint      = camera.CameraViewCoordinate();
            var translatedPoints = new SDL.SDL_Point[_numberOfDrawSegments];

            for (int i = 0; i < _numberOfDrawSegments; i++)
            {
                if (index < _numberOfArcSegments - 1)
                {
                    index++;
                }
                else
                {
                    index = 0;
                }

                var translated = matrix.Transform(_points[index].x, _points[index].y); //add zoom transformation.

                //translate everything to viewscreen & camera positions
                int x = (int)(ViewScreenPos.x + translated.x + camerapoint.x);
                int y = (int)(ViewScreenPos.y + translated.y + camerapoint.y);

                translatedPoints[i] = new SDL.SDL_Point()
                {
                    x = x, y = y
                };
            }

            //now we draw a line between each of the points in the translatedPoints[] array.
            float alpha = MaxAlpha;

            for (int i = 0; i < _numberOfDrawSegments - 1; i++)
            {
                SDL.SDL_SetRenderDrawColor(rendererPtr, Red, Grn, Blu, (byte)alpha);//we cast the alpha here to stop rounding errors creaping up.
                SDL.SDL_RenderDrawLine(rendererPtr, translatedPoints[i].x, translatedPoints[i].y, translatedPoints[i + 1].x, translatedPoints[i + 1].y);
                alpha -= _alphaChangeAmount;
            }
            SDL.SDL_SetRenderDrawColor(rendererPtr, oR, oG, oB, oA);
            SDL.SDL_SetRenderDrawBlendMode(rendererPtr, blendMode);
        }
示例#4
0
        public override void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            CreatePointArray();
            ViewScreenPos = matrix.Transform(WorldPosition.X, WorldPosition.Y);//sets the zoom position.


            _soiViewRadius = camera.ViewDistance(_soiWorldRadius);

            int index       = _index;
            var camerapoint = camera.CameraViewCoordinate();
            //ViewScreenPos += camerapoint;

            var vsp = new SDL.SDL_Point()
            {
                x = ViewScreenPos.x + camerapoint.x,
                y = ViewScreenPos.y + camerapoint.y
            };

            ViewScreenPos = vsp;
            PointD translated;

            _drawPoints = new SDL.SDL_Point[_numberOfDrawSegments];
            for (int i = 0; i < _numberOfDrawSegments; i++)
            {
                if (IsClockwiseOrbit)
                {
                    if (index < _numberOfArcSegments - 1)
                    {
                        index++;
                    }
                    else
                    {
                        index = 0;
                    }
                }
                else if (index > 0)
                {
                    index--;
                }
                else
                {
                    index = _numberOfArcSegments - 1;
                }

                translated = matrix.TransformD(_points[index].X, _points[index].Y); //add zoom transformation.

                int x = (int)(ViewScreenPos.x + translated.X);
                int y = (int)(ViewScreenPos.y + translated.Y);

                _drawPoints[i] = new SDL.SDL_Point()
                {
                    x = x, y = y
                };
            }
        }
示例#5
0
        public virtual void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            var camerapoint = camera.CameraViewCoordinate();

            ViewScreenPos = matrix.Transform(WorldPosition.X, WorldPosition.Y);

            //matrix.Translate(WorldPosition.X + camerapoint.x, WorldPosition.Y + camerapoint.y);

            //todo: proper matrix transformations might clean this code up a bit. I'm failing to get it working properly though.
            //Matrix matrix2 = new Matrix();
            //matrix2.Translate(WorldPosition.X, WorldPosition.Y);
            //matrix2.Scale(camera.ZoomLevel);
            //matrix2.Translate(camerapoint.x, camerapoint.y);


            float zoomLevel = 1;

            if (ShapesScaleWithZoom)
            {
                zoomLevel = camera.ZoomLevel;
            }
            DrawShapes = new Shape[this.Shapes.Count];
            for (int i = 0; i < Shapes.Count; i++)
            {
                var      shape      = Shapes[i];
                PointD[] drawPoints = new PointD[shape.Points.Length];//matrix.Transform(shape.Points);
                for (int i2 = 0; i2 < shape.Points.Length; i2++)
                {
                    int x = (int)(ViewScreenPos.x + (shape.Points[i2].X + camerapoint.x) * zoomLevel);
                    int y = (int)(ViewScreenPos.y + (shape.Points[i2].Y + camerapoint.y) * zoomLevel);

                    //SDL.SDL_Point pnt = matrix2.Transform(shape.Points[i2].x, shape.Points[i2].y);
                    //int x1 = (int)(pnt.x * zoomLevel);
                    //int y1 = (int)(pnt.y * zoomLevel);
                    drawPoints[i2] = new PointD()
                    {
                        X = x, Y = y
                    };
                }
                DrawShapes[i] = (new Shape()
                {
                    Points = drawPoints, Color = shape.Color
                });
            }
        }
示例#6
0
        public override void Draw(IntPtr rendererPtr, Camera camera)
        {
            var    camerapoint = camera.CameraViewCoordinate();
            int    x           = (int)(X + camerapoint.x + ViewOffset.x);
            int    y           = (int)(Y + camerapoint.y + ViewOffset.y);
            ImVec2 pos         = new ImVec2(x, y);

            ImGui.PushStyleColor(ImGuiCol.WindowBg, new ImVec4(0, 0, 0, 0)); //make the background transperent.
            ImGui.SetNextWindowPos(pos, ImGuiCond.Always);


            ImGui.Begin(NameString, ref IsActive, _flags);

            ImGui.PushStyleColor(ImGuiCol.Button, new ImVec4(0, 0, 0, 0));
            if (ImGui.Button(NameString)) //If the name gets clicked, we tell the state.
            {
                _state.EntityClicked(_entityGuid, MouseButtons.Primary);
            }
            var size = ImGui.GetLastItemRectSize();

            Height = size.y;
            Width  = size.x;
            ViewDisplayRect.Width  = size.x;
            ViewDisplayRect.Height = size.y;

            ImGui.PopStyleColor();
            if (ImGui.BeginPopupContextItem("NameContextMenu", 1))
            {
                _state.EntityClicked(_entityGuid, MouseButtons.Alt);
                _state.ContextMenu = new EntityContextMenu(_state, _entityGuid);
                _state.ContextMenu.Display();

                ImGui.EndPopup();
            }



            ImGui.End();
            ImGui.PopStyleColor(); //have to pop the color change after pushing it.
        }
示例#7
0
        public override void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            ViewScreenPos = matrix.Transform(WorldPosition.X, WorldPosition.Y);//sets the zoom position.


            //get matrix transformations for zoom
            //Matrix matrix2 = new Matrix();
            //matrix2.Scale(camera.ZoomLevel);

            int index       = _index;
            var camerapoint = camera.CameraViewCoordinate();

            var vsp = new SDL.SDL_Point()
            {
                x = ViewScreenPos.x + camerapoint.x,
                y = ViewScreenPos.y + camerapoint.y
            };

            ViewScreenPos = vsp;

            _drawPoints = new SDL.SDL_Point[_numberOfDrawSegments];

            //first index in the drawPoints is the position of the body
            var translated = matrix.TransformD(_bodyRalitivePos.X, _bodyRalitivePos.Y);

            _drawPoints[0] = new SDL.SDL_Point()
            {
                x = (int)(ViewScreenPos.x + translated.X), y = (int)(ViewScreenPos.y + translated.Y)
            };



            for (int i = 1; i < _numberOfDrawSegments; i++)
            {
                if (IsClockwiseOrbit)
                {
                    if (index < _numberOfArcSegments - 1)
                    {
                        index++;
                    }
                    else
                    {
                        index = 0;
                    }
                }
                else if (index > 0)
                {
                    index--;
                }
                else
                {
                    index = _numberOfArcSegments - 1;
                }

                translated = matrix.TransformD(_points[index].X, _points[index].Y); //add zoom transformation.

                //translate everything to viewscreen & camera positions
                //int x = (int)(ViewScreenPos.x + translated.X + camerapoint.x);
                //int y = (int)(ViewScreenPos.y + translated.Y + camerapoint.y);
                int x = (int)(ViewScreenPos.x + translated.X);
                int y = (int)(ViewScreenPos.y + translated.Y);

                _drawPoints[i] = new SDL.SDL_Point()
                {
                    x = x, y = y
                };
            }
        }