Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4093 in orxonox.OLD


Ignore:
Timestamp:
May 6, 2005, 8:19:01 PM (19 years ago)
Author:
nico
Message:

branches/heightMap: challenging the model class

Location:
orxonox/branches/heightMap/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/heightMap/src/lib/graphics/importer/heightmap.cc

    r4090 r4093  
    1616        this->setName(fileName);
    1717       
    18         this->import(fileName);
     18        this->import(fileName, displaylistResolution, vertexResolution);
    1919       
    20         //this->finalize();
     20        this->finalize();
    2121}
    2222
     
    2525}
    2626
    27 bool Heightmap::import (const char* fileName)
     27bool Heightmap::import (const char* fileName, int displaylistResolution, int vertexResolution)
    2828{
    2929        PRINTF(4)("preparing to read in file: %s\n", fileName);
     
    3232        this->bitmap = IMG_Load(fileName);
    3333
     34        // how many pixels wide is a display list?
     35        int pixPerDLSide = displaylistResolution * vertexResolution;
     36
     37        int howManyListsWide = bitmap->w / pixPerDLSide + 1;
     38        int howManyListsHigh = bitmap->h / pixPerDLSide + 1;
    3439       
     40        // calculated pixel dimensions of one display list. usually equals pixPerDLSide, but at the end of the picture
     41        // this needs to be shorter, that we do not make a segfault
     42        int width = pixPerDLSide;
     43        int height = pixPerDLSide;
    3544       
    36        
     45        for (int i=0; i<howManyListsWide; i++)
     46        {
     47                for (int j=0; j<howManyListsHigh; j++)
     48                {
     49                        // catch out of image access in x-direction
     50                        if ( (j+1)*pixPerDLSide - 1 >= bitmap->w )      width = bitmap->w - j*pixPerDLSide;
     51                        else                                                                            width = pixPerDLSide;
     52                        // y-direction
     53                        if ( (i+1)*pixPerDLSide - 1 >= bitmap->h )      height = bitmap->h - i*pixPerDLSide;
     54                        else                                                                            height = pixPerDLSide;
     55                       
     56                        this->readIntoGroup(j*pixPerDLSide,i*pixPerDLSide,width,height,vertexResolution);
     57                }
     58        }
    3759       
    3860        return true;
    3961}
    4062
     63void Heightmap::readIntoGroup(int left, int top,int width, int height, int vertexResolution)
     64{
     65        //this->newGroup();
     66       
     67        for (int z=top; z < top+height; z++)
     68        {
     69                for (int x=left; x < left+width; x++)
     70                {
     71                        this->addVertex(x,this->getHeightAt(x,z),z);
     72                }
     73        }
     74}
     75
     76float Heightmap::getHeightAt(int x, int z)
     77{
     78        Uint8 index;
     79        SDL_Color color;
     80       
     81        SDL_LockSurface(bitmap);
     82       
     83        index = *((Uint8*)bitmap->pixels + z * bitmap->pitch + x * bitmap->format->BytesPerPixel);
     84        color = bitmap->format->palette->colors[index];
     85       
     86        SDL_UnlockSurface(bitmap);
     87       
     88        // return the red component, because in a grayscale pic, r,g and b are all the same value
     89        return (GLint)color.r;
     90}
  • orxonox/branches/heightMap/src/lib/graphics/importer/heightmap.h

    r4090 r4093  
    1616       
    1717private:
    18         bool import (const char* fileName);
     18        bool Heightmap::import (const char* fileName, int displaylistResolution, int vertexResolution);
     19        void Heightmap::readIntoGroup(int left, int top,int width, int height, int vertexResolution);
     20
     21        float Heightmap::getHeightAt(int x, int z);
    1922
    2023        // holds the loaded pixels
  • orxonox/branches/heightMap/src/story_entities/world.cc

    r4090 r4093  
    627627
    628628  //terrain = new Terrain("../data/worlds/newGround.obj");
    629   terrain = new Terrain("../data/pictures/heightmapHello.bmp");
     629  terrain = new Terrain("../data/pictures/heightmapHello.bmp",100,1);
    630630  terrain->setRelCoor(Vector(0,-10,0));
    631631  this->spawn(terrain);
Note: See TracChangeset for help on using the changeset viewer.