[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 | |
---|
| 22 | #define texRate 32 |
---|
| 23 | #define texRatef 4.0f |
---|
| 24 | #define tileSize 64 |
---|
| 25 | |
---|
[7468] | 26 | //!< define the LOD level distances. later this could be dynamicaly adjusted |
---|
| 27 | #define HM_LOD_LOW_RES 5000 //!< low resolution unless farther away than LOW_RES |
---|
| 28 | #define HM_LOD_HIGH_RES 1000 |
---|
| 29 | |
---|
| 30 | |
---|
[5967] | 31 | class SDL_Surface; |
---|
| 32 | class Vector; |
---|
[6956] | 33 | class Material; |
---|
| 34 | class PNode; |
---|
| 35 | class Texture; |
---|
| 36 | class HeightMap; |
---|
[5942] | 37 | |
---|
[7466] | 38 | |
---|
| 39 | //!< one part of the height map |
---|
[7490] | 40 | class Tile : public PNode |
---|
[5942] | 41 | { |
---|
[7466] | 42 | public: |
---|
| 43 | Tile(int i1, int j1, int i2, int j2, HeightMap* hm) ; |
---|
| 44 | virtual ~Tile(); |
---|
[6956] | 45 | |
---|
[7466] | 46 | int getRes(); |
---|
| 47 | int setHighRes(bool b); |
---|
[6956] | 48 | |
---|
[7466] | 49 | void draw(); |
---|
[7490] | 50 | inline void drawHighRes() const { highResModel->draw(); } |
---|
| 51 | inline void drawLowRes() const { lowResModel->draw(); } |
---|
[6956] | 52 | |
---|
[7466] | 53 | |
---|
| 54 | private: |
---|
[7469] | 55 | void load(int i1, int j1, int i2, int i2, VertexArrayModel* model, int Res); |
---|
[7466] | 56 | |
---|
| 57 | |
---|
| 58 | public: |
---|
| 59 | float x; |
---|
| 60 | float z; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | private: |
---|
[7468] | 64 | VertexArrayModel* highResModel; //!< heigh resolution model of the tile |
---|
| 65 | VertexArrayModel* lowResModel; //!< low resolution model of the tile |
---|
| 66 | |
---|
[7469] | 67 | HeightMap* heightMapReference; //!< reference to the heightmap this tile belongs to |
---|
[7466] | 68 | int highRes; //!< |
---|
| 69 | int lowRes; //!< |
---|
[6956] | 70 | }; |
---|
| 71 | |
---|
[7466] | 72 | |
---|
| 73 | //!< the height map representation itself |
---|
[6956] | 74 | class HeightMap : public VertexArrayModel |
---|
| 75 | { |
---|
[7466] | 76 | friend class Tile; |
---|
[5967] | 77 | |
---|
[7466] | 78 | public: |
---|
[7497] | 79 | HeightMap(const std::string& heightMapName); |
---|
| 80 | HeightMap(const std::string& heightMapName, const std::string& colorMapName); |
---|
[7466] | 81 | virtual ~HeightMap(); |
---|
[6956] | 82 | |
---|
[7497] | 83 | void init(const std::string& heightMapName); |
---|
| 84 | |
---|
[7466] | 85 | void setAbsCoor(Vector V); |
---|
| 86 | float getHeight(float x, float y); |
---|
| 87 | float getNormal(float x, float y); |
---|
[5967] | 88 | |
---|
[7466] | 89 | void load(); |
---|
| 90 | void load(int Mode); |
---|
| 91 | void load(const std::string&, int Mode); |
---|
| 92 | void scale( Vector V); |
---|
[6956] | 93 | |
---|
[7498] | 94 | void draw() const; |
---|
[7466] | 95 | |
---|
| 96 | |
---|
| 97 | private: |
---|
| 98 | void generateNormalVectorField(); |
---|
| 99 | void drawRect(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight ); |
---|
| 100 | void fixBoarder(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight); |
---|
| 101 | |
---|
| 102 | /** helper function absolute value @param val value*/ |
---|
| 103 | inline int abs(int val) { return (val<0)?-val:val; } |
---|
| 104 | /** returns the max of two numbers @param x value 1 @param y value 2*/ |
---|
| 105 | inline int max(int x, int y) { return (x>y)? x:y; } |
---|
| 106 | /** returns the min of two numbers @param x value 1 @param y value 2*/ |
---|
| 107 | inline int min(int x, int y) { return (x<y)? x: y; } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | private: |
---|
[7499] | 111 | SDL_Surface* heightMap; //!< image of the height map |
---|
| 112 | SDL_Surface* colorMap; //!< image of the color map |
---|
[7466] | 113 | unsigned char* heights; |
---|
[7490] | 114 | unsigned char* colors; |
---|
[7466] | 115 | |
---|
| 116 | Vector** normalVectorField; |
---|
| 117 | Tile*** tiles; |
---|
| 118 | Vector camCoords; |
---|
| 119 | Vector offsetCoords; |
---|
| 120 | Material* tmp_mat; |
---|
| 121 | Material* red_mat; |
---|
| 122 | Texture* texture; |
---|
| 123 | const PNode* camera; |
---|
| 124 | |
---|
| 125 | float scaleX ; |
---|
| 126 | float scaleY ; |
---|
| 127 | float scaleZ ; |
---|
| 128 | float shiftX ; // to be removed |
---|
| 129 | float shiftY ; // to be removed |
---|
| 130 | float shiftZ ; // to be removed |
---|
| 131 | float offsetX; |
---|
| 132 | float offsetY; |
---|
| 133 | float offsetZ; |
---|
| 134 | int cmScaleX; |
---|
| 135 | int cmScaleY; |
---|
| 136 | bool hasColourMap; |
---|
[5942] | 137 | }; |
---|