title: Rotation in XNA
body: <p>I have a question concerning model rotation in XNA. The question is - what should I do (which values should be changed and how) to rotate green model in that way (red arrows):</p>
  
  <p><a href="http://img843.imageshack.us/i/question1.jpg/" rel="nofollow">http://img843.imageshack.us/i/question1.jpg/</a></p>
  
  <p>Code used to draw :</p>
  
  <pre><code>DrawModel(elementD, new Vector3(-1, 0.5f, 0.55f), 0,-90,0);
  
  private void DrawModel(Model model, Vector3 position, float rotXInDeg, float rotYInDeg, float rotZInDeg)
      {
          float rotX = (float)(rotXInDeg * Math.PI / 180);
          float rotY = (float)(rotYInDeg * Math.PI / 180);
          float rotZ = (float)(rotZInDeg * Math.PI / 180);
  
          Matrix worldMatrix = Matrix.CreateScale(0.5f, 0.5f, 0.5f) * Matrix.CreateRotationY(rotY) *Matrix.CreateRotationX(rotX)*Matrix.CreateRotationZ(rotZ)* Matrix.CreateTranslation(position);
          Matrix[] xwingTransforms = new Matrix[model.Bones.Count];
          model.CopyAbsoluteBoneTransformsTo(xwingTransforms);
          foreach (ModelMesh mesh in model.Meshes)
          {
              foreach (BasicEffect effect in mesh.Effects)
              {
                  effect.EnableDefaultLighting();
  
                  effect.View = cam.viewMatrix;
                  effect.Projection = cam.projectionMatrix;
                  effect.World = (xwingTransforms[mesh.ParentBone.Index] * worldMatrix);
              }
              mesh.Draw();
          }
  
      }
  </code></pre>
  
  <hr>
  
  <p>So I tried to apply your solution by changing my code slightly:  </p>
  
  <pre><code>Matrix worldMatrix = Matrix.CreateScale(0.5f, 0.5f, 0.5f) * Matrix.CreateRotationY(rotY) * Matrix.CreateRotationX(rotX)  * Matrix.CreateTranslation(position)
                  * Matrix.CreateRotationX((float)(45 * Math.PI / 180)) * Matrix.CreateRotationZ(rotZ) * Matrix.CreateRotationX((float)(-45 * Math.PI / 180)); 
  </code></pre>
  
  <p>By changing rotZ parameter indeed I was able to rotate the model. However the effect is not what I wanted to achieve <a href="http://img225.imageshack.us/i/questionau.jpg/" rel="nofollow">http://img225.imageshack.us/i/questionau.jpg/</a>, it changed its position. Is it because of a faulty model or some other mistake? I want the "cylinder" to remain in its position. Do you know how can I do this?</p>