Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

ParentBone.Transform and depth problem

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Tasaq   Members   

1530
Like
0Likes
Like

Posted 04 March 2012 - 08:21 AM

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? Posted Image
here's my code for drawing:

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


#2 Tarika   Members   

485
Like
0Likes
Like

Posted 04 March 2012 - 08:44 AM

question, how come you are using 'effect.EnableDefaultLighting();'and 'Matrix.CreateScale(Scale)' 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


#3 Tasaq   Members   

1530
Like
0Likes
Like

Posted 04 March 2012 - 10:29 AM

question, how come you are using 'effect.EnableDefaultLighting();'and 'Matrix.CreateScale(Scale)' 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 Posted Image As for lighting I forgot to delete leftovers :\
I solved the problem but... I am still confused Posted Image 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 Posted Image

#4 Tarika   Members   

485
Like
1Likes
Like

Posted 04 March 2012 - 11:43 AM

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





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.