0
votes

I have a project due very soon and I'm having lots of issues trying to load a model I made in 3D Studio Max. The model I made is what I want as my terrain in my XNA game. Here is what I've done so far:

Methods:

    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    Model terrainModel;
    Vector3 terrainPosition = Vector3.Zero;

    Vector3 cameraPosition = new Vector3(0.0f, 60.0f, 160.0f);
    Vector3 cameraLookAt = new Vector3(0.0f, 60.0f, 160.0f);
    Matrix cameraProjectionMatrix;
    Matrix cameraViewMatrix;

LoadContent()

        spriteBatch = new SpriteBatch(GraphicsDevice);

        cameraViewMatrix = Matrix.CreateLookAt(
            cameraPosition,
            Vector3.Zero,
            Vector3.Up);

        cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
            MathHelper.ToRadians(80.0f),
            graphics.GraphicsDevice.Viewport.AspectRatio,
            1.0f,
            1000.0f);

        terrainModel = Content.Load<Model>("alphastreet");

Draw(GameTime gameTime)

GraphicsDevice.Clear(Color.CornflowerBlue);

        DrawModel(terrainModel, terrainPosition);

        // TODO: Add your drawing code here

        base.Draw(gameTime);

And then I want to Draw:

void DrawModel(Model model, Vector3 modelPosition)
    {
        foreach (ModelMesh mesh in model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.PreferPerPixelLighting = true;

                effect.World = Matrix.CreateTranslation(modelPosition);
                effect.Projection = cameraProjectionMatrix;
                effect.View = cameraViewMatrix;
            }
            mesh.Draw();
        }
    }

Everything else is just as an XNA file should look. The model it's self looks like a fairly straightforward street. However, upon XNA loading the model, it's just a big block in the window that loads.

I don't know what I'm doing that's making the model load like this, but it's making me pull my hair out. Any help would be appreciated.

Also, would anybody be able to direct me to walk-through/guide or a class that creates a First Person Shooter camera, since that is the game I'm going. I probably shouldn't have picked that, but it's way too late to change now, so if you could help there too you would really be saving my skin!

Thanks, Jake!

1

1 Answers

0
votes

Is there more than one mesh in the model, and if so, have you tried rendering each one separately? Have you tried using identity matrices for world and view to make sure these aren't the issue? I assume you haven't made any other state changes to xna/directx, if so try disabling these.

For a FPS camera, you can just track the x and y rotation in float variables and update these each frame based upon how far the mouse has moved in x and y. From these you can generate a camera view matrix; something like the following:

var mx = Matrix.CreateRotationX(xangle);
var my = Matrix.CreateRotationY(yangle);
var pos = Matrix.CreateTranslation(position);
var view = mx * my * pos; // These might be in the wrong order, not sure off the top of my head
view.Invert();

The camera is always inverted because moving left moves the world right, turning left turns the world right etc.