Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualkavaari

Posted 08 June 2012 - 05:17 AM

I changed the grid creation code to more efficient one. I took the code almost straight from Riemers example, so there shouldn't be much errors in that, but still the problem exist, it's driving me crazy!


int iCounter = 0;
//Vertices
for (int x = 0; x < numSideTiles+1; x++)
	 for (int z = 0; z < numSideTiles+1; z++)
	 {
		  float xPos = x * spacing;
		  float zPos = z * spacing;

		  vertices[x + z * (numSideTiles + 1)] = new PositionNormalTextured() { Position = new Vector4(xPos, 0, zPos, 1.0f), Normal = normal, UV = new Vector2(x, z) };
	 }
//Indices
for (int x = 0; x < numSideTiles; x++)
	 for (int z = 0; z < numSideTiles; z++)
	 {
		  ushort lowerLeft = (ushort)(x + z * (numSideTiles+1));
		  ushort lowerRight = (ushort)((x + 1) + z * (numSideTiles + 1));
		  ushort topLeft = (ushort)(x + (z + 1) * (numSideTiles + 1));
		  ushort topRight = (ushort)((x + 1) + (z + 1) * (numSideTiles + 1));

		  indices[iCounter++] = topLeft;
		  indices[iCounter++] = lowerRight;
		  indices[iCounter++] = lowerLeft;
		  
		  indices[iCounter++] = topLeft;
		  indices[iCounter++] = topRight;
		  indices[iCounter++] = lowerRight;

	 }

Here is a picture of 5x5 quad, and as you can see it's a little different.
[attachment=9350:5x5quadWTFv2.png]

I'm thinking the problem is somewhere else than in the loop.

#1kavaari

Posted 08 June 2012 - 05:16 AM

I changed the grid creation code to more efficient one, I took the code almost straight from Riemers example, so there shouldn't be much errors in that, but still the problem exist, it's driving me crazy!


int iCounter = 0;
//Vertices
for (int x = 0; x < numSideTiles+1; x++)
	 for (int z = 0; z < numSideTiles+1; z++)
	 {
		  float xPos = x * spacing;
		  float zPos = z * spacing;

		  vertices[x + z * (numSideTiles + 1)] = new PositionNormalTextured() { Position = new Vector4(xPos, 0, zPos, 1.0f), Normal = normal, UV = new Vector2(x, z) };
	 }
//Indices
for (int x = 0; x < numSideTiles; x++)
	 for (int z = 0; z < numSideTiles; z++)
	 {
		  ushort lowerLeft = (ushort)(x + z * (numSideTiles+1));
		  ushort lowerRight = (ushort)((x + 1) + z * (numSideTiles + 1));
		  ushort topLeft = (ushort)(x + (z + 1) * (numSideTiles + 1));
		  ushort topRight = (ushort)((x + 1) + (z + 1) * (numSideTiles + 1));

		  indices[iCounter++] = topLeft;
		  indices[iCounter++] = lowerRight;
		  indices[iCounter++] = lowerLeft;
		  
		  indices[iCounter++] = topLeft;
		  indices[iCounter++] = topRight;
		  indices[iCounter++] = lowerRight;

	 }

Here is a picture of 5x5 quad, and as you can see it's a little different.
[attachment=9350:5x5quadWTFv2.png]

I'm thinking the problem is somewhere else than in the loop.

PARTNERS