I've made some models in Blender and exported them in Autodesk fbx format. I'm trying to view them using XNA 4.0 Refresh.

Loading them isn't much an issue, but I'm not familiar enough with XNA 4.0 to, well basically I want to load in the model at say the origin (0,0,0) world coordinates, and then rotate and/or zoom the camera about the world coordinates origin as well so that I can test the model. Typically the mouse, and maybe some arrow keys for zooming/rotating the camera.

Anyways, this seems like a simple task and I shouldn't have to re-invent this, isn't there a skeleton code somewhere for this kind of thing for XNA 4.0? I couldn't find a solid example for this on the web. I found a couple that seemed like they might work for xbox, but I'm trying to do this on windows only.

Anyways, just looking to be pointed in the right direction on this one, thanks.


1 Answer 1


First, start with something that can load FBX files. If you've got this working - then by all means use your own code. But I suggest also looking at the WinForms 2 sample which shows a rotating FBX model.

Next is handling user input. In XNA you will want to look at the Mouse class (MSDN). The basic pattern for using it is to keep the current and previous mouse states and then compare the difference in positions.

MouseState lastMouseState;
protected override void Update(GameTime gameTime)
    MouseState mouseState = Mouse.GetState();
    int deltaX = mouseState.X - lastMouseState.X;
    int deltaY = mouseState.Y - lastMouseState.Y;
    // ...

For Keyboard (MSDN) the process is pretty much the same - compare the last and current states.

If you are using WinForms (as per that sample), you'll have to hook up events to the model viewer control and handle those instead.

Finally, what you are trying to implement here is called an orbit camera. I don't think there's any definitive way to implement this. It's just a series of matrix transformations.

The WinForms 2 sample I linked implements most of what you want already. Look at ModelViewerControl.Draw in that sample for where it sets up its matrices. Here's a modified version that you can work from:

Matrix world = Matrix.CreateRotationY(rotateY) * Matrix.CreateRotationX(rotateX);
Matrix view = Matrix.CreateLookAt(modelCenter + new Vector2(0, 0, modelRadius + zoom),
                                  modelCenter, Vector3.Up);

Then it's simply a matter of taking those delta inputs from earlier and then accumulating those deltas in the appropriate variable. For example:

const float rotateSpeedFactor = 0.05f; // this is a guess
rotateX += deltaX * rotateSpeedFactor;
rotateY += deltaY * rotateSpeedFactor;

Edit: Another one to look at is the Skinned Model sample, which implements almost exactly what you are looking for (with keyboard control - arrows rotate, Z/X to zoom).

  • \$\begingroup\$ Thanks, this was really helpful especially the Skinned Model Sample. \$\endgroup\$ Jul 7, 2012 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .