示例#1
0
        static void Main()
        {
            Scene scene = new Scene();
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            GameTime time = new GameTime();
            MessagePump.Run(scene.GraphicsEngine.Form, () =>
            {
                watch.Reset();
                watch.Start();

                int frameTime = 1;
                if (time.LastFrameElapsedTime.TotalMilliseconds < frameTime)
                    System.Threading.Thread.Sleep((int)(frameTime - time.LastFrameElapsedTime.TotalMilliseconds));
                scene.Update(time);
                scene.Draw();

                watch.Stop();
                time.LastFrameElapsedTime = watch.Elapsed;
                time.TotalGameTime = time.TotalGameTime + watch.Elapsed;

            });
            scene.Dispose();

            // TODO ce soir
            // frustrum culling pour la planète.
            // backface culling pour le ground.
            //
        }
示例#2
0
文件: Scene.cs 项目: crissian/planets
        /// <summary>
        /// Mets à jour la caméra contrôlée par la souris.
        /// </summary>
        /// <param name="time"></param>
        void UpdateMouseCamera(GameTime time)
        {
            /*
            float angleSpeed = 30;
            // Angle de la caméra.
            float delta = Math.Min(0.1f, 0.1f);
            Vector2 mouse = Input.GetMousePos();
            int centerX = Scene.Instance.ResolutionWidth / 2;
            int centerY = Scene.Instance.ResolutionHeight / 2;
            float cameraRotationX = -Microsoft.Xna.Framework.MathHelper.ToRadians((mouse.X - centerX) * angleSpeed * 0.01f);
            float cameraRotationY = Microsoft.Xna.Framework.MathHelper.ToRadians((mouse.Y - centerY) * angleSpeed * 0.01f);
            */
            if (Input.IsPressed(SlimDX.DirectInput.Key.LeftShift))
            {
                float speed = 0.030f * time.LastFrameElapsedTime.Milliseconds / 25.0f;
                if (Input.IsPressed(SlimDX.DirectInput.Key.A))
                    Camera.RotateSide(speed); //cameraRotationX * angleSpeed * delta);
                if (Input.IsPressed(SlimDX.DirectInput.Key.S))
                    Camera.RotateUpDown(-speed); //-cameraRotationY * angleSpeed * delta);
                if (Input.IsPressed(SlimDX.DirectInput.Key.D))
                    Camera.RotateSide(-speed);//cameraRotationX * angleSpeed * delta);
                if (Input.IsPressed(SlimDX.DirectInput.Key.W))
                    Camera.RotateUpDown(speed); //-cameraRotationY * angleSpeed * delta);
            }
            else
            {
                float speed = 0.0005f * time.LastFrameElapsedTime.Milliseconds / 25.0f;
                if (Input.IsPressed(SlimDX.DirectInput.Key.Space))
                    speed *= 100;
                if (Input.IsPressed(SlimDX.DirectInput.Key.A))
                    Camera.MoveSide(speed);//cameraRotationX * angleSpeed * delta);
                if (Input.IsPressed(SlimDX.DirectInput.Key.S))
                    Camera.MoveForward(-speed); //-cameraRotationY * angleSpeed * delta);
                if (Input.IsPressed(SlimDX.DirectInput.Key.D))
                    Camera.MoveSide(-speed);//cameraRotationX * angleSpeed * delta);
                if (Input.IsPressed(SlimDX.DirectInput.Key.W))
                    Camera.MoveForward(speed); //-cameraRotationY * angleSpeed * delta);
            }
            /*GraphicsEngine.BasicEffect.PtLight = new World.Graphics.PointLight()
            {
                Ambient = new Color4(0.3f, 0.3f, 0.3f),
                Diffuse = new Color4(0.7f, 0.7f, 0.7f),
                Specular = new Color4(0.7f, 0.7f, 0.7f),
                Attenuation = new Vector3(0.1f, 0.01f, 0.0f),
                Range = 5000f,
                Position = Camera.Position
            };*/

            GraphicsEngine.WaterEffect.PtLight = GraphicsEngine.BasicEffect.PtLight;
            GraphicsEngine.BasicEffect.EyePosition = Camera.Position;
            GraphicsEngine.AtmosphereEffect.EyePosition = Camera.Position;
            GraphicsEngine.WaterEffect.EyePosition = Camera.Position;
            //GraphicsEngine.BasicEffect.PtLight.Position = Camera.Position;
        }
示例#3
0
文件: Scene.cs 项目: crissian/planets
 /// <summary>
 /// Mets à jour les éléments de la scène.
 /// </summary>
 public void Update(GameTime time)
 {
     Input.Update();
     FPSCounter.AddFrame((float)time.LastFrameElapsedTime.TotalSeconds);
     DiagnosisWindow.Text = "Perf Diagnostic (" + FPSCounter.GetAverageFps().ToString() + " fps)";
     ThreadPool.Update();
     UpdateMouseCamera(time);
     Planet.Update(time);
 }