Sign in to follow this  
homer_3

Trouble rendering a mesh

Recommended Posts

homer_3    173
I'm trying to render a mesh but I'm not getting anything on the screen. To render I'm using:
public void DrawModel(Vector3 pos, Vector3 rotation)
        {
            boneTransforms = new Matrix[Character.Model.Bones.Count];
            Character.Model.Root.Transform = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z) *
                        Matrix.CreateScale(.8f) *
                        Matrix.CreateTranslation(pos);
            Character.Model.CopyAbsoluteBoneTransformsTo(boneTransforms);
            foreach (ModelMesh mesh in Character.Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = boneTransforms[mesh.ParentBone.Index];
                    effect.View = Session.TileEngine.Camera.CameraViewMatrix;
                    effect.Projection = Session.TileEngine.Camera.CameraProjectionMatrix;

                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;
                }

                mesh.Draw();
            }
        }

with CameraViewMatrix and CameraProjectionMatrix being:
cameraViewMatrix = Matrix.CreateLookAt(
                new Vector3(Game1.BackBufferWidth / 2, Game1.BackBufferHeight / 2, 0),
                new Vector3(Game1.BackBufferWidth / 2, Game1.BackBufferHeight / 2, -200),
                Vector3.Up);

            _cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45.0f), //how wide the camera sees
                ((float)(Game1.BackBufferWidth))/((float)(Game1.BackBufferHeight)),
                1.0f, //near clipping plane
                10000.0f); //far clipping plane

I've used code similar this to render meshes before, so I'm not sure what the problem is.

Share this post


Link to post
Share on other sites
Enerjak    277
I'm having the same problem with my Application in XNA and in DX. I don't know what the problem it as i've set it far enough to be able to be seen. I hope you can get someone to help you with this as i'm having the same problem.

Share this post


Link to post
Share on other sites
YoYoFreakCJ    100
In order to pretend that the model's vertices are simple totally out of place, you should try to position the model at Vector3.Zero, as well as it's meshes [change effect.World = ... to effect.World = Matrix.Identity] and the camera target. The camera position is somewhere else. If you still don't see anything, try resizing the model when you press a specific key. Maybe it is just too big and encloses your camera completely. In this case the culling would hinder you to see your model's intestines.

If you still don't see anything then, I would recommend you supply us with your model so we can take a look at it.

Hope I could help.

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