Weird appearance for a 3D XNA ground

Posted by Belos on Game Development See other posts from Game Development or by Belos
Published on 2012-07-05T10:16:31Z Indexed on 2012/07/05 15:24 UTC
Read the original article Hit count: 248

Filed under:
|
|

I wanted to add a ground so I can know the position of a helicopter in the world. But the ground appeared in a weird way:

http://i.stack.imgur.com/yTSuW.jpg

The ground had the following texture:

http://i.stack.imgur.com/pdpxB.png

EDIT: Sorry, I forgot to post the code:

public class ImportModel
{
    public Vector3 Position { get; set; }
    public Vector3 Rotation { get; set; }
    public Vector3 Scale { get; set; }
    Model Model;
    Matrix[] modeltransforms;
    GraphicsDevice GraphicDevice;
    ContentManager Content;
    BoundingSphere sphere;
    bool boundingimplemented = false;
    public ImportModel(string model, GraphicsDevice gd, ContentManager cm, Vector3 position, Vector3 rot, Vector3 sca)
    {
        GraphicDevice = gd;
        Content = cm;
        Position = position;
        Rotation = rot;
        Scale = sca;
        Model = Content.Load<Model>(model);
        modeltransforms = new Matrix[Model.Bones.Count];
        Model.CopyAbsoluteBoneTransformsTo(modeltransforms);
    }
    public void Draw(Camera camera)
    {
        Matrix baseworld = Matrix.CreateScale(Scale) * Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix.CreateTranslation(Position);
        foreach (ModelMesh mesh in Model.Meshes)
        {
            Matrix localworld = modeltransforms[mesh.ParentBone.Index] * baseworld;
            foreach (ModelMeshPart meshpart in mesh.MeshParts)
            {
                BasicEffect effect = (BasicEffect)meshpart.Effect;
                effect.World = localworld;
                effect.View = camera.View;
                effect.Projection = camera.Projection;
                effect.EnableDefaultLighting();
            }
            mesh.Draw();
        }
    }
    public BoundingSphere BoundingSphere
    {
        get
        {
            if (!boundingimplemented)
            {
                foreach (ModelMesh mesh in Model.Meshes)
                {
                    BoundingSphere transformed = mesh.BoundingSphere.Transform(
                    modeltransforms[mesh.ParentBone.Index]);
                    sphere = BoundingSphere.CreateMerged(sphere, transformed);
                }
                Matrix worldTransform = Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position);
                BoundingSphere transforme = sphere;
                transforme = transforme.Transform(worldTransform);
                return transforme;
            }
            else
            {
                Matrix worldTransform = Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position);
                BoundingSphere transformed = sphere;
                transformed = transformed.Transform(worldTransform);
                return transformed;
            }
        }
    }
}

Then I call the class from the Game1 class:

ImportModel ground = new ImportModel("ground", GraphicsDevice, Content, Vector3.Zero, Vector3.Zero, new Vector3(20f));

EDIT2:This is how the scene looks from top:

i.stack.imgur.com/Hs983.jpg

© Game Development or respective owner

Related posts about XNA

Related posts about c#