Exemple #1
0
        public void UpdateMouseTerrainPos(int x, int y)
        {
            System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
            pt = mRenderWindow.PointToClient(pt);

            Vector3 screenCoord = new Vector3();

            screenCoord.X = (((2.0f * pt.X) / Device.Viewport.Width) - 1);
            screenCoord.Y = -(((2.0f * pt.Y) / Device.Viewport.Height) - 1);

            var invProj = Matrix.Invert(Device.GetTransform(TransformState.Projection));
            var invView = Matrix.Invert(Device.GetTransform(TransformState.View));

            var nearPos = new Vector3(screenCoord.X, screenCoord.Y, 0);
            var farPos  = new Vector3(screenCoord.X, screenCoord.Y, 1);

            nearPos = Vector3.TransformCoordinate(nearPos, invProj * invView);
            farPos  = Vector3.TransformCoordinate(farPos, invProj * invView);

            Ray   ray      = new Ray(nearPos, Vector3.Normalize((farPos - nearPos)));
            float distance = 0;

            ADT.IADTChunk hitChunk = null;
            bool          hit      = ADT.ADTManager.Intersect(ray, ref distance, out hitChunk);

            ShaderCollection.TerrainShader.SetValue("DrawMouse", hit);
            if (hit)
            {
                ShaderCollection.TerrainShader.SetValue("MousePosition", ray.Position + distance * ray.Direction);
                MousePosition = ray.Position + distance * ray.Direction;
                Game.GameManager.WorldManager.MouseHoverChunk = hitChunk;
            }
            else
            {
                Game.GameManager.WorldManager.MouseHoverChunk = null;
                MousePosition = new Vector3(999999, 999999, 999999);
            }
        }
Exemple #2
0
        public void Update(Video.ICamera cam)
        {
            if (isInWorld == false)
                return;

            var pos = cam.Position;
            pos.X = Utils.Metrics.MidPoint + pos.X;
            pos.Y = Utils.Metrics.MidPoint + pos.Y;
            int myX = (int)(pos.X / Utils.Metrics.Tilesize);
            int myY = (int)(pos.Y / Utils.Metrics.Tilesize);

            var qry = from file in mFiles
                      where (
                      file.IndexX > myX + 1 ||
                      file.IndexX < myX - 1 ||
                      file.IndexY > myY + 1 ||
                      file.IndexY < myY - 1
                      )
                      select file;

            foreach (var old in qry)
            {
                old.Unload();
            }

            mFiles.RemoveAll((ADT.IADTFile af) => { return qry.Contains(af); });

            uint indexValue = 0;
            List<uint> indices = new List<uint>();
            for (int i = -1; i < 2; ++i)
            {
                for (int j = -1; j < 2; ++j)
                {
                    if (myX + j < 0 || myY + i < 0)
                        continue;

                    indexValue = ((uint)(myX + j)) * 1000 + ((uint)(myY + i));
                    indices.Add(indexValue);
                }
            }

            var sel = from index in indices
                      where (mFiles.Exists((ADT.IADTFile file) =>
                          {
                              var adtIndex = file.IndexX * 1000 + file.IndexY;
                              return adtIndex == index;
                          }
                      ) == false)
                      select index;

            foreach (var index in sel)
            {
                uint ix = index / 1000;
                uint iy = index % 1000;
                var str = @"World\Maps\" + mContinent + "\\" + mContinent + "_" + ix + "_" + iy + ".adt";
                ADT.IADTFile file = ADT.ADTManager.CreateADT(mWdtManager.getWDT(mContinent), str, ix, iy);
                file.Continent = mContinent;
                if (file != null)
                    mFiles.Add(file);
            }

            var curTile = GetCurrentTile();
            if (curTile != mHoveredTile)
            {
                mHoveredTile = curTile;
                Game.GameManager.InformPropertyChanged(GameProperties.HoveredADT);
            }
            var curChunk = GetCurrentChunk();
            if (curChunk != mHoveredChunk)
            {
                mHoveredChunk = curChunk;
                Game.GameManager.InformPropertyChanged(GameProperties.HoveredChunk);
            }
        }