Пример #1
0
        public void UpdateLightCamera()
        {
            Vector3 forward      = MathHelper.Forward;
            Vector3 targetPlaneX = MathHelper.Right;
            Vector3 targetPlaneY = MathHelper.Up;

            var world = Matrix.Identity;

            world *= Matrix.Scaling(new Vector3(LightRadius, LightRadius, LightRadius));
            world *= Matrix.Scaling((float)Math.Tan(SpotLightAngle) * (targetPlaneX + targetPlaneY) + forward);
            Vector3 up = MathHelper.Up;

            if (Math.Abs(Vector3.Dot(up, SpotDirection)) > 0.999)
            {
                up = MathHelper.Right;
            }


            world *= Matrix.Invert(Matrix.LookAtRH(Vector3.Zero, -SpotDirection, up));//world *= Matrix.CreateWorld(Vector3.Zero, -SpotDirection, up);
            world *= Matrix.Translation(LightPosition);


            Vector3    scale, translation;
            Quaternion rotation;

            world.Decompose(out scale, out rotation, out translation);

            Matrix view       = Matrix.Invert(world);
            Matrix projection = Matrix.PerspectiveFovRH(MathHelper.PiOver2, 1, 0.01f, 1); //TODO: fix field of view?

            LightCamera.SetViewProjectionMatrix(view, projection);
            LightCamera.NearClip = 0.01f;
            LightCamera.FarClip  = 1;
        }