| 1 | /* | 
|---|
| 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 3 |  | 
|---|
| 4 |    Copyright (C) 2004 orx | 
|---|
| 5 |  | 
|---|
| 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 7 |    it under the terms of the GNU General Public License as published by | 
|---|
| 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 9 |    any later version. | 
|---|
| 10 |  | 
|---|
| 11 |    ### File Specific: | 
|---|
| 12 |    main-programmer: bottac@ee.ethz.ch | 
|---|
| 13 |  | 
|---|
| 14 |    review: patrick boenzli, patrick@orxonox.ethz.ch | 
|---|
| 15 | */ | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | #include "vertex_array_model.h" | 
|---|
| 19 | #include "p_node.h" | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 | #define HM_TEX_RATE      32 | 
|---|
| 23 | #define HM_TILE_SIZE     64 | 
|---|
| 24 |  | 
|---|
| 25 | //!< define the LOD level distances. later this could be dynamicaly adjusted | 
|---|
| 26 | #define HM_LOD_LOW_RES     5000         //!< low resolution unless farther away than LOW_RES | 
|---|
| 27 | #define HM_LOD_HIGH_RES    1000 | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | class SDL_Surface; | 
|---|
| 31 | class Material; | 
|---|
| 32 | class Texture; | 
|---|
| 33 | class HeightMap; | 
|---|
| 34 |  | 
|---|
| 35 |  | 
|---|
| 36 | //!< one part of the height map | 
|---|
| 37 | class Tile : public PNode | 
|---|
| 38 | { | 
|---|
| 39 |   public: | 
|---|
| 40 |     Tile(int i1, int j1, int i2, int j2, HeightMap* hm) ; | 
|---|
| 41 |     virtual ~Tile(); | 
|---|
| 42 |  | 
|---|
| 43 |     int getRes(); | 
|---|
| 44 |     int setHighRes(bool b); | 
|---|
| 45 |  | 
|---|
| 46 |     void draw(); | 
|---|
| 47 |     inline void drawHighRes() const { highResModel->draw(); } | 
|---|
| 48 |     inline void drawLowRes() const { lowResModel->draw(); } | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 |   private: | 
|---|
| 52 |     void load(int i1, int j1, int i2, int i2, VertexArrayModel* model, int Res); | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 |   public: | 
|---|
| 56 |     float x; | 
|---|
| 57 |     float z; | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|
| 60 |   private: | 
|---|
| 61 |     VertexArrayModel*                          highResModel;                      //!< heigh resolution model of the tile | 
|---|
| 62 |     VertexArrayModel*                          lowResModel;                       //!< low resolution model of the tile | 
|---|
| 63 |  | 
|---|
| 64 |     HeightMap*                                 heightMapReference;                //!< reference to the heightmap this tile belongs to | 
|---|
| 65 |     int                                        highRes;                           //!< | 
|---|
| 66 |     int                                        lowRes;                            //!< | 
|---|
| 67 | }; | 
|---|
| 68 |  | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | //!< the height map representation itself | 
|---|
| 72 | class HeightMap : public VertexArrayModel | 
|---|
| 73 | { | 
|---|
| 74 |   ObjectListDeclaration(HeightMap); | 
|---|
| 75 |   friend class Tile; | 
|---|
| 76 |  | 
|---|
| 77 |   public: | 
|---|
| 78 |     HeightMap(const std::string& heightMapName); | 
|---|
| 79 |     HeightMap(const std::string& heightMapName, const std::string& colorMapName); | 
|---|
| 80 |     virtual ~HeightMap(); | 
|---|
| 81 |  | 
|---|
| 82 |     void setAbsCoor(Vector V); | 
|---|
| 83 |     float getHeight(float x, float y); | 
|---|
| 84 |     float getNormal(float x, float y); | 
|---|
| 85 |  | 
|---|
| 86 |     void load(); | 
|---|
| 87 |     void load(int Mode); | 
|---|
| 88 |     void load(const std::string&, int Mode); | 
|---|
| 89 |     void scale( Vector V); | 
|---|
| 90 |  | 
|---|
| 91 |     void draw() const; | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 |   private: | 
|---|
| 95 |     void init(const std::string& heightMapName); | 
|---|
| 96 |  | 
|---|
| 97 |     void generateNormalVectorField(); | 
|---|
| 98 |     void drawRect(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight ); | 
|---|
| 99 |     void fixBoarder(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight); | 
|---|
| 100 |  | 
|---|
| 101 |     /** helper function absolute value @param val value*/ | 
|---|
| 102 |     inline int abs(int val) { return (val<0)?-val:val; } | 
|---|
| 103 |     /** returns the max of two numbers @param x value 1 @param y value 2*/ | 
|---|
| 104 |     inline int max(int x, int y) { return (x>y)? x:y; } | 
|---|
| 105 |     /** returns the min of two numbers @param x value 1 @param y value 2*/ | 
|---|
| 106 |     inline int min(int x, int y) { return (x<y)? x: y; } | 
|---|
| 107 |  | 
|---|
| 108 |  | 
|---|
| 109 |   private: | 
|---|
| 110 |     SDL_Surface*                          heightMap;                          //!< image of the height map | 
|---|
| 111 |     SDL_Surface*                          colorMap;                           //!< image of the color map | 
|---|
| 112 |     unsigned char*                        heights; | 
|---|
| 113 |     unsigned char*                        colors; | 
|---|
| 114 |  | 
|---|
| 115 |     Vector**                              normalVectorField; | 
|---|
| 116 |     Tile***                               tiles; | 
|---|
| 117 |     Vector                                camCoords; | 
|---|
| 118 |     Vector                                offsetCoords; | 
|---|
| 119 |     Material*                             tmp_mat; | 
|---|
| 120 |     Material*                             red_mat; | 
|---|
| 121 |     Texture*                              texture; | 
|---|
| 122 |     const PNode*                          camera; | 
|---|
| 123 |  | 
|---|
| 124 |     float                                 scaleX ; | 
|---|
| 125 |     float                                 scaleY ; | 
|---|
| 126 |     float                                 scaleZ ; | 
|---|
| 127 |     float                                 shiftX ; // to be removed | 
|---|
| 128 |     float                                 shiftY ; // to be removed | 
|---|
| 129 |     float                                 shiftZ ; // to be removed | 
|---|
| 130 |     float                                 offsetX; | 
|---|
| 131 |     float                                 offsetY; | 
|---|
| 132 |     float                                 offsetZ; | 
|---|
| 133 |     int                                   cmScaleX; | 
|---|
| 134 |     int                                   cmScaleY; | 
|---|
| 135 |     bool                                  hasColourMap; | 
|---|
| 136 | }; | 
|---|