/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: bottac@ee.ethz.ch review: patrick boenzli, patrick@orxonox.ethz.ch */ #include "vertex_array_model.h" #include "p_node.h" #define HM_TEX_RATE 32 #define HM_TILE_SIZE 64 //!< define the LOD level distances. later this could be dynamicaly adjusted #define HM_LOD_LOW_RES 5000 //!< low resolution unless farther away than LOW_RES #define HM_LOD_HIGH_RES 1000 class SDL_Surface; class Vector; class Material; class PNode; class Texture; class HeightMap; //!< one part of the height map class Tile : public PNode { public: Tile(int i1, int j1, int i2, int j2, HeightMap* hm) ; virtual ~Tile(); int getRes(); int setHighRes(bool b); void draw(); inline void drawHighRes() const { highResModel->draw(); } inline void drawLowRes() const { lowResModel->draw(); } private: void load(int i1, int j1, int i2, int i2, VertexArrayModel* model, int Res); public: float x; float z; private: VertexArrayModel* highResModel; //!< heigh resolution model of the tile VertexArrayModel* lowResModel; //!< low resolution model of the tile HeightMap* heightMapReference; //!< reference to the heightmap this tile belongs to int highRes; //!< int lowRes; //!< }; //!< the height map representation itself class HeightMap : public VertexArrayModel { friend class Tile; public: HeightMap(const std::string& heightMapName); HeightMap(const std::string& heightMapName, const std::string& colorMapName); virtual ~HeightMap(); void setAbsCoor(Vector V); float getHeight(float x, float y); float getNormal(float x, float y); void load(); void load(int Mode); void load(const std::string&, int Mode); void scale( Vector V); void draw() const; private: void init(const std::string& heightMapName); void generateNormalVectorField(); void drawRect(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight ); void fixBoarder(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight); /** helper function absolute value @param val value*/ inline int abs(int val) { return (val<0)?-val:val; } /** returns the max of two numbers @param x value 1 @param y value 2*/ inline int max(int x, int y) { return (x>y)? x:y; } /** returns the min of two numbers @param x value 1 @param y value 2*/ inline int min(int x, int y) { return (x