]> git.tdb.fi Git - r2c2.git/blob - source/3d/terrain.h
Add editable terrain objects
[r2c2.git] / source / 3d / terrain.h
1 #ifndef R2C2_3D_TERRAIN_H_
2 #define R2C2_3D_TERRAIN_H_
3
4 #include <msp/gl/mesh.h>
5 #include <msp/gl/primitivebuilder.h>
6 #include <msp/gl/renderable.h>
7 #include <msp/gl/technique.h>
8 #include "libr2c2/terrain.h"
9 #include "object.h"
10
11 namespace R2C2 {
12
13 class Terrain3D: public Object3D, public Msp::GL::Renderable
14 {
15 private:
16         Terrain &terrain;
17         Msp::GL::Mesh mesh;
18         const Msp::GL::Technique &tech;
19
20         static unsigned surface_indices[];
21         static unsigned wall_indices[];
22
23 public:
24         Terrain3D(Layout3D &, Terrain &);
25         virtual ~Terrain3D();
26
27         virtual Vector get_node() const;
28         virtual bool is_visible() const { return true; }
29
30 private:
31         void create_mesh();
32         void gather_nodes(unsigned, unsigned, Vector *);
33         void build_triangle(Msp::GL::PrimitiveBuilder &, const Vector *, const unsigned *);
34         void update_triangle(unsigned, const Vector *, const unsigned *);
35
36         void size_changed(unsigned, unsigned);
37         void tile_changed(unsigned, unsigned, bool);
38
39 public:
40         virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
41 };
42
43 } // namespace R2C2
44
45 #endif