コード例 #1
0
ファイル: Camera.cs プロジェクト: OptimShi/ACViewer
        public void InitDungeon(R_Landblock landblock, Model.BoundingBox box)
        {
            var size = box.Size;

            var center = box.Center;

            // draw a view plane from NW to SE
            var p1 = new Vector3(box.Mins.X, box.Maxs.Y, center.Z);
            var p2 = new Vector3(box.Maxs.X, box.Mins.Y, center.Z);

            var length = Vector3.Distance(p1, p2);

            var unit_length = (float)Math.Sqrt(length * length / 2);

            var dist_scalar = 0.75f;

            unit_length *= dist_scalar;

            // move camera out in -x, -y by this distance
            var position = center;

            position.X -= unit_length;
            position.Y -= unit_length;
            position.Z += unit_length;

            Position = position;

            Dir = Vector3.Normalize(box.Center - Position);

            Up    = Vector3.UnitZ;
            Speed = World_Speed;

            CreateLookAt();
        }
コード例 #2
0
ファイル: Camera.cs プロジェクト: OptimShi/ACViewer
        public void InitTeleport(R_Landblock landblock, float zBump)
        {
            var origin      = Teleport.Origin;
            var orientation = Teleport.Orientation;

            var lbx = landblock.Landblock.ID >> 24;
            var lby = landblock.Landblock.ID >> 16 & 0xFF;

            Position = new Vector3(lbx * 192.0f + origin.X, lby * 192.0f + origin.Y, origin.Z + zBump);

            Dir = Vector3.Normalize(Vector3.Transform(Vector3.UnitY, Matrix.CreateFromQuaternion(orientation.ToXna())));

            Up = Vector3.UnitZ;

            Speed = World_Speed;

            CreateLookAt();
        }
コード例 #3
0
ファイル: Camera.cs プロジェクト: OptimShi/ACViewer
        public void InitLandblock(R_Landblock landblock)
        {
            var x = landblock.Landblock.ID >> 24;
            var y = landblock.Landblock.ID >> 16 & 0xFF;

            var height = landblock.Landblock.Polygons[0].Vertices[0].Origin.Z;

            Position = new Vector3(x * 192.0f, y * 192.0f, height + 50.0f);

            var lookAt = new Vector3(x * 192.0f + 96.0f, y * 192.0f + 96.0f, height);

            Dir = Vector3.Normalize(lookAt - Position);

            Up = Vector3.UnitZ;

            Speed = World_Speed;

            CreateLookAt();
        }
コード例 #4
0
ファイル: WorldViewer.cs プロジェクト: OptimShi/ACViewer
        public void LoadLandblock(uint landblockID, uint radius = 1)
        {
            if (PlayerMode)
            {
                ExitPlayerMode();
                InitPlayerMode = true;
            }

            Render.Buffer.ClearBuffer();
            Server.Init();
            TextureCache.Init();

            LScape.unload_landblocks_all();

            var landblock = LScape.get_landblock(landblockID);

            if (landblock.HasDungeon)
            {
                radius = 0;
            }

            DungeonMode = landblock.HasDungeon;

            var center_lbx = landblockID >> 24;
            var center_lby = landblockID >> 16 & 0xFF;

            //Landblocks = new Dictionary<uint, R_Landblock>();
            R_Landblock r_landblock = null;
            R_Landblock centerBlock = null;

            for (var lbx = (int)(center_lbx - radius); lbx <= center_lbx + radius; lbx++)
            {
                if (lbx < 0 || lbx > 254)
                {
                    continue;
                }

                for (var lby = (int)(center_lby - radius); lby <= center_lby + radius; lby++)
                {
                    if (lby < 0 || lby > 254)
                    {
                        continue;
                    }

                    var lbid = (uint)(lbx << 24 | lby << 16 | 0xFFFF);

                    var timer = Stopwatch.StartNew();
                    landblock = LScape.get_landblock(lbid);
                    timer.Stop();

                    r_landblock = new R_Landblock(landblock);
                    //LScape.unload_landblock(lbid);

                    if (landblockID == lbid)
                    {
                        centerBlock = r_landblock;
                    }

                    MainWindow.Status.WriteLine($"Loaded {lbid:X8} in {timer.Elapsed.TotalMilliseconds}ms");

                    //Landblocks.Add(lbid, new R_Landblock(landblock));
                }
            }

            Render.Buffer.BuildBuffers();
            Render.InitEmitters();

            if (FileExplorer.Instance.TeleportMode)
            {
                var zBump = DungeonMode ? 1.775f : 2.775f;

                if (InitPlayerMode)
                {
                    zBump = 0.0f;
                }

                Camera.InitTeleport(centerBlock, zBump);
                FileExplorer.Instance.TeleportMode = false;
            }
            else if (DungeonMode)
            {
                BoundingBox = new Model.BoundingBox(Render.Buffer.RB_EnvCell);
                Camera.InitDungeon(r_landblock, BoundingBox);
            }
            else
            {
                Camera.InitLandblock(r_landblock);
            }

            SingleBlock = landblock.ID;

            FreeResources();

            Server.OnLoadWorld();
        }
コード例 #5
0
ファイル: WorldViewer.cs プロジェクト: OptimShi/ACViewer
        public async void LoadLandblocks(Vector2 startBlock, Vector2 endBlock)
        {
            //Console.WriteLine($"LoadLandblocks({startBlock}, {endBlock})");
            if (PlayerMode)
            {
                ExitPlayerMode();
                InitPlayerMode = true;
            }

            Render.Buffer.ClearBuffer();
            Server.Init();
            TextureCache.Init();

            LScape.unload_landblocks_all();

            DungeonMode = false;

            var dx        = (int)(endBlock.X - startBlock.X) + 1;
            var dy        = (int)(startBlock.Y - endBlock.Y) + 1;
            var numBlocks = dx * dy;

            var size        = endBlock - startBlock;
            var center      = startBlock + size / 2;
            var centerX     = (uint)Math.Round(center.X);
            var centerY     = (uint)Math.Round(center.Y);
            var landblockID = centerX << 24 | centerY << 16 | 0xFFFF;

            MainWindow.Status.WriteLine($"Loading {numBlocks} landblocks");
            await Task.Delay(1);

            //Landblocks = new Dictionary<uint, R_Landblock>();
            R_Landblock r_landblock = null;
            R_Landblock centerBlock = null;

            for (var lbx = (uint)startBlock.X; lbx <= endBlock.X; lbx++)
            {
                if (lbx < 0 || lbx > 254)
                {
                    continue;
                }

                for (var lby = (uint)endBlock.Y; lby <= startBlock.Y; lby++)
                {
                    if (lby < 0 || lby > 254)
                    {
                        continue;
                    }

                    var lbid = lbx << 24 | lby << 16 | 0xFFFF;

                    var timer     = Stopwatch.StartNew();
                    var landblock = LScape.get_landblock(lbid);
                    timer.Stop();

                    r_landblock = new R_Landblock(landblock);
                    //LScape.unload_landblock(lbid);

                    if (lbid == landblockID)
                    {
                        centerBlock = r_landblock;
                    }

                    MainWindow.Status.WriteLine($"Loaded {lbid:X8} in {timer.Elapsed.TotalMilliseconds}ms");

                    //Landblocks.Add(lbid, new R_Landblock(landblock));
                }
            }

            Render.Buffer.BuildBuffers();
            Render.InitEmitters();

            Camera.InitLandblock(centerBlock);
            GameView.ViewMode = ViewMode.World;

            SingleBlock = uint.MaxValue;

            FreeResources();

            Server.OnLoadWorld();
        }