Size error when rotating/scaling

Sep 1, 2011 at 8:00 AM

Hi Ohan,

 first of all, thanks for your time and create this space to share knowledge.

Im having some problem when rotating and scaling an .fbx model (like the ship in the tutorial 8), when i scale the model it shrinks (but then scales with no problem) and when i rotate the model is enlarged (very!). Will the model returning to the original size in the case of rotatint it ? u wrote that the model is very large... anyway this is my code: 

protected override void Update(GameTime gameTime)

       {

   KeyboardState state = Keyboard.GetState();

           //rotación eje X

           if (state.IsKeyDown(Keys.W))

           {

               deltaRotationX += gameTime.ElapsedGameTime.TotalSeconds / 2;

               sphereTransParentNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)deltaRotationY)

   * Quaternion.CreateFromAxisAngle(Vector3.Right, (float)deltaRotationX)

   * Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)deltaRotationZ);

           }

           else if (state.IsKeyDown(Keys.S))

           {

               deltaRotationX -= gameTime.ElapsedGameTime.TotalSeconds / 2;

               sphereTransParentNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)deltaRotationY)

   * Quaternion.CreateFromAxisAngle(Vector3.Right, (float)deltaRotationX)

   * Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)deltaRotationZ);

           }

 

           //rotación eje Y

           if (state.IsKeyDown(Keys.D))

           {

               deltaRotationY += gameTime.ElapsedGameTime.TotalSeconds / 2;

               sphereTransParentNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)deltaRotationY)

   * Quaternion.CreateFromAxisAngle(Vector3.Right, (float)deltaRotationX)

   * Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)deltaRotationZ);

           }

           else if (state.IsKeyDown(Keys.A))

           {

               deltaRotationY -= gameTime.ElapsedGameTime.TotalSeconds / 2;

               sphereTransParentNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)deltaRotationY)

   * Quaternion.CreateFromAxisAngle(Vector3.Right, (float)deltaRotationX)

   * Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)deltaRotationZ);

           }

           //ritación eje Z

           if (state.IsKeyDown(Keys.Q))

           {

               deltaRotationZ += gameTime.ElapsedGameTime.TotalSeconds / 2;

               sphereTransParentNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)deltaRotationY)

   * Quaternion.CreateFromAxisAngle(Vector3.Right, (float)deltaRotationX)

   * Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)deltaRotationZ);

           }

           else if (state.IsKeyDown(Keys.E))

           {

               deltaRotationZ -= gameTime.ElapsedGameTime.TotalSeconds / 2;

               sphereTransParentNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)deltaRotationY)

   * Quaternion.CreateFromAxisAngle(Vector3.Right, (float)deltaRotationX)

   * Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)deltaRotationZ);

           }

           // Zoom in

           if (state.IsKeyDown(Keys.Up))

           {

               i += gameTime.ElapsedGameTime.TotalSeconds / 2;

                sphereTransParentNode.Scale = new Vector3((float)i, (float)i, (float)i);

           }

               //Zoom out

           else if (state.IsKeyDown(Keys.Down))

           {

               i -= gameTime.ElapsedGameTime.TotalSeconds / 2;

               sphereTransParentNode.Scale = new Vector3((float)i, (float)i, (float)i);

           }

base.Update(gameTime);

       }

 

I´ll appreciate your help, thank u very much!

Coordinator
Sep 2, 2011 at 3:28 AM

If you're using the ship model and if you're taking the codes directly from the tutorial, it's being scaled to much smaller size. 

However, in your update code, you're setting the scale to your own scale based on the elapsed time, so it'll appear huge (you're basically resetting it to your own scale from, say, 0.0001f scale or something very small). If you want to scale it from the already scaled version, then you should multiply your scale to its original Scale (e.g., sphereTransParentNode.Scale *= 1.1f for enlarging, and less than 1.0f for shrinking).

The rotation will not affect the scaling, so it must be something else.

Ohan

Sep 2, 2011 at 5:59 PM

Thank you very much! i understand the scale problem, it multiplies each axis of the vector. Im trying now to scale it slower b/c it scales too fast.. so ill work on that. Do you see any error in the rotating code? it rotates with no problem buy sometimes the model is enlarged, i assume that might be another problem.