| [5942] | 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: | 
|---|
| [6956] | 12 |    main-programmer: bottac@ee.ethz.ch | 
|---|
| [7466] | 13 |  | 
|---|
 | 14 |    review: patrick boenzli, patrick@orxonox.ethz.ch | 
|---|
| [5942] | 15 | */ | 
|---|
 | 16 |  | 
|---|
| [5967] | 17 |  | 
|---|
| [6956] | 18 | #include "vertex_array_model.h" | 
|---|
| [7490] | 19 | #include "p_node.h" | 
|---|
| [5942] | 20 |  | 
|---|
| [6956] | 21 |  | 
|---|
| [7500] | 22 | #define HM_TEX_RATE      32 | 
|---|
 | 23 | #define HM_TILE_SIZE     64 | 
|---|
| [6956] | 24 |  | 
|---|
| [7468] | 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 |  | 
|---|
| [5967] | 30 | class SDL_Surface; | 
|---|
| [6956] | 31 | class Material; | 
|---|
 | 32 | class Texture; | 
|---|
 | 33 | class HeightMap; | 
|---|
| [5942] | 34 |  | 
|---|
| [7466] | 35 |  | 
|---|
 | 36 | //!< one part of the height map | 
|---|
| [7490] | 37 | class Tile : public PNode | 
|---|
| [5942] | 38 | { | 
|---|
| [7466] | 39 |   public: | 
|---|
 | 40 |     Tile(int i1, int j1, int i2, int j2, HeightMap* hm) ; | 
|---|
 | 41 |     virtual ~Tile(); | 
|---|
| [6956] | 42 |  | 
|---|
| [7466] | 43 |     int getRes(); | 
|---|
 | 44 |     int setHighRes(bool b); | 
|---|
| [6956] | 45 |  | 
|---|
| [7466] | 46 |     void draw(); | 
|---|
| [7490] | 47 |     inline void drawHighRes() const { highResModel->draw(); } | 
|---|
 | 48 |     inline void drawLowRes() const { lowResModel->draw(); } | 
|---|
| [6956] | 49 |  | 
|---|
| [7466] | 50 |  | 
|---|
 | 51 |   private: | 
|---|
| [7469] | 52 |     void load(int i1, int j1, int i2, int i2, VertexArrayModel* model, int Res); | 
|---|
| [7466] | 53 |  | 
|---|
 | 54 |  | 
|---|
 | 55 |   public: | 
|---|
 | 56 |     float x; | 
|---|
 | 57 |     float z; | 
|---|
 | 58 |  | 
|---|
 | 59 |  | 
|---|
 | 60 |   private: | 
|---|
| [7468] | 61 |     VertexArrayModel*                          highResModel;                      //!< heigh resolution model of the tile | 
|---|
 | 62 |     VertexArrayModel*                          lowResModel;                       //!< low resolution model of the tile | 
|---|
 | 63 |  | 
|---|
| [7469] | 64 |     HeightMap*                                 heightMapReference;                //!< reference to the heightmap this tile belongs to | 
|---|
| [7466] | 65 |     int                                        highRes;                           //!< | 
|---|
 | 66 |     int                                        lowRes;                            //!< | 
|---|
| [6956] | 67 | }; | 
|---|
 | 68 |  | 
|---|
| [7466] | 69 |  | 
|---|
| [9869] | 70 |  | 
|---|
| [7466] | 71 | //!< the height map representation itself | 
|---|
| [6956] | 72 | class HeightMap : public VertexArrayModel | 
|---|
 | 73 | { | 
|---|
| [9869] | 74 |   ObjectListDeclaration(HeightMap); | 
|---|
| [7466] | 75 |   friend class Tile; | 
|---|
| [5967] | 76 |  | 
|---|
| [7466] | 77 |   public: | 
|---|
| [7497] | 78 |     HeightMap(const std::string& heightMapName); | 
|---|
 | 79 |     HeightMap(const std::string& heightMapName, const std::string& colorMapName); | 
|---|
| [7466] | 80 |     virtual ~HeightMap(); | 
|---|
| [6956] | 81 |  | 
|---|
| [7466] | 82 |     void setAbsCoor(Vector V); | 
|---|
 | 83 |     float getHeight(float x, float y); | 
|---|
 | 84 |     float getNormal(float x, float y); | 
|---|
| [5967] | 85 |  | 
|---|
| [7466] | 86 |     void load(); | 
|---|
 | 87 |     void load(int Mode); | 
|---|
 | 88 |     void load(const std::string&, int Mode); | 
|---|
 | 89 |     void scale( Vector V); | 
|---|
| [6956] | 90 |  | 
|---|
| [7498] | 91 |     void draw() const; | 
|---|
| [7466] | 92 |  | 
|---|
 | 93 |  | 
|---|
 | 94 |   private: | 
|---|
| [7526] | 95 |     void init(const std::string& heightMapName); | 
|---|
 | 96 |  | 
|---|
| [7466] | 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: | 
|---|
| [7499] | 110 |     SDL_Surface*                          heightMap;                          //!< image of the height map | 
|---|
 | 111 |     SDL_Surface*                          colorMap;                           //!< image of the color map | 
|---|
| [7466] | 112 |     unsigned char*                        heights; | 
|---|
| [7490] | 113 |     unsigned char*                        colors; | 
|---|
| [7466] | 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; | 
|---|
| [5942] | 136 | }; | 
|---|