Пример #1
0
 public override void UpdateScene(float dt)
 {
     base.UpdateScene(dt);
     if (Util.IsKeyDown(Keys.Up))
     {
         _camera.Walk(100.0f * dt);
     }
     if (Util.IsKeyDown(Keys.Down))
     {
         _camera.Walk(-100.0f * dt);
     }
     if (Util.IsKeyDown(Keys.Left))
     {
         _camera.Strafe(-100.0f * dt);
     }
     if (Util.IsKeyDown(Keys.Right))
     {
         _camera.Strafe(100.0f * dt);
     }
     if (Util.IsKeyDown(Keys.PageUp))
     {
         _camera.Zoom(-dt);
     }
     if (Util.IsKeyDown(Keys.PageDown))
     {
         _camera.Zoom(+dt);
     }
     if (Util.IsKeyDown(Keys.Space))
     {
         _camera.LookAt(new Vector3(0, 5, -5), new Vector3(0, 0, 0), Vector3.UnitY);
     }
 }
Пример #2
0
        private BallisticDemo(IntPtr hInstance)
            : base(hInstance)
        {
            _currentShotType = ShotType.Laser;

            MainWindowCaption = "Ballistic Demo";

            _lastMousePos = new Point();

            _camera = new FpsCamera();
            _camera.LookAt(new Vector3(10, 2, -10), new Vector3(0, 1, 0), Vector3.UnitY);

            _dirLights = new[] {
                new DirectionalLight {
                    Ambient   = new Color4(0.2f, 0.2f, 0.2f),
                    Diffuse   = new Color4(0.7f, 0.7f, 0.7f),
                    Specular  = new Color4(0.8f, 0.8f, 0.8f),
                    Direction = new Vector3(-0.57735f, -0.57735f, 0.57735f)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(1.0f, 0.4f, 0.4f, 0.4f),
                    Specular  = new Color4(1.0f, 0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(-0.707f, -0.707f, 0)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(1.0f, 0.2f, 0.2f, 0.2f),
                    Specular  = new Color4(0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(0, 0, -1)
                }
            };
        }
Пример #3
0
            public FpsCamera ToCamera(Matrix transform)
            {
                var camera = new FpsCamera(Fov.ToRadians());

                camera.LookAt(
                    Vector3.TransformCoordinate(Position, transform),
                    Vector3.TransformCoordinate(Position + Look, transform),
                    Vector3.TransformNormal(Up, transform));
                return(camera);
            }
Пример #4
0
            public FpsCamera ToCamera()
            {
                var camera = new FpsCamera(Fov.ToRadians())
                {
                    Position = Position
                };

                camera.LookAt(Position, Position + Look, Up);
                return(camera);
            }
Пример #5
0
        private PointLightDemo(IntPtr hInstance) : base(hInstance)
        {
            MainWindowCaption        = "Point Light Demo";
            _lastMousePos            = new Point();
            Enable4XMsaa             = true;
            GammaCorrectedBackBuffer = true;

            _camera = new FpsCamera();
            _camera.LookAt(new Vector3(71, 41, 71), Vector3.Zero, Vector3.UnitY);

            _dirLightDirection.Normalize();
        }
Пример #6
0
        public void SetCamera(Vector3 from, Vector3 to, float fovRadY)
        {
            UseFpsCamera = true;
            Camera       = new FpsCamera(fovRadY);

            _cameraTo = to;
            Camera.LookAt(from, to, Vector3.UnitY);
            Camera.SetLens(AspectRatio);
            //Camera.UpdateViewMatrix();

            PrepareCamera(Camera);
            IsDirty = true;
        }
Пример #7
0
        public void SetCamera(Vector3 lookFrom, Vector3 lookAt, float fovRadY, float tiltRad)
        {
            UseFpsCamera = true;
            AutoRotate   = false;
            Camera       = new FpsCamera(fovRadY);

            _cameraTo = lookAt;
            Camera.LookAt(lookFrom, lookAt, tiltRad);
            Camera.SetLens(AspectRatio);
            //Camera.UpdateViewMatrix();

            PrepareCamera(Camera);
            IsDirty           = true;
            _cameraIgnoreNext = true;
        }
Пример #8
0
        public bool Update(Vector3 position, Vector3 direction, float range, float angle)
        {
            var result = _dirty;

            _dirty = false;

            if (result || _camera.FovY != angle || _camera.FarZ != range)
            {
                _camera.FovY = angle;
                _camera.FarZ = range;
                _camera.SetLens(1f);
                result = true;
            }

            if (result || _camera.Position != position || Vector3.Dot(_camera.Look, direction) < 0.99)
            {
                _camera.LookAt(position, position + direction,
                               Math.Abs(direction.Y - 1f) < 0.01f || Math.Abs(direction.Y - (-1f)) < 0.01f ? Vector3.UnitX : Vector3.UnitY);
                _camera.UpdateViewMatrix();
                result = true;
            }

            if (result)
            {
                ShadowTransform = _camera.ViewProj * new Matrix {
                    M11 = 0.5f,
                    M22 = -0.5f,
                    M33 = 1.0f,
                    M41 = 0.5f,
                    M42 = 0.5f,
                    M44 = 1.0f
                };
            }

            return(result);
        }