riemerg

Hi all --

I have finished porting my second series of tutorials to XNA final code! You can find it here:

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

Some of the XNA concepts covered in this second series include: textured triangles, importing a Model and using a custom effect to render it, first-person camera positioning, basic 3D position updating mechanism, basic boundingsphere collision detection, point sprites, alpha blending, textured model loading with storage of its textures

More basic stuff is shown in the first series. Readers are combining all concepts to build a basic, but working flight simulator. The code of my 3rd chapter (a detailed introduction to HLSL) has already been converted to XNA final code, it's only a matter of days before you can expect to see the first ported pages.

Once again, comments are welcome

riemer




Re: XNA Game Studio Express Second series (13 parts) of 3D XNA tutorials finished +flightsim

Lostlogic

Thanks for the excellent tutorials.

I have a question though: I'm trying to use a texture for the terrain example (instead of coloring it) and can't figure out based on your code how you came to derive:

public static int SizeInBytes = 7 * 4;

What does the 7 and 4 represent I've tried changing the vertex struct to the following:

public struct VertexPositionNormalTextured
{
public Vector3 Position;
public Vector3 Normal;
public Vector3 TextureCoordinate;

public static int SizeInBytes = 7 * 4;

public static VertexElement[] VertexElements = new VertexElement[]
{
new VertexElement( 0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0 ),
new VertexElement( 0, sizeof(float) * 3, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Normal, 0 ),
new VertexElement( 0, sizeof(float) * 4, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0 ),
};
}


The problem is that when I go to allocate memory for the vb object the debugger comes back with "Not enough space in buffer". So, I'm guessing that changing from Position, Color, Normal to Position, Normal, TextureCoord I've changed the size of the vertex buffer and therefore need to change the sizeinbytes member Any suggestions you have on this would be appreciated.

Thanks





Re: XNA Game Studio Express Second series (13 parts) of 3D XNA tutorials finished +flightsim

BLiTZWiNG

I'm no expert at XNA, especially the vertex elements, but what I can tell you:

Vector3 Position = 3 floats (1 float = 4 bytes)
Color Color = 1 int (1 int = 4 bytes)
Vector3 Normal = 3 floats

= 3 + 1 + 3 = 7
7 * 4 because each float is 4 bytes

therefore each Vector3 takes 12 bytes

A texture coord is made up of 2 floats, u & v. So now you have position + normal + texture = 3 + 3 + 2 = 8!

So your last line should be sizeof(float) * 2 not 4.

HTH




Re: XNA Game Studio Express Second series (13 parts) of 3D XNA tutorials finished +flightsim

Lostlogic

BLiTZWiNG wrote:
I'm no expert at XNA, especially the vertex elements, but what I can tell you:

Vector3 Position = 3 floats (1 float = 4 bytes)
Color Color = 1 int (1 int = 4 bytes)
Vector3 Normal = 3 floats

= 3 + 1 + 3 = 7
7 * 4 because each float is 4 bytes

therefore each Vector3 takes 12 bytes

A texture coord is made up of 2 floats, u & v. So now you have position + normal + texture = 3 + 3 + 2 = 8!

So your last line should be sizeof(float) * 2 not 4.

HTH

Although the code you mention doesnt work it led me in the right direction, so thanks!

The code that works:

public struct VertexPositionNormalColored
{
public Vector3 Position; // 3
public Vector3 Normal; // 3
public Vector2 TextureCoordinate; // 2

public static int SizeInBytes = 8 * 4;
public static VertexElement[] VertexElements = new VertexElement[]
{
new VertexElement( 0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0 ),
new VertexElement( 0, sizeof(float) * 3, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Normal, 0 ),
new VertexElement( 0, sizeof(float) * 6, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0 ),
};
}





Re: XNA Game Studio Express Second series (13 parts) of 3D XNA tutorials finished +flightsim

BLiTZWiNG

Nothing better than the feeling of reading something that doesn't work and making it work!

Well, thats my opinion anyway. Glad it helped!





Re: XNA Game Studio Express Second series (13 parts) of 3D XNA tutorials finished +flightsim

riemerg

Hi --

That part of code is explained in more detail in Series 3, which focusses on HLSL. However, since they are much more important in XNA as they were in MDX, I have extended my explanation on vertex formats in XNA a bit. It's become quite a lengthy page, but I think it contains all details so everybody can understand vertex formats, and create their own. If you feel some info is missing, make sure you let me know!






Re: XNA Game Studio Express Second series (13 parts) of 3D XNA tutorials finished +flightsim

Lostlogic

riemerg wrote:

Hi --

That part of code is explained in more detail in Series 3, which focusses on HLSL. However, since they are much more important in XNA as they were in MDX, I have extended my explanation on vertex formats in XNA a bit. It's become quite a lengthy page, but I think it contains all details so everybody can understand vertex formats, and create their own. If you feel some info is missing, make sure you let me know!


Although I figured out the custom vertex I do want to figure out how to do it in shaders as your new article shows. I appreciate the effort you put into the tutorials as they are very helpful!