Creating a Simple 3D Game with XNA/Adding a Sky Sphere

Creating your SkySphere Renderer
In order to render the skysphere, we will create a new rendering class similar to the one used to render the fish, but modified to allow the model to render without an armature structure in place. First, create a new class file by right clicking on your project, selecting 'Add'/'New Item' and selecting 'Class'. Change the class and file name to 'GenericModelRenderer'.

Change the default using statements to the following.

And ensure that the class is using the XNA namespace by affixing the class name with.

Add the following class variables and constructor. public Model currentModel; public Vector3 Translation = new Vector3(0, 0, 0); public Vector3 Rotation = new Vector3(0, 0, 0); public float Scale = 1.0f;

Unlike the previous code, much less initialisation is required as we do not need to initialise the animation player. You'll see a similar trend with this classes equivalent to the 'ModelDraw' method.

Notice that the draw method uses the same arguments as the other fish code, can be used in more or less the same way.

Using Your Renderer
Place a new folder in your models folder called 'SkySphere', and add your model and texture. Go back into your main 'Game1' file, and add the new class variable.

Go into your LoadContent file, and add the following lines to initialise the class and set up the model for rendering.

And in the draw method, add the following line about the same place as your fish models draw method.

Render the code, and if you're set up is the same as mine, you should see a screen like this.



You might notice this isn't quite what we need. We can adjust the position and the scale by adjusting the public variables in the SkySphere class. In my case, I added the following changes after the classes initialisation in the LoadContent method.

Adjust to taste, and you should see a screen similar to mine here.