Results 1 to 5 of 5

Thread: Height Map -- Lines

  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

  2. #2

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    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?
    "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

  3. #3
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    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.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Also instead of making the indices in reverse order try using Clockwise Culling instead of Anticlockwise Culling, or vise verser.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    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.
    "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