Main Page   Class Hierarchy   Compound List   Header Files   Compound Members  

ddghemap.h

This is the verbatim text of the ddghemap.h include file.
/*
    Copyright (C) 1997, 1998, 1999, 2000 by Alex Pfaffe
        (Digital Dawn Graphics Inc)
  
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
  
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
  
    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ddgHeightMap_Class_
#define _ddgHeightMap_Class_

#include "util/ddgerror.h"
#include "math/ddgvec.h"

class WEXP ddgHeightMap {
        short*  _pixbuffer;
        unsigned short  _cols;
        unsigned short  _rows;
        float _scale;
        float _base;
public:
        ddgHeightMap( void )
                : _pixbuffer(0), _scale(1), _base(0) {}
        ddgHeightMap( unsigned short r, unsigned short c)
                : _pixbuffer(0), _scale(1), _base(0) { allocate(r,c); }
        ~ddgHeightMap();
        short *buffer(void) { return _pixbuffer; }
        unsigned short cols(void) { return _cols; }
        unsigned short rows(void) { return _rows; }
        bool allocate( unsigned short r, unsigned short c);
        void set(unsigned short r, unsigned short c,
                short d1)
        {
                ddgAssert(r < _rows && c < _cols);
                _pixbuffer[(r*_cols+c)+0] = d1;
        }
        short get(unsigned short r, unsigned short c,
                short *d1 = 0)
        {
                ddgAssert(r < _rows && c < _cols);
                short s = _pixbuffer[(r*_cols+c)+0];
                if (d1) *d1 = s;
                return s;
        }
        static inline float sconvert(short n, float base, float scale)
        {
                return (n + 0x7FFF) * scale + base;
        }
        static inline short siconvert(float n, float base, float scale)
        {
                return (short) ddgUtil::clamp((n - base ) / scale - 0x7FFF,-0x7FFF,0x7FFF);
        }
        inline short iconvert(float n)
        {
                return siconvert(n, _base, _scale );
        }
        inline float convert(short n)
        {
                return sconvert(n, _base, _scale);
        }
        float getf(unsigned short r, unsigned short c,
                float *d1 = 0)
        {
                ddgAssert(r < _rows && c < _cols);
                float s = convert( _pixbuffer[(r*_cols+c)+0] );
                if (d1) *d1 = s;
                return s;
        }
        bool readMemory( unsigned short *buf );

        bool loadTerrain(const char *filename);

        bool readTGN(const void *buf, unsigned long size);

        bool readRAW(const char *filename, int w, int h);

        bool readTGN(const char *filename);

        bool writeTGN(const char *filename);
        bool readPGM(const char* data, int desired_max);

        bool generateHeights(unsigned int r, unsigned int c, float octaves);
        ddgHeightMap * ddgHeightMap::quadify( void );

        void canyonize(float strength );
        void glaciate(float strength );
        void setMinMax(float b = 0, float d = 1) { _scale = (d-b)/0xFFFF; _base = b;  }
        void setScaleAndBase(float s, float b = 0) { _scale = s*_scale; _base += b;  }
        float scale(void) { return _scale; }
        float base(void) { return _base; }
        void scale(float s );
        void translate(float t );
        int mini(void);
        int maxi(void);
        void setmax( int m);
        void setmin( int m);
        void scalef(float s ) { scale( iconvert(s)); }
        void translatef(float t ) { translate( iconvert(t)); }
        float minf(void)  { return convert(mini()); }
        float maxf(void)  { return convert(maxi()); }
        void setmaxf( float m) { setmax( iconvert(m)); }
        void setminf( float m) { setmin( iconvert(m)); }
        void closeEdge(float l);
        void sin(void);
        bool saveAsTGA(const char *filename);
        bool createSpectralMap(int level, float smoothness);
        void vertexNormal(ddgVector3& normal, long row, long col, float gridSpacing);

};

#endif

Generated at Sun Sep 17 19:27:53 2000 for Digital Dawn Graphics Toolkit by doxygen 0.49-991205 written by Dimitri van Heesch, © 1997-1999