XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Models enlarge in a rotation transoformation

Last post 7/1/2009 10:38 AM by Cinosura. 2 replies.
  • 7/1/2009 9:28 AM

    Models enlarge in a rotation transoformation

    Hi all,

    I have a problem with models rotation.

    I drew a scene with nine scaled cube (just to form cards) and I positioned them in an order way onto a plane.
    then I tried to apply some animation into the scene, defining a 180 degrees rotationfor each cards (standing in their own position).

    At First I simply used this code:

                if (rotation[index-1] < 3.14f) 
                { 
     
                    worldScena[index] = Matrix.CreateRotationY(MathHelper.ToRadians(1f))* worldScena[index]; 
     

                    rotation[index-1] += MathHelper.ToRadians(1f); 
                } 

    where worSdscena is an array of world Matrix, one for each card.

    This code works well for what reguard rotation but it adds an enlargment to cards during it (they become thicker). Cards return to the correct dimensions whene they stop to rotate.

    So I tried to modify this code in this way:
    if (rotation[index-1] < 3.14f) 
     
    worldScena.Translation=-posizioneScena[index]; 
    worldScena[index] *= Matrix.CreateRotationY(MathHelper.ToRadians(1f)); 
    wordlScena.Translation=posizioneScena[index]; 
                     
    rotation[index-1] += MathHelper.ToRadians(1f); 

    where posizioneScena[] is a vector3 array which contains all of the information about initial cards position.

    This code works properly, cards rotate and they don't enlarge during rotation. But this time a got another problem, after rotation "worldScena.Translation=posizioneScena[index]" doesn't carry the object where it was at the origin, but it assign it a new position.

    There's something I can do to solve this last problem?

    Thanks anyone could help me.
  • 7/1/2009 9:53 AM In reply to

    Re: Models enlarge in a rotation transoformation

    You have a - sign in front of your posizioneScena[index]. And you miss indexers at line 4 and 6.
  • 7/1/2009 10:38 AM In reply to

    Re: Models enlarge in a rotation transoformation

    Sorry, you're right. I made a mistake into rewrite it. that's the correct one:


    if (rotation[index-1] < 3.14f)  
    {  
      
    worldScena[index].Translation=-posizioneScena[index];  
    worldScena[index] *= Matrix.CreateRotationY(MathHelper.ToRadians(1f));  
    wordlScena[index].Translation=posizioneScena[index];  
                      
    rotation[index-1] += MathHelper.ToRadians(1f);  
    }  
    Anyway, the - sign at line 4 is correct cause I have to translate world matrix into the origin first and then rotate it. posizioneScena[] is computed start from (0,0,0).

    if I replace line 4 with

    worldScena[index].Translation=Vector3.Zero;  

    the result is the same.
Page 1 of 1 (3 items) Previous Next