Need Some Assistance with XNA

Started by
5 comments, last by Nypyren 8 years, 11 months ago

Hello, I am new to the forums. I am not sure if this is the right place to post this type of thing, so I apologize in advance. I am currently taking an online course on XNA which I am having a lot of difficulty with. The course does not use the textbook directly, as in it does not use any exercises or similar projects from the book, so I am having a really hard time learning the concepts. I have tried to find a tutor from the college and they are not offered for this course. I've been in close contact with the instructor and it is not helping me. With that being said, I am looking for someone who might be interested in tutoring me throughout the rest of this course, which is roughly two more weeks. I would prefer one-on-one help rather than posting the whole project in a forum. I'm willing to pay for your time and help as well.

Advertisement
Maybe this can get you started:
http://rbwhitaker.wikidot.com/xna-tutorials

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Thanks for the link cozzie. I have viewed those tutorials, but my questions and trouble areas are more specific.

Thanks for the link cozzie. I have viewed those tutorials, but my questions and trouble areas are more specific.

Those are the best kinds of questions to ask here.


Those are the best kinds of questions to ask here.

I am usually hesitant to post for help in forums because the responses I receive are rude and unhelpful, but this forum does not come off that way.

I was not sure how to post this, but here is the starting point project that I was given: https://dl.dropboxusercontent.com/u/30197844/Klax.zip

This is week 4 of the course, so there are some things that I have done to it already, like the shader effect for example. What we need to do now is change all of the blocks to be 3D, and change the camera view after an event (such as a block hitting the paddle). In the Klax class, you can see I commented out my understanding of 3D and uses of the camera view as I was just playing around with the code. The program runs fine in 2D. My problem is now implementing 3D into the current game. Looking at the Block class, I am thinking of a way to change the Draw function so it draws myModel (defined in Klax class). I would also have to change the Draw functions in the other classes as well. Would this be the correct approach? I would appreciate any help you can give me, and if I posted the project incorrectly I apologize.

For starters, here is what is currently in the Block class, which basically draws all of the blocks in the game.


internal void Draw(SpriteBatch spriteBatch)
{
    spriteBatch.Draw(Klax.Texture, new Vector2(Column * Klax.ColumnWidth + Klax.ColumnOriginX, (int)Y), _colors[ColorIndex]);
}

My thought was that I should change it to Klax.myModel, which is the loaded in the Klax class, but I am a little lost on what else I need to do.

OK. The SpriteBatch class is only for sprites (sprites are 2D rectangles).

To draw a 3D model, you need to use something specific for that:

https://msdn.microsoft.com/en-us/library/bb197293(v=xnagamestudio.31).aspx

*** IMPORTANT NOTE: This is from XNA 3.1. If you're using a different version, google search for "XNA 3D model example", because things often change slightly between different versions, so the code might not even compile on a different version! ***


Quote taken from that example:

protected override void Draw(GameTime gameTime)
{
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

    // Copy any parent transforms.
    Matrix[] transforms = new Matrix[myModel.Bones.Count];
    myModel.CopyAbsoluteBoneTransformsTo(transforms);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in myModel.Meshes)
    {
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
            effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();
    }
    base.Draw(gameTime);
}
As you can see, 3D models require more setup steps to draw!

Transforms:
World matrix: Used to control how the model is translated (moved), oriented (rotated), and scaled (made larger/smaller).

View matrix: Used to control the "camera" (your viewpoint in space).
Projection matrix: Used to control the camera's field of view.


Effects: Are used to control how the pixels of the model are colored - they can take into account things like light sources, shiny spots on the surface, and MUCH more. These are also known as "Shaders".

Hopefully that helps some. 3D rendering takes a lot of getting used to!

This topic is closed to new replies.

Advertisement