-
1 Attachment(s)
Height Map -- Lines
Why on earth would this happen (Look at picture)
The lines you see seemingly appear behind me from the point you can see them in the pic onward.
On the way back from the otherside, all you can see above you is some nasty spaces apart lines, it is super ugly...*** is going on.
The vertices MUST be getting listed incorrectly.
Scale = 1024, size = 128.
This is the code which generates the map you see
PHP Code:
bool Landscape::GenerateHeightMap(int size, int scale)
{
FILE *fp;
Segments[0].Size = size;
Segments[0].Scale = scale;
int Size = size;
int Scale = scale;
unsigned char *hmap = new unsigned char[size*size];
memset(hmap, 0, sizeof(unsigned char)*size*size);
if ((fp = fopen("image.raw", "rb")) == NULL)
return false;
fread(hmap, sizeof(unsigned char), size*size, fp);
fclose(fp);
Segments[0].NumVertices = Size*Size;
Segments[0].Vertices = new D3DVERTEX[Segments[0].NumVertices];
memset(Segments[0].Vertices, 0, Segments[0].NumVertices);
float texdelta = 2.0f/Size;
D3DVERTEX vert;
int CurrVertex=0;
float UTile=12.0f;
float VTile=12.0f;
// loop through every pixel in the heightmap
for (int y=0; y < Size; y++)
{
for (int x=0; x < Size; x++)
{
// Get the current vertex we want to calculate
CurrVertex = y*Size+x;
AddVertice(0,
CurrVertex,
(float)(x) * Scale,
(float)(hmap[CurrVertex] * (Scale/2)),
(float)(y) * Scale,
UTile * ((float)x * texdelta * 0.5f),
VTile * (1.0f - (float)y * texdelta * 0.5f)
);
}
}
Segments[0].NumIndices = (Size-1)*(Size-1)*6;
Segments[0].Indices = new unsigned short[Segments[0].NumIndices];
memset(Segments[0].Indices, 0, Segments[0].NumIndices);
int idx=Segments[0].NumIndices;
for (y=0; y < Size-1; y++)
{
for (int x=0; x < Size-1; x++)
{
CurrVertex = y*(Size)+x;
Segments[0].Indices[idx--] = CurrVertex;
Segments[0].Indices[idx--] = CurrVertex+1;
Segments[0].Indices[idx--] = CurrVertex+(Size);
Segments[0].Indices[idx--] = CurrVertex+(Size)+1;
Segments[0].Indices[idx--] = CurrVertex+(Size);
Segments[0].Indices[idx--] = CurrVertex+1;
}
}
// we dont need the heightmap anymore, get rid of it
if (hmap) { delete hmap; hmap = NULL; }
return true;
}
Edit:
What type of draw method should I use? STRIP, LIST?
Notice how I am listing the indice backwards...If I don't, then I only seem every 2nd triangle on the terrain unless my camera is below the terrain then I see it all.....
That code is generating enough triangles for the top and bottom to be displayed. I only need to see the top...when the camera is above.
If I do a LINESTRIP it seems every vertice point runs a tangent to an infinite nowhere.
-
OKAY
If I use TRAINGLELIST and put the camera below the terrain it works fine. I think...so it is actually sitting below 0..ie the triangles are being render in the wrong orientation.
any assistance?
-
can you post a couple more pictures from different angles so I can see what is actually happening. Also are all those lines going to 0,0? This is a common problem when you run out of verts in your buffer.
-
Also instead of making the indices in reverse order try using Clockwise Culling instead of Anticlockwise Culling, or vise verser.
-
Thanks for your attempted assistance.
You are indeed correct.
I had to record the indices in the proper order 0 to end..
They were originally being ordered clockwise....so by reversing it I sorta fixed the problem on TRIANGLESTRIP.
TO FIX IT:
First off, using TRAINGLELIST allowed me to only see the outline of hills above the terrain, and I could see everything if I went below the terrain and looked up at it.
So after staring at the code forever I realized the indices where still being ordered clockwise...so I switched it to the opposite.
Segments[0].Indices[idx++] = CurrVertex+(Size);
Segments[0].Indices[idx++] = CurrVertex+1;
Segments[0].Indices[idx++] = CurrVertex;
Segments[0].Indices[idx++] = CurrVertex+1;
Segments[0].Indices[idx++] = CurrVertex+(Size);
Segments[0].Indices[idx++] = CurrVertex+(Size)+1;
That minor change to the code fixed it fine...No crazy lines, I can see the terrain from any angle above the terrain. Using TRAINGLELIST.
Only problem I encounter now....Is below the terrain I should not see anything...assumably...But I can see every 2nd triangle
I'll post a jpeg showing an example....It weird. Literally every 2nd triangle is removed from culling when below the terrain, but they all show above the terrain....
I do not get it...
I can't seem to see if the code I posted above is trying to create the terrain as to allow seeing from both sides.