Results 1 to 5 of 5

Thread: Height Map -- Lines

Threaded View

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    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 sizeint 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(hmap0sizeof(unsigned char)*size*size);
        
        if ((
    fp fopen("image.raw""rb")) == NULL)
            return 
    false;

        
    fread(hmapsizeof(unsigned char), size*sizefp);

        
    fclose(fp);
        
        
    Segments[0].NumVertices Size*Size;
        
    Segments[0].Vertices = new D3DVERTEX[Segments[0].NumVertices];
        
    memset(Segments[0].Vertices0Segments[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=0Sizey++)
        {
            for (
    int x=0Sizex++)
            {
                
    // 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)texdelta 0.5f),
                           
    VTile * (1.0f - (float)texdelta 0.5f)
                          );
            }
        }

        
    Segments[0].NumIndices = (Size-1)*(Size-1)*6;
        
    Segments[0].Indices = new unsigned short[Segments[0].NumIndices];
        
    memset(Segments[0].Indices0Segments[0].NumIndices);

        
    int idx=Segments[0].NumIndices;
        for (
    y=0Size-1y++)
        {
            for (
    int x=0Size-1x++)
            {
                
    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 hmaphmap 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.
    Attached Images Attached Images  
    Last edited by Halsafar; Nov 28th, 2004 at 11:09 PM.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width