symmetry

view src/terrain.h @ 1:46fe847bba08

using goat3dgfx
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 25 Feb 2014 23:47:20 +0200
parents
children
line source
1 #ifndef TERRAIN_H_
2 #define TERRAIN_H_
4 #include "vmath/vmath.h"
6 class Terrain {
7 private:
8 float dx, dy; // inter-pixel distance in uv-space
9 int xsz, ysz;
10 float *hmap;
12 float scale, height_scale;
14 mutable int dlist, dlist_norm;
15 mutable int dlist_sub[2], dlist_norm_sub[2];
16 mutable float dlist_norm_sz;
18 void invalidate_mesh();
20 public:
21 Terrain();
22 ~Terrain();
24 void set_scale(float s);
25 float get_scale() const;
27 void set_height_scale(float s);
28 float get_height_scale() const;
30 bool load(const char *fname);
31 int get_map_width() const { return xsz; }
32 int get_map_height() const { return ysz; }
34 Vector2 world_to_uv(const Vector2 &pt) const;
35 Vector2 uv_to_world(const Vector2 &pt) const;
37 float lookup(int x, int y) const;
39 float get_height(const Vector2 &pt) const;
40 Vector3 get_normal(const Vector2 &pt) const;
42 float get_world_height(const Vector2 &pt) const;
44 bool intersect(const Ray &ray, float *dist) const;
45 bool intersect_micro(const Ray &ray, float *dist, float thres = 0.01) const;
47 void draw(int usub = 0, int vsub = 0) const;
48 void draw_normals(float sz = 1.0, int usub = 0, int vsub = 0) const;
49 };
51 #endif // TERRAIN_H_