ParentBone.Transform and depth problem

Started by
2 comments, last by AmzBee 12 years, 1 month ago
I have multiple objects in my .fbx file so i wanted to place them right with MeshModel.ParenBone.Transform, but when i do so my depth is messed up (when you can see objects behind objects that are closer to camera). When I am drawing w/o bone transform everything is okay, I am so confused about it, have no clue how multiplying matrices can affect depth buffer :\ I also want to note that I am not using spriteBatch. Anyone knows how to fix this? sad.png
here's my code for drawing:

[source]public void draw(Vector3 pos, Vector3 scale, float yaw, float pitch, float roll)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = mesh.ParentBone.Transform * Matrix.CreateScale(Scale) * Matrix.CreateScale(scale) *
Matrix.CreateFromYawPitchRoll(yaw + Rotation.Y, pitch + Rotation.X, roll + Rotation.Z) *
Matrix.CreateTranslation(pos);
effect.EnableDefaultLighting();
effect.Projection = Projection;
effect.View = View;
effect.PreferPerPixelLighting = true;
effect.DiffuseColor *= Effects.DiffuseColor;
effect.SpecularColor *= Effects.SpecularColor;
effect.AmbientLightColor *= Effects.AmbientLightColor;
effect.Alpha = Effects.Alpha;
effect.EnableDefaultLighting();
}

mesh.Draw();
}
}[/source]
Advertisement
question, how come you are using '[color=#000000][font=Consolas,]effect.EnableDefaultLighting();'[/font]and '[color=#000000][font=Consolas,]Matrix.CreateScale(Scale)' [/font]twice? Onto your question though, have you made sure that you
have depth testing enabled? try placing the following as the first line in your draw method:


GraphicsDevice.DepthStencilState = DepthStencilState.Default;


Aimee.

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com


question, how come you are using '[color=#000000][font=Consolas,]effect.EnableDefaultLighting();'[/font]and '[color=#000000][font=Consolas,]Matrix.CreateScale(Scale)' [/font]twice? Onto your question though, have you made sure that you
have depth testing enabled? try placing the following as the first line in your draw method:


GraphicsDevice.DepthStencilState = DepthStencilState.Default;


Aimee.

Those are different Scales smile.png As for lighting I forgot to delete leftovers :\
I solved the problem but... I am still confused smile.png code:
public void draw(Vector3 pos, Vector3 scale, float yaw, float pitch, float roll)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = Matrix.CreateScale(Scale) * Matrix.CreateScale(scale) *
Matrix.CreateFromYawPitchRoll( Rotation.Y, Rotation.X, Rotation.Z) *
Matrix.CreateFromYawPitchRoll(yaw , pitch , roll ) *
Matrix.CreateTranslation(pos) ;
effect.EnableDefaultLighting();
effect.Projection = Projection;
effect.View = View;
effect.PreferPerPixelLighting = true;
effect.DiffuseColor *= Effects.DiffuseColor;
effect.SpecularColor *= Effects.SpecularColor;
effect.AmbientLightColor *= Effects.AmbientLightColor;
effect.Alpha = Effects.Alpha;
}
mesh.Draw();
}
}

Now I am not using bones, but I can see that objects are placed correct and there's no problem with depth anymore smile.png
Maybe this might work:


public void draw(Vector3 pos, Vector3 scale, float yaw, float pitch, float roll)
{
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);

foreach (ModelMesh mesh in model.Meshes)
{

foreach (BasicEffect effect in mesh.Effects)
{
effect.World = transforms[mesh.ParentBone.Index]
* Matrix.CreateScale(Scale) * Matrix.CreateScale(scale)
* Matrix.CreateFromYawPitchRoll( Rotation.Y, Rotation.X, Rotation.Z)
* Matrix.CreateFromYawPitchRoll(yaw , pitch , roll )
* Matrix.CreateTranslation(pos);

effect.Projection = Projection;
effect.View = View;


effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.DiffuseColor *= Effects.DiffuseColor;
effect.SpecularColor *= Effects.SpecularColor;
effect.AmbientLightColor *= Effects.AmbientLightColor;
effect.Alpha = Effects.Alpha;
}
mesh.Draw();
}

}

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

This topic is closed to new replies.

Advertisement