Why is my model's scale changing after rotating it?
Posted
by
justnS
on Game Development
See other posts from Game Development
or by justnS
Published on 2011-11-20T19:05:46Z
Indexed on
2011/11/21
2:09 UTC
Read the original article
Hit count: 286
I have just started a simple flight simulator and have implemented Roll and pitch. In the beginning, testing went very well; however, after about 15-20 seconds of constantly moving the thumbsticks in a random or circular motion, my model's scale begins to grow. At first I thought the model was moving closer to the camera, but i set break points when it was happening and can confirm the translation of my orientation matrix remains 0,0,0. Is this a result of Gimbal Lock?
Does anyone see an obvious error in my code below?
public override void Draw( Matrix view, Matrix projection )
{
Matrix[] transforms = new Matrix[Model.Bones.Count];
Model.CopyAbsoluteBoneTransformsTo( transforms );
Matrix translateMatrix = Matrix.Identity
* Matrix.CreateFromAxisAngle( _orientation.Right, MathHelper.ToRadians( pitch ) )
* Matrix.CreateFromAxisAngle( _orientation.Down, MathHelper.ToRadians( roll ) );
_orientation *= translateMatrix;
foreach ( ModelMesh mesh in Model.Meshes )
{
foreach ( BasicEffect effect in mesh.Effects )
{
effect.World = _orientation * transforms[mesh.ParentBone.Index];
effect.View = view;
effect.Projection = projection;
effect.EnableDefaultLighting();
}
mesh.Draw();
}
}
public void Update( GamePadState gpState )
{
roll = 5 * gpState.ThumbSticks.Left.X;
pitch = 5 * gpState.ThumbSticks.Left.Y;
}
© Game Development or respective owner