symmetry

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/terrain.h	Tue Feb 25 23:47:20 2014 +0200
     1.3 @@ -0,0 +1,51 @@
     1.4 +#ifndef TERRAIN_H_
     1.5 +#define TERRAIN_H_
     1.6 +
     1.7 +#include "vmath/vmath.h"
     1.8 +
     1.9 +class Terrain {
    1.10 +private:
    1.11 +	float dx, dy;	// inter-pixel distance in uv-space
    1.12 +	int xsz, ysz;
    1.13 +	float *hmap;
    1.14 +
    1.15 +	float scale, height_scale;
    1.16 +
    1.17 +	mutable int dlist, dlist_norm;
    1.18 +	mutable int dlist_sub[2], dlist_norm_sub[2];
    1.19 +	mutable float dlist_norm_sz;
    1.20 +
    1.21 +	void invalidate_mesh();
    1.22 +
    1.23 +public:
    1.24 +	Terrain();
    1.25 +	~Terrain();
    1.26 +
    1.27 +	void set_scale(float s);
    1.28 +	float get_scale() const;
    1.29 +
    1.30 +	void set_height_scale(float s);
    1.31 +	float get_height_scale() const;
    1.32 +
    1.33 +	bool load(const char *fname);
    1.34 +	int get_map_width() const { return xsz; }
    1.35 +	int get_map_height() const { return ysz; }
    1.36 +
    1.37 +	Vector2 world_to_uv(const Vector2 &pt) const;
    1.38 +	Vector2 uv_to_world(const Vector2 &pt) const;
    1.39 +
    1.40 +	float lookup(int x, int y) const;
    1.41 +
    1.42 +	float get_height(const Vector2 &pt) const;
    1.43 +	Vector3 get_normal(const Vector2 &pt) const;
    1.44 +
    1.45 +	float get_world_height(const Vector2 &pt) const;
    1.46 +
    1.47 +	bool intersect(const Ray &ray, float *dist) const;
    1.48 +	bool intersect_micro(const Ray &ray, float *dist, float thres = 0.01) const;
    1.49 +
    1.50 +	void draw(int usub = 0, int vsub = 0) const;
    1.51 +	void draw_normals(float sz = 1.0, int usub = 0, int vsub = 0) const;
    1.52 +};
    1.53 +
    1.54 +#endif	// TERRAIN_H_