Ejemplo n.º 1
0
        private void Map_MouseMove(object sender, MouseEventArgs e)
        {
            /* if you can drag, then drag
             * when draging, capture the relative position of the mouse to the map image
             * set the position of the map image to the position of the mouse
             */
            if (MapInfo.DoesDrag && MapInfo.CanDrag)
            {
                MapInfo.position = MapInfo.OldPos + ((Vec)e.GetPosition(Map) - new Vec(100, 100) - MapInfo.OldMousPos);

                if (MapInfo.position.X < -128)
                {
                    MapInfo.OldPos.X   += 256;
                    MapInfo.chunkPos.X += 1;
                    MapInfo.Update();
                }
                if (MapInfo.position.X > 128)
                {
                    MapInfo.OldPos.X   -= 256;
                    MapInfo.chunkPos.X -= 1;
                    MapInfo.Update();
                }

                if (MapInfo.position.Y < -128)
                {
                    MapInfo.OldPos.Y   += 256;
                    MapInfo.chunkPos.Y += 1;
                    MapInfo.Update();
                }
                if (MapInfo.position.Y > 128)
                {
                    MapInfo.OldPos.Y   -= 256;
                    MapInfo.chunkPos.Y -= 1;
                    MapInfo.Update();
                }

                var nx = (MapInfo.position.X + 256 + 128) % 256;
                var ny = (MapInfo.position.Y + 256 + 128) % 256;

                nx = 255 - nx;
                ny = 255 - ny;

                CurrBID = MapInfo.BIDSource[(int)nx, (int)ny];

                Canvas.SetLeft(Chunks, MapInfo.position.X - MapInfo.origin.X);
                Canvas.SetTop(Chunks, MapInfo.position.Y - MapInfo.origin.Y);

                Utils.Vec deltaPos = (Utils.Vec)e.GetPosition(Map) - oldDeltaPos;

                BiomeEventData.Distance += Math.Sqrt(deltaPos | deltaPos);

                Time.Delta = (uint)(Math.Sqrt(deltaPos | deltaPos) * MapInfo.PixelTime);

                Update();

                BiomeEventList.BiomeList[CurrBID].Load();

                oldDeltaPos = (Utils.Vec)e.GetPosition(Map);
            }
        }
Ejemplo n.º 2
0
        private void Map_MouseDown(object sender, MouseButtonEventArgs e)
        {
            oldDeltaPos = (Utils.Vec)e.GetPosition(Map);

            MapInfo.OldMousPos = (Vec)e.GetPosition(Map) - new Vec(100, 100);
            MapInfo.OldPos     = MapInfo.position;
            MapInfo.DoesDrag   = true;
        }
Ejemplo n.º 3
0
        public static void Draw()
        {
            var dvel = Math.PI * 2 / (Hpd * Time.Hour);
            var yvel = Math.PI * 2 / (Dpy * Hpd * Time.Hour);

            var insvel = yvel / (1 - Eccentricity * Math.Cos(yvel * Time.T));             //Deppricated code, this doesn't work the way I need it to. Eccentricity will likely need to be passed through an integral in order to get the proper function to shift the sun's position correctly due to eccentricity

            var dpos = dvel * Time.T;
            var ypos = yvel * Time.T;

            var ntilt = Utils.Quat.Rot(Tilt, new Utils.Vec3(1, 0, 0));                                                                                  //stores a rotation bassed off of the axial tilt

            ntilt = ntilt ^ Utils.Quat.Rot(ypos, new Utils.Vec3(0, 1, 0));                                                                              //rotates the rotation bassed off of the orbital position

            var nrpos = Rpos ^ ntilt;                                                                                                                   //offsets the position given the current latitude

            var npos = nrpos ^ Utils.Quat.Rot(dpos, new Utils.Vec3(0, -1, 0)) ^ Utils.Quat.Rot(Latitude, (Utils.Vec3)(Rpos) * new Utils.Vec3(0, 1, 0)); //Rotates the sun around proper axis throught the day

            var v3 = (Utils.Vec3)npos;                                                                                                                  //casting the quaterneon to a vector
            var p3 = (Utils.Pol3)v3;                                                                                                                    //casting the vector to a polar 3
            var p  = (Utils.Pol)p3;                                                                                                                     //this colapses the polar3 down to a polar2 to display current heading and altitude

            Pos = !p * (200 / Math.PI);                                                                                                                 //make the sun draw at the correct place on the canvas

            Circle.Width  = Radius * 2;
            Circle.Height = Radius * 2;

            //ternary would simplify it to Circle.Stroke = (Pos | Pos) > Math.Pow(100 + Radius, 2) ? Brushes.Transparent : Brushes.White;
            if ((Pos | Pos) > Math.Pow(100 + Radius, 2)) //only display the sun if it is actually above the horizon
            {
                Circle.Stroke = System.Windows.Media.Brushes.Transparent;
                Circle.Fill   = System.Windows.Media.Brushes.Transparent;
                Horizon.Fill  = new SolidColorBrush(System.Windows.Media.Color.FromRgb(20, 20, 30));
            }
            else
            {
                Circle.Stroke = System.Windows.Media.Brushes.White;
                Circle.Fill   = System.Windows.Media.Brushes.White;
                Horizon.Fill  = new SolidColorBrush(System.Windows.Media.Color.FromRgb(40, 40, 100));
            }
            Circle.StrokeThickness = 3;
            Circle.SetValue(Canvas.LeftProperty, (Pos + Origin).X - Radius);
            Circle.SetValue(Canvas.TopProperty, (Pos + Origin).Y - Radius);
        }