Sign in to follow this  
royteusink

[C#] Error with shadow

Recommended Posts

Hi all, Why is my shadow drawing like this? How do i fix this problem? [EDIT] I want to add a shadow below my player models with a shadow plane. But when I draw the shadow it draws like this see picture above. It is like the shadow is attached to the arms like glue or something, kinda weird ><. I don't know how i can fix this problem. How can i draw this shadow on the same Y axis ?? Thanks Free Image Hosting at www.ImageShack.us SHADOW:
//#### DRAW SHADOW #####
                mtrlShadow = new Material();
                mtrlShadow.Diffuse = Color.Black;
                shadowPlane = new Plane(0.0f, 1.0f, 0.0f, 0.0f);
                matShadow.Shadow(new Vector4(1.0f, 1.0f, 1.0f, 0.0f), shadowPlane);
                Properties.device.Material = mtrlShadow;
                Properties.device.Transform.World = frame.CombinedTransformationMatrix*Matrix.Scaling(SetScaling, SetScaling, SetScaling) * Matrix.RotationYawPitchRoll(SetYaw, SetPitch, SetRoll) * Matrix.Translation(SetPosition.X,SetPosition.Y,SetPosition.Z ) * matShadow;
                
                for (int iattrib1 = 0; iattrib1 < mesh.NumberAttributes; iattrib1++)
                {
                    mesh.MeshData.Mesh.DrawSubset(iattrib1);
                }
                //#######################


DRAW PLAYER MODEL + SHADOW:
        Plane shadowPlane;
        Matrix matShadow;
        Material mtrlShadow;
        public void DrawMeshContainer(MeshContainerDerived mesh, FrameDerived frame)
        {
            if (mesh.SkinInformation != null)
            {
                int attribIdPrev = -1;

                for (int iattrib = 0; iattrib < mesh.NumberAttributes; iattrib++)
                {
                    int numBlend = 0;
                    BoneCombination[] bones = mesh.GetBones();
                    for (int i = 0; i < mesh.NumberInfluences; i++)
                    {
                        if (bones[iattrib].BoneId[i] != -1)
                        {
                            numBlend = i;
                        }
                    }

                    if (Properties.device.DeviceCaps.MaxVertexBlendMatrices >= numBlend + 1)
                    {
                        Matrix[] offsetMatrices = mesh.GetOffsetMatrices();
                        FrameDerived[] frameMatrices = mesh.GetFrames();
                        for (int i = 0; i < mesh.NumberInfluences; i++)
                        {
                            int matrixIndex = bones[iattrib].BoneId[i];
                            if (matrixIndex != -1)
                            {
                               Matrix tempMatrix = offsetMatrices[matrixIndex] *
                                   frameMatrices[matrixIndex].
                                   CombinedTransformationMatrix * Matrix.Scaling(SetScaling, SetScaling, SetScaling) * Matrix.RotationYawPitchRoll(SetYaw, SetPitch, SetRoll) * Matrix.Translation(SetPosition);

                                Properties.device.Transform.SetWorldMatrixByIndex(i, tempMatrix);
                            }
                        }

                        Properties.device.RenderState.VertexBlend = (VertexBlend)numBlend;
                        
                        if ((attribIdPrev != bones[iattrib].AttributeId) ||
                            (attribIdPrev == -1))
                        {
                            Properties.device.Material = mesh.GetMaterials()[bones[iattrib].AttributeId].Material3D;
                            Properties.device.SetTexture(0, mesh.GetTextures()[bones[iattrib].AttributeId]);
                            attribIdPrev = bones[iattrib].AttributeId;
                        }
                        mesh.MeshData.Mesh.DrawSubset(iattrib);
                    }
                }

                //#### DRAW SHADOW #####
                mtrlShadow = new Material();
                mtrlShadow.Diffuse = Color.Black;
                shadowPlane = new Plane(0.0f, 1.0f, 0.0f, 0.0f);
                matShadow.Shadow(new Vector4(1.0f, 1.0f, 1.0f, 0.0f), shadowPlane);
                Properties.device.Material = mtrlShadow;
                Properties.device.Transform.World = frame.CombinedTransformationMatrix*Matrix.Scaling(SetScaling, SetScaling, SetScaling) * Matrix.RotationYawPitchRoll(SetYaw, SetPitch, SetRoll) * Matrix.Translation(SetPosition.X,SetPosition.Y,SetPosition.Z ) * matShadow;
                
                for (int iattrib1 = 0; iattrib1 < mesh.NumberAttributes; iattrib1++)
                {
                    mesh.MeshData.Mesh.DrawSubset(iattrib1);
                }
                //#######################
            }
            else 
            {
                Properties.device.Transform.World = frame.CombinedTransformationMatrix;
                ExtendedMaterial[] mtrl = mesh.GetMaterials();
                for (int iMaterial = 0; iMaterial < mtrl.Length; iMaterial++)
                {
                    Properties.device.Material = mtrl[iMaterial].Material3D;
                    Properties.device.SetTexture(0, mesh.GetTextures()[iMaterial]);
                    mesh.MeshData.Mesh.DrawSubset(iMaterial);
                }
            }
        }


[Edited by - royteusink on October 22, 2006 12:21:40 PM]

Share this post


Link to post
Share on other sites
Probably people don't like a vague description like "it does not work, here is my code". Maybe it is helpfull if you describe what you want, what your method is and what the problems are.

Share this post


Link to post
Share on other sites
Well, sorry for bad english, but I want to add a shadow below my player models with a shadow plane. But when I draw the shadow it draws like this see picture above. It is like the shadow is attached to the arms like glue or something, kinda weird ><. I don't know how i can fix this problem. How can i draw this shadow on the same Y axis ??

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this