Esempio n. 1
0
        void Render3D(double delta, float t)
        {
            if (SkyboxRenderer.ShouldRender)
            {
                SkyboxRenderer.Render(delta);
            }
            AxisLinesRenderer.Render(delta);
            Entities.RenderModels(Graphics, delta, t);
            Entities.RenderNames(Graphics, delta);

            ParticleManager.Render(delta, t);
            Camera.GetPickedBlock(SelectedPos);             // TODO: only pick when necessary
            EnvRenderer.Render(delta);
            MapRenderer.Update(delta);
            MapRenderer.RenderNormal(delta);
            MapBordersRenderer.RenderSides(delta);

            if (SelectedPos.Valid && !HideGui)
            {
                Picking.UpdateState(SelectedPos);
                Picking.Render(delta);
            }

            // Render water over translucent blocks when underwater for proper alpha blending
            Vector3 pos = LocalPlayer.Position;

            if (CurrentCameraPos.Y < World.Env.EdgeHeight &&
                (pos.X < 0 || pos.Z < 0 || pos.X > World.Width || pos.Z > World.Length))
            {
                MapRenderer.RenderTranslucent(delta);
                MapBordersRenderer.RenderEdges(delta);
            }
            else
            {
                MapBordersRenderer.RenderEdges(delta);
                MapRenderer.RenderTranslucent(delta);
            }

            // Need to render again over top of translucent block, as the selection outline
            // is drawn without writing to the depth buffer
            if (SelectedPos.Valid && !HideGui &&
                BlockInfo.Draw[SelectedPos.Block] == DrawType.Translucent)
            {
                Picking.Render(delta);
            }

            Entities.DrawShadows();
            SelectionManager.Render(delta);
            Entities.RenderHoveredNames(Graphics, delta);

            bool left   = IsMousePressed(MouseButton.Left);
            bool middle = IsMousePressed(MouseButton.Middle);
            bool right  = IsMousePressed(MouseButton.Right);

            Input.PickBlocks(true, left, middle, right);
            if (!HideGui)
            {
                HeldBlockRenderer.Render(delta);
            }
        }
Esempio n. 2
0
        public override Vector3 GetCameraPos(Vector3 eyePos)
        {
            Vector3 dir = Utils.GetDirVector(player.YawRadians, player.PitchRadians);

            Picking.ClipCameraPos(game, eyePos, dir, distance, game.CameraClipPos);
            return(game.CameraClipPos.IntersectPoint);
        }
Esempio n. 3
0
        public override void GetPickedBlock(PickedPos pos)
        {
            Vector3 eyePos = player.EyePosition;
            Vector3 dir    = Utils.GetDirVector(player.HeadYRadians, player.HeadXRadians);
            float   reach  = game.LocalPlayer.ReachDistance;

            Picking.CalculatePickedBlock(game, eyePos, dir, reach, pos);
        }
Esempio n. 4
0
        public override Vector3 GetCameraPos(Vector3 eyePos)
        {
            Vector3 dir = Utils.GetDirVector(player.HeadYawRadians,
                                             AdjustPitch(player.PitchDegrees));

            Picking.ClipCameraPos(game, eyePos, dir, dist, game.CameraClipPos);
            return(game.CameraClipPos.IntersectPoint);
        }
Esempio n. 5
0
        public override void GetPickedBlock(PickedPos pos)
        {
            Vector3 dir = GetDirVector();
            Vector3 eyePos = player.EyePosition;
            int     adjCamX, adjCamZ;

            GetCamChunk(out adjCamX, out adjCamZ);
            eyePos.X -= adjCamX;
            eyePos.Z -= adjCamZ;
            float reach = game.LocalPlayer.ReachDistance;

            Picking.CalculatePickedBlock(game, eyePos, dir, reach, pos);
        }
Esempio n. 6
0
        public override Matrix4 GetView(double delta)
        {
            CalcViewBobbing(delta);
            Vector3 eyePos = player.EyePosition;

            eyePos.Y += bobYOffset;

            Vector3 dir = Utils.GetDirVector(player.YawRadians, player.PitchRadians);

            Picking.ClipCameraPos(game, eyePos, dir, distance, game.CameraClipPos);
            Vector3 cameraPos = game.CameraClipPos.IntersectPoint;

            return(Matrix4.LookAt(cameraPos, eyePos, Vector3.UnitY) * tiltMatrix);
        }
Esempio n. 7
0
        public override Vector3 GetPosition(float t)
        {
            CalcViewBobbing(t, dist);
            Vector3 target = player.EyePosition;

            target.Y += bobbingVer;

            // cast ray from player position to camera position
            // this way we can stop if we hit a block in the way
            Vector2 rot = GetOrientation();
            Vector3 dir = -Utils.GetDirVector(rot.X, rot.Y);

            Picking.ClipCameraPos(game, target, dir, dist, game.CameraClipPos);
            return(game.CameraClipPos.Intersect);
        }
Esempio n. 8
0
        public override Vector3 GetCameraPos(float t)
        {
            CalcViewBobbing(t, dist);
            Vector3 eyePos = player.EyePosition;

            eyePos.Y += bobbingVer;

            Vector3 dir = GetDirVector();

            if (!forward)
            {
                dir = -dir;
            }
            Picking.ClipCameraPos(game, eyePos, dir, dist, game.CameraClipPos);
            return(game.CameraClipPos.Intersect);
        }
