• Advertisement
Sign in to follow this  

ParentBone.Transform and depth problem

This topic is 2148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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? [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
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]

Share this post


Link to post
Share on other sites
Advertisement
question, how come you are using '[color=#000000][font=Consolas,]effect.EnableDefaultLighting();'[/font][/color]and '[color=#000000][font=Consolas,]Matrix.CreateScale(Scale)' [/font][/color]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:

[CODE]
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
[/CODE]

Aimee.

Share this post


Link to post
Share on other sites
[quote name='AmzBee' timestamp='1330872269' post='4919176']
question, how come you are using '[color=#000000][font=Consolas,]effect.EnableDefaultLighting();'[/font][/color]and '[color=#000000][font=Consolas,]Matrix.CreateScale(Scale)' [/font][/color]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:

[CODE]
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
[/CODE]

Aimee.
[/quote]
Those are different Scales [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] As for lighting I forgot to delete leftovers :\
I solved the problem but... I am still confused [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] code:
[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();
}
}[/CODE]
Now I am not using bones, but I can see that objects are placed correct and there's no problem with depth anymore [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
Maybe this might work:

[CODE]
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();
}

}
[/CODE]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement