Terrain basics

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_basics.php

This tutorial doesn’t require any significant changes, really we are just carrying over earlier changes that we have made.

So where we initialize myVertexDeclaration in your SetUpVertices() method instead of creating a new instance like so:

myVertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);

we can use the one from VertexPositionColor which looks like this:

myVertexDeclaration = VertexPositionColor.VertexDeclaration;

Now when we declare the array for our indices we will use either int[] or short[] depending on the graphics profile you have set in the properties for your project. If you aren’t sure which one you are using these profile setting can be found in solution explorer, in the properties of your game project (either right-click the project and select properties or double-click the grey properties folder under your project.)

Reach Profile =

Define your array like this:

short[] indices;

And in your SetUpIndices() method, initialize it like this:

indices = new short[(terrainWidth – 1) * (terrainHeight – 1) * 6];

Last declare the variables inside the for-loop like this:

short lowerLeft = (short)(x + y * terrainWidth);
short lowerRight = (short)((x + 1) + y * terrainWidth);
short topLeft = (short)(x + (y + 1) * terrainWidth);
short topRight = (short)((x + 1) + (y + 1) * terrainWidth);

HiDef Profile =

Define your array like this:

int[] indices;

And in your SetUpIndices() method, initialize it like this:

indices = new int[(terrainWidth – 1) * (terrainHeight – 1) * 6];

Last declare the variables inside the for-loop like this:

int lowerLeft = x + y*terrainWidth;
int lowerRight = (x + 1) + y*terrainWidth;
int topLeft = x + (y + 1) * terrainWidth;
int topRight = (x + 1) + (y + 1) * terrainWidth;

And that wraps it up for this tutorial, next up Terrain from file!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s