Shadows

Topics: Developer Forum, Project Management Forum, User Forum
Jun 4, 2008 at 1:21 PM
Hello again :-)

I have been trying to add shadow to my models, using the Matrix.CreateShadow() method. When i use the Matrix.CreateShadow nothing shows up on the screen.

Here's my code. Could you please tell what's going wrong?

protected override void LoadGraphicsContent(bool loadAllContent)
        {
            dwarfPosition.X = -0.005f;
            dwarfPosition.Y = 0f;
            dwarfPosition.Z = 0.025f;

            dwarfPosition1.X = 0.01f;
            dwarfPosition1.Y = 0f;
            dwarfPosition1.Z = 0.022f;

            Model model = content.Load<Model>("animations");
            Model model1 = content.Load<Model>("animations");
            dwarfAnimator = new ModelAnimator(this, model);
            dwarfAnimator1 = new ModelAnimator(this, model);
   
            Viewport port = graphics.GraphicsDevice.Viewport;
            view = Matrix.CreateLookAt(
                new Vector3(0, 10, -25), Vector3.Zero, Vector3.Up);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.PiOver4, (float)port.Width / port.Height, .1f, 10000f);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (Effect effect in mesh.Effects)
                {
                    if (effect is BasicEffect)
                    {
                        BasicEffect basic = (BasicEffect)effect;
                        basic.View = view;
                        basic.Projection = projection;
                    }
                    else if (effect is BasicPaletteEffect)
                    {
                        BasicPaletteEffect palette = (BasicPaletteEffect)effect;
                        palette.View = view;
                        palette.Projection = projection;
                        // enable some lighting
                        palette.EnableDefaultLighting();
                        palette.DirectionalLight0.Direction = lightPos;
                    }
                }
            }

            dwarfAnimator.World = Matrix.CreateTranslation(dwarfPosition)
                * Matrix.CreateScale(500f)
                * Matrix.CreateRotationY(91f);

            dwarfAnimator1.World = Matrix.CreateTranslation(dwarfPosition1)
                * Matrix.CreateScale(500f)
                * Matrix.CreateRotationY(91f);

            dwarfAnimator1.World = Matrix.CreateTranslation(dwarfPosition1)
                * Matrix.CreateScale(500f)
                * Matrix.CreateRotationY(91f);
                //* Matrix.CreateShadow(lightPos, lightPlane);

            // Animation Stuff
            //run = new AnimationController(this, dwarfAnimator.Animations["Run"]);
            //RunController(dwarfAnimator, run);

            // Animation Stuff
            //walk = new AnimationController(this, dwarfAnimator.Animations["Walk"]);
            //RunController(dwarfAnimator1, walk);
        }
Jun 23, 2008 at 4:14 PM
Hmmm. Looks a little hopeful to me. MSDN has a "how to" on this: http://msdn.microsoft.com/en-us/library/bb464050.aspx

Also, there are many better ways to make shadows than flattening the mesh unfortunately they are not easy. I recommend, don't re-invent the wheel  ;-)  especially not when someone as clever as Catalin Zima has already invented it: http://www.catalinzima.com/?p=336