Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/height_map.h @ 7526

Last change on this file since 7526 was 7526, checked in by patrick, 18 years ago

orxonox: work flush on hm

  • Property svn:executable set to *
File size: 4.4 KB
Line 
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
30class SDL_Surface;
31class Vector;
32class Material;
33class PNode;
34class Texture;
35class HeightMap;
36
37
38//!< one part of the height map
39class Tile : public PNode
40{
41  public:
42    Tile(int i1, int j1, int i2, int j2, HeightMap* hm) ;
43    virtual ~Tile();
44
45    int getRes();
46    int setHighRes(bool b);
47
48    void draw();
49    inline void drawHighRes() const { highResModel->draw(); }
50    inline void drawLowRes() const { lowResModel->draw(); }
51
52
53  private:
54    void load(int i1, int j1, int i2, int i2, VertexArrayModel* model, int Res);
55
56
57  public:
58    float x;
59    float z;
60
61
62  private:
63    VertexArrayModel*                          highResModel;                      //!< heigh resolution model of the tile
64    VertexArrayModel*                          lowResModel;                       //!< low resolution model of the tile
65
66    HeightMap*                                 heightMapReference;                //!< reference to the heightmap this tile belongs to
67    int                                        highRes;                           //!<
68    int                                        lowRes;                            //!<
69};
70
71
72//!< the height map representation itself
73class HeightMap : public VertexArrayModel
74{
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};
Note: See TracBrowser for help on using the repository browser.