Beispiel #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (shadowMap != null)
            {
                shadowMap.Draw(gameTime);
            }

            transformable.Update(gameTime);
        }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (shadows)
            {
                if (game.World.Players[0] != null)
                {
                    {
                        Vector3 v = game.World.Players[0].GlobalPosition +
                                    (int)shadowMapCameraSizeLow.Y * 0.45f *
                                    game.World.Players[0].Camera.GlobalTransformation.Forward;

                        float x = v.X;
                        float z = v.Z;

                        bool rotate = shadowMapCameraSizeLow.X != shadowMapCameraSizeLow.Y;

                        if (!rotate)
                        {
                            // texel size in world coordinates
                            float texelWidth  = shadowMapCameraSizeLow.X / shadowMapLow.Width;
                            float texelHeight = shadowMapCameraSizeLow.Y / shadowMapLow.Height;

                            // truncate x and z to texel size to reduce flicker
                            x = (float)Math.Floor(x / texelWidth) * texelWidth;
                            z = (float)Math.Floor(z / texelHeight) * texelHeight;
                        }

                        shadowMapLow.Scene.Camera.LocalPosition = new Vector3(x, shadowMapCameraHeight, z);

                        if (rotate)
                        {
                            shadowMapLow.Scene.Camera.LocalRotation =
                                Quaternion.Concatenate(
                                    Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), -(float)Math.PI / 2),
                                    Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                                                                   (float)
                                                                   Math.Acos(
                                                                       game.World.Players[0].Camera.GlobalTransformation
                                                                       .
                                                                       Forward.Z)
                                                                   )
                                    );
                        }
                    }
                    {
                        Vector3 v = game.World.Players[0].GlobalPosition +
                                    (int)shadowMapCameraSizeHigh.Y * 0.3f *
                                    game.World.Players[0].Camera.GlobalTransformation.Forward;

                        float x = v.X;
                        float z = v.Z;

                        bool rotate = shadowMapCameraSizeHigh.X != shadowMapCameraSizeHigh.Y;

                        if (!rotate)
                        {
                            // texel size in world coordinates
                            float texelWidth  = shadowMapCameraSizeHigh.X / shadowMapHigh.Width;
                            float texelHeight = shadowMapCameraSizeHigh.Y / shadowMapHigh.Height;

                            // truncate x and z to texel size to reduce flicker
                            x = (float)Math.Floor(x / texelWidth) * texelWidth;
                            z = (float)Math.Floor(z / texelHeight) * texelHeight;
                        }

                        shadowMapHigh.Scene.Camera.LocalPosition = new Vector3(x, shadowMapCameraHeight, z);

                        if (rotate)
                        {
                            shadowMapHigh.Scene.Camera.LocalRotation =
                                Quaternion.Concatenate(
                                    Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), -(float)Math.PI / 2),
                                    Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                                                                   (float)
                                                                   Math.Acos(
                                                                       game.World.Players[0].Camera.GlobalTransformation
                                                                       .
                                                                       Forward.Z)
                                                                   )
                                    );
                        }
                    }
                }

                shadowMapHigh.Draw(gameTime);
                shadowMapLow.Draw(gameTime);
            }
        }