# xna model scaling - model is bigger than world

I'm having trouble scaling my model in XNA with C#. The model is bigger than the world itself and I can't seem to scale it down. Below is the code I'm using and an attached screenshot. How can I scale my model down?

       private void DrawModel(Matrix currentViewMatrix)
{

Matrix[] bones = animationPlayer.GetSkinTransforms();

// Compute camera matrices.
Matrix view = Matrix.CreateTranslation(0, -40, 0) *
Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation_model)) *
Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) *
Matrix.CreateLookAt(new Vector3(0, 0, -cameraDistance),
new Vector3(0, 0, 0), Vector3.Up);

float fieldOfView = MathHelper.ToRadians(4);

Matrix projection = Matrix.CreatePerspectiveFieldOfView(fieldOfView, device.Viewport.AspectRatio, 1, 100000);

// Render the skinned mesh.
foreach (ModelMesh mesh in currentModel.Meshes)
{
foreach (SkinnedEffect effect in mesh.Effects)
{
effect.SetBoneTransforms(bones);

effect.View = view;
effect.Projection = projection;

effect.EnableDefaultLighting();

effect.SpecularColor = new Vector3(0.25f);
effect.SpecularPower = 16;
}

mesh.Draw();
}
}


edit: when I change the following lines, I'm able to scale the model, however when I turn my model, it rotates in a circle; the model isn't properly scaled. If I do not scale the model, it turns properly around itself.

How can I fix this?

Matrix view = Matrix.CreateTranslation(0, -50, 0) *
Matrix.CreateScale(0.01f, 0.01f, 0.01f) *
Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation_model)) *
Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) *
Matrix.CreateLookAt(new Vector3(0, 0, -cameraDistance),
new Vector3(0, 0, 0), Vector3.Up);


## 1 Answer

You should first scale and rotate, and then translate:

        Vector3 objPos = new Vector3(0, -50, 0);
Vector3 camPos = objPos - Vector3.One * cameraDistance;
Matrix view =
Matrix.CreateScale(0.01f, 0.01f, 0.01f) *
Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation_model)) *
Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) *
Matrix.CreateTranslation(objPos) *
Matrix.CreateLookAt(camPos, obsPos, Vector3.Up);


EDITED: Because camera was placed where object was not.

• thanks for your help. I did try that before you posted, if I use 0.01f as scale, the model 'doesn't show up (it probably does but not visible)'. I can only get the model to show again if I use a scale above 1f. Am I missing something essential? – Maarten Hartman Sep 4 '13 at 11:20
• It's due to the camera position, the lookat args have to be changed – Blau Sep 4 '13 at 11:28
• thanks, I get "No overload for method 'CreateTranslation' takes 0 arguments" - I've tried to add '0, -10, 0' as value but then the model isn't visible – Maarten Hartman Sep 4 '13 at 11:49
• btw: is it possible (or even an decent idea) to scale the world instead of the model ? – Maarten Hartman Sep 4 '13 at 12:17
• The best would be separate model trasforms from camera transforms, so you can scale, translate and rotate the models, and only calculate camera transform once time. – Blau Sep 4 '13 at 14:26