Jump to content
  • Advertisement
Sign in to follow this  
jalpeshk

[XNA] Model Rotation & Lighting

This topic is 2562 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

pYZoA.jpg


All the blocks shown are rendered from the same model, with a few of them being rotated by 90 degrees. I'm using a shader to get the lighting, but the models that are rotated also have their lighting shifted. It seems as if the models are rotated after the shader effects are applied? My shader can be found here: http://pastebin.ca/2066327

How can I get the rotated models to have the same lighting? The rotation values are passed in the World matrix.

Here is the rendering code:

foreach (ModelMesh mesh in model.Meshes)
{
foreach (Effect effect in mesh.Effects)
{
...

effect.Parameters["World"].SetValue(gameModel.Transforms[mesh.ParentBone.Index] * gameModel.World);
effect.Parameters["View"].SetValue(gameModel.View);
effect.Parameters["Projection"].SetValue(gameModel.Projection);
}

mesh.Draw();
}



I set each objects World before it is rendered to a matrix that create the horizontal shear effect off the models.

Here is the code for each objects World Matrix:

public Matrix World
{
get { return _world; }
set
{
Matrix scale = Matrix.CreateScale(_scale);
Matrix rotation = Matrix.CreateRotationX(MathHelper.ToRadians(_rotate.X)) * Matrix.CreateRotationY(MathHelper.ToRadians(_rotate.Y)) * Matrix.CreateRotationZ(MathHelper.ToRadians(_rotate.Z));
Matrix translation = Matrix.CreateTranslation(_translate);

_world = translation * scale * rotation * value;
}
}

Share this post


Link to post
Share on other sites
Advertisement

_world = translation * scale * rotation * value;


I think your matrix order is backwards. It should be:

world = scale * rotation * translation;

See if that fixes it.


Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!