| 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 | |
|---|
| 15 | |
|---|
| 16 | #include "vertex_array_model.h" |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #define texRate 32 |
|---|
| 20 | #define texRatef 4.0f |
|---|
| 21 | #define tileSize 64 |
|---|
| 22 | |
|---|
| 23 | class SDL_Surface; |
|---|
| 24 | class Vector; |
|---|
| 25 | class Material; |
|---|
| 26 | class PNode; |
|---|
| 27 | class Texture; |
|---|
| 28 | class HeightMap; |
|---|
| 29 | |
|---|
| 30 | class Tile |
|---|
| 31 | { |
|---|
| 32 | public: |
|---|
| 33 | void draw(); |
|---|
| 34 | void drawHighRes(); |
|---|
| 35 | void drawLowRes(); |
|---|
| 36 | int getRes(); |
|---|
| 37 | int setHighRes(bool b); |
|---|
| 38 | Tile(int i1, int j1, int i2, int j2, HeightMap* hm ) ; |
|---|
| 39 | Tile(); |
|---|
| 40 | float x; |
|---|
| 41 | float z; |
|---|
| 42 | virtual ~Tile(); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | private: |
|---|
| 47 | HeightMap* hmref; |
|---|
| 48 | VertexArrayModel* highResModel; |
|---|
| 49 | VertexArrayModel* lowResModel; |
|---|
| 50 | int highRes; |
|---|
| 51 | int lowRes; |
|---|
| 52 | void load(int i1, int j1, int i2, int i2, HeightMap* hm, VertexArrayModel* model, int Res); |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | class HeightMap : public VertexArrayModel |
|---|
| 56 | { |
|---|
| 57 | public: |
|---|
| 58 | void draw(); |
|---|
| 59 | void load(); |
|---|
| 60 | void load(int Mode); |
|---|
| 61 | void load(const char*, int Mode); |
|---|
| 62 | void scale( Vector V); |
|---|
| 63 | void setAbsCoor(Vector V); |
|---|
| 64 | float getHeight(float x, float y); |
|---|
| 65 | float getNormal(float x, float y); |
|---|
| 66 | HeightMap(); |
|---|
| 67 | HeightMap(const char*); |
|---|
| 68 | HeightMap(const char*, const char*); |
|---|
| 69 | virtual ~HeightMap(); |
|---|
| 70 | |
|---|
| 71 | friend class Tile; |
|---|
| 72 | |
|---|
| 73 | private: |
|---|
| 74 | SDL_Surface* heightMap; |
|---|
| 75 | SDL_Surface* colourMap; |
|---|
| 76 | unsigned char* heights; |
|---|
| 77 | unsigned char* colours; |
|---|
| 78 | |
|---|
| 79 | void generateNormalVectorField(); |
|---|
| 80 | void drawRect(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight ); |
|---|
| 81 | void fixBoarder(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight); |
|---|
| 82 | Vector ** normalVectorField ; |
|---|
| 83 | Tile *** tiles; |
|---|
| 84 | Vector camCoords; |
|---|
| 85 | Vector offsetCoords; |
|---|
| 86 | Material * tmp_mat; |
|---|
| 87 | Material* red_mat; |
|---|
| 88 | Texture* texture; |
|---|
| 89 | const PNode* camera; |
|---|
| 90 | float scaleX ; |
|---|
| 91 | float scaleY ; |
|---|
| 92 | float scaleZ ; |
|---|
| 93 | float shiftX ; // to be removed |
|---|
| 94 | float shiftY ; // to be removed |
|---|
| 95 | float shiftZ ; // to be removed |
|---|
| 96 | float offsetX; |
|---|
| 97 | float offsetY; |
|---|
| 98 | float offsetZ; |
|---|
| 99 | int cmScaleX; |
|---|
| 100 | int cmScaleY; |
|---|
| 101 | bool hasColourMap; |
|---|
| 102 | |
|---|
| 103 | inline int abs(int val) |
|---|
| 104 | { |
|---|
| 105 | if(val < 0) val = -val; |
|---|
| 106 | return val; |
|---|
| 107 | } |
|---|
| 108 | inline int max(int x, int y) |
|---|
| 109 | { |
|---|
| 110 | return (x>y)? x:y; |
|---|
| 111 | } |
|---|
| 112 | inline int min(int x, int y) |
|---|
| 113 | { |
|---|
| 114 | return (x<y)? x: y; |
|---|
| 115 | } |
|---|
| 116 | }; |
|---|