I'm trying to move a camera over a model that is used as the floor of the game. When I move the camera, the texture of the model is not showing correctly (video of the problem: http://www.youtube.com/watch?v=bpycA7epMns&feature=youtu.be). I know that the model is fine because i use xnamodelviewer (http://modelviewer.codeplex.com/) to preview all the models, and i can see it all right, even if i move the camera. So, the problem is in my model class maybe? what is wrong with this? any help is appreciated.

this is the model class im using:

public class CModel
    public Vector3 Position { get; set; }
    public Vector3 Rotation { get; set; }
    public Vector3 Scale { get; set; }

    public Model Model { get; private set; }

    private Matrix[] modelTransforms;
    private GraphicsDevice graphicsDevice;
    private BoundingSphere boundingSphere;

    public BoundingSphere BoundingSphere
            // No need for rotation, as this is a sphere
            Matrix worldTransform = Matrix.CreateScale(Scale)
                * Matrix.CreateTranslation(Position);

            BoundingSphere transformed = boundingSphere;
            transformed = transformed.Transform(worldTransform);

            return transformed;

    public CModel(Model Model, Vector3 Position, Vector3 Rotation,
        Vector3 Scale, GraphicsDevice graphicsDevice)
        this.Model = Model;

        modelTransforms = new Matrix[Model.Bones.Count];


        this.Position = Position;
        this.Rotation = Rotation;
        this.Scale = Scale;

        this.graphicsDevice = graphicsDevice;

    private void buildBoundingSphere()
        BoundingSphere sphere = new BoundingSphere(Vector3.Zero, 0);

        // Merge all the model's built in bounding spheres
        foreach (ModelMesh mesh in Model.Meshes)
            BoundingSphere transformed = mesh.BoundingSphere.Transform(

            sphere = BoundingSphere.CreateMerged(sphere, transformed);

        this.boundingSphere = sphere;

    public virtual void Draw(Matrix View, Matrix Projection,bool luces)
        // Calculate the base transformation by combining
        // translation, rotation, and scaling
        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 = View;
                effect.Projection = Projection;
                if (luces == true)
                    effect.LightingEnabled = true;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;

If I disable the line: graphicsDevice.DepthStencilState = DepthStencilState.Default; The problem with the texture is solved, but i now have problems with the model showing things that must be hidden behind others, like in this picture: model problems


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.