Esempio n. 9
0
        public override void Dispose()
        {
            MapRenderer.Dispose();
            MapBordersRenderer.Dispose();
            EnvRenderer.Dispose();
            WeatherRenderer.Dispose();
            SetNewScreen(null);
            fpsScreen.Dispose();
            SelectionManager.Dispose();
            TerrainAtlas.Dispose();
            TerrainAtlas1D.Dispose();
            ModelCache.Dispose();
            Picking.Dispose();
            ParticleManager.Dispose();
            Players.Dispose();
            AsyncDownloader.Dispose();
            AudioPlayer.Dispose();
            AxisLinesRenderer.Dispose();

            Chat.Dispose();
            if (activeScreen != null)
            {
                activeScreen.Dispose();
            }
            Graphics.DeleteIb(defaultIb);
            Graphics.Dispose();
            Drawer2D.DisposeInstance();
            Animations.Dispose();
            Graphics.DeleteTexture(ref CloudsTexId);
            Graphics.DeleteTexture(ref RainTexId);
            Graphics.DeleteTexture(ref SnowTexId);
            Graphics.DeleteTexture(ref GuiTexId);
            Graphics.DeleteTexture(ref GuiClassicTexId);

            if (Options.HasChanged)
            {
                Options.Save();
            }
            base.Dispose();
        }
Esempio n. 10
0
        void Render3D(double delta, float t)
        {
            CurrentCameraPos = Camera.GetCameraPos(LocalPlayer.EyePosition);
            if (SkyboxRenderer.ShouldRender)
            {
                SkyboxRenderer.Render(delta);
            }
            AxisLinesRenderer.Render(delta);
            Entities.RenderModels(Graphics, delta, t);
            Entities.RenderNames(Graphics, delta, t);

            ParticleManager.Render(delta, t);
            Camera.GetPickedBlock(SelectedPos);               // TODO: only pick when necessary
            EnvRenderer.Render(delta);
            MapRenderer.Render(delta);
            MapBordersRenderer.RenderSides(delta);

            if (SelectedPos.Valid && !HideGui)
            {
                Picking.Render(delta, SelectedPos);
            }
            MapBordersRenderer.RenderEdges(delta);
            MapRenderer.RenderTranslucent(delta);

            Entities.DrawShadows();
            SelectionManager.Render(delta);
            Entities.RenderHoveredNames(Graphics, delta, t);

            bool left   = IsMousePressed(MouseButton.Left);
            bool middle = IsMousePressed(MouseButton.Middle);
            bool right  = IsMousePressed(MouseButton.Right);

            InputHandler.PickBlocks(true, left, middle, right);
            if (!HideGui)
            {
                BlockHandRenderer.Render(delta, t);
            }
        }
Esempio n. 11
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            PerformFpsElapsed(e.Time * 1000);
            Graphics.BeginFrame(this);
            Graphics.BindIb(defaultIb);
            accumulator += e.Time;
            Vertices     = 0;
            if (!Focused && !ScreenLockedInput)
            {
                SetNewScreen(new PauseScreen(this));
            }

            base.OnRenderFrame(e);
            CheckScheduledTasks(e.Time);
            float t = (float)(ticksAccumulator / ticksPeriod);

            LocalPlayer.SetInterpPosition(t);

            Graphics.Clear();
            Graphics.SetMatrixMode(MatrixType.Modelview);
            Matrix4 modelView = Camera.GetView(e.Time);

            View = modelView;
            Graphics.LoadMatrix(ref modelView);
            Culling.CalcFrustumEquations(ref Projection, ref modelView);

            bool visible = activeScreen == null || !activeScreen.BlocksWorld;

            if (visible)
            {
                AxisLinesRenderer.Render(e.Time);
                Players.RenderModels(Graphics, e.Time, t);
                Players.RenderNames(Graphics, e.Time, t);
                CurrentCameraPos = Camera.GetCameraPos(LocalPlayer.EyePosition);

                ParticleManager.Render(e.Time, t);
                Camera.GetPickedBlock(SelectedPos);                   // TODO: only pick when necessary
                EnvRenderer.Render(e.Time);
                if (SelectedPos.Valid && !HideGui)
                {
                    Picking.Render(e.Time, SelectedPos);
                }
                MapRenderer.Render(e.Time);
                SelectionManager.Render(e.Time);
                WeatherRenderer.Render(e.Time);
                Players.RenderHoveredNames(Graphics, e.Time, t);

                bool left   = IsMousePressed(MouseButton.Left);
                bool middle = IsMousePressed(MouseButton.Middle);
                bool right  = IsMousePressed(MouseButton.Right);
                InputHandler.PickBlocks(true, left, middle, right);
                if (!HideGui)
                {
                    BlockHandRenderer.Render(e.Time, t);
                }
            }
            else
            {
                SelectedPos.SetAsInvalid();
            }

            Graphics.Mode2D(Width, Height, EnvRenderer is StandardEnvRenderer);
            fpsScreen.Render(e.Time);
            if (activeScreen == null || !activeScreen.HidesHud)
            {
                hudScreen.Render(e.Time);
            }
            if (activeScreen != null)
            {
                activeScreen.Render(e.Time);
            }
            Graphics.Mode3D(EnvRenderer is StandardEnvRenderer);

            if (screenshotRequested)
            {
                TakeScreenshot();
            }
            Graphics.EndFrame(this);
        }