ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.35
Committed: Tue Aug 9 23:58:43 2005 UTC (18 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.34: +21 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #ifndef ENTITY_H
2     #define ENTITY_H
3    
4 root 1.22 #include <vector>
5 root 1.1
6 root 1.32 #include <iostream>
7 root 1.22 #include "opengl.h"
8 root 1.1
9 root 1.5 #include "util.h"
10 root 1.1 #include "oct.h"
11 root 1.8 #include "view.h"
12 root 1.22 #include "material.h"
13 root 1.1
14     using namespace std;
15 root 1.24 using namespace gl;
16 root 1.1
17 root 1.22 struct geometry
18     {
19 root 1.19 geometry *parent;
20 root 1.1 box bbox;
21    
22 root 1.19 virtual void update ()
23 root 1.15 {
24 root 1.19 if (parent)
25     parent->update ();
26 root 1.15 }
27    
28 root 1.19 virtual void draw (view &ctx) = 0;
29     geometry (geometry *parent = 0) : parent(parent) { };
30     virtual ~geometry ();
31 root 1.1 };
32    
33 root 1.22 struct geometry_opengl : geometry
34     {
35 root 1.19 GLuint list; // TODO: dynamic caching
36 root 1.13
37 root 1.19 geometry_opengl ();
38     ~geometry_opengl ();
39 root 1.1 };
40    
41     template<GLenum type>
42 root 1.24 struct geometry_opengl1d : geometry_opengl, vector<vertex_v3f>
43 root 1.22 {
44 root 1.24 void set (const vector<vertex_v3f> &v);
45 root 1.18 void draw (view &ctx);
46 root 1.1 };
47    
48     template<GLenum type>
49 root 1.22 struct geometry_opengl2d : geometry_opengl
50     {
51     material *m;
52    
53     geometry_opengl2d () : m(0) { };
54 root 1.6
55 root 1.24 void set (const vector<vertex_t2f_n3f_v3f> &v);
56 root 1.18 void draw (view &ctx);
57 root 1.1 };
58    
59 root 1.19 typedef geometry_opengl1d<GL_POINTS> geometry_points;
60     typedef geometry_opengl1d<GL_LINES> geometry_lines;
61     typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip;
62     typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop;
63     typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles;
64     typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip;
65     typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan;
66     typedef geometry_opengl2d<GL_QUADS> geometry_quads;
67     typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip;
68     typedef geometry_opengl2d<GL_POLYGON> geometry_polygon;
69 root 1.20
70 root 1.24 struct geometry_nurbs : geometry, vector<vertex_t2f_n3f_v3f>
71 root 1.22 {
72 root 1.20 GLUnurbsObj *nurb;
73 root 1.21 GLUtesselator *tess;
74 root 1.20 GLfloat ctlpoints[4][4][3];
75    
76 root 1.21 geometry_nurbs() : tess(0), nurb(0) { }
77 root 1.20 virtual void draw (view &ctx);
78     void set ();
79     };
80 root 1.11
81 root 1.23 struct geometry_sphere : geometry
82     {
83 root 1.31 material *m;
84 root 1.23 GLfloat radius;
85    
86     void update ();
87     void draw (view &ctx);
88 root 1.31 geometry_sphere (material *m, GLfloat radius) : m(m), radius(radius) { update (); };
89 root 1.32 };
90    
91     struct geometry_indexed_2d : geometry
92     {
93     material *m;
94    
95     GLenum type;
96    
97     vertex_buffer vb;
98     index_buffer ib;
99    
100     void draw (view &ctx);
101    
102     template <typename vertex, typename index>
103     geometry_indexed_2d (material *m, GLenum type, const vector<vertex> &v, const vector<index> &i)
104 root 1.33 : m(m), type(type)
105 root 1.32 {
106     vb.set (v);
107 root 1.33 ib.set (i);
108 root 1.32
109 root 1.33 bbox.reset ();
110     for (typename vector<vertex>::const_iterator i = v.begin () ; i != v.end (); ++i)
111     bbox.add (i->v);
112 root 1.32 }
113    
114 root 1.23 };
115    
116     /////////////////////////////////////////////////////////////////////////////
117    
118 root 1.22 struct geometry_filter : geometry
119     {
120 root 1.16 protected:
121 root 1.19 geometry *g;
122 root 1.16 public:
123 root 1.11
124 root 1.19 void set (geometry *g);
125    
126     geometry *content () { return g; };
127 root 1.11
128 root 1.16 void update ();
129 root 1.11 void show ();
130 root 1.18 void draw (view &ctx);
131 root 1.19 geometry_filter (geometry *g = 0) { set (g); }
132     ~geometry_filter ();
133     };
134    
135 root 1.22 struct geometry_transform : geometry_filter
136     {
137 root 1.19 protected:
138     matrix m;
139     public:
140     void update ();
141    
142     void show ();
143     void draw (view &ctx);
144 root 1.17 void set_matrix (const matrix &xfrm);
145     void update (const matrix &xfrm);
146 root 1.19
147     geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
148     geometry_transform () : geometry_filter(0), m(1) { };
149 root 1.11 };
150 root 1.1
151 root 1.22 struct geometry_anim : geometry_transform
152     {
153 root 1.12 GLfloat vx, vy, vz;
154 root 1.18 void draw (view &ctx);
155 root 1.19 };
156    
157 root 1.22 struct geometry_container : geometry, protected vector<geometry *>
158     {
159 root 1.19 void update ();
160    
161     void add (geometry *g);
162     void draw (view &ctx);
163     ~geometry_container ();
164     };
165    
166     /////////////////////////////////////////////////////////////////////////////
167    
168 root 1.22 struct entity : geometry_filter
169     {
170 root 1.19 sector orig;
171     point p;
172     sector a, b; // bounding box corners
173    
174     vector<octant *> o;
175    
176     void update ();
177     void draw (view &ctx);
178    
179     void move (const vec3 &v);
180    
181 root 1.22 virtual void show ();
182     virtual void hide ();
183 root 1.19
184     entity (geometry *g = 0);
185     ~entity ();
186 root 1.12 };
187 root 1.22
188 root 1.34 struct entity_moveable : entity
189     {
190     vec3 v;
191     entity_moveable (geometry *g = 0) : entity (g) { }
192    
193     void perform_step (double t);
194     };
195    
196 root 1.30 struct entity_light : entity
197 root 1.22 {
198 root 1.30 light *lview;
199 root 1.22 };
200    
201 root 1.27 /////////////////////////////////////////////////////////////////////////////
202 root 1.35 // not the final API(!)
203    
204     struct skybox
205     {
206     texture *tex[6];
207    
208     skybox (
209     const char *left,
210     const char *front,
211     const char *right,
212     const char *back,
213     const char *top,
214     const char *bottom
215     );
216    
217     ~skybox ();
218    
219     void draw (view &ctx);
220     };
221    
222     /////////////////////////////////////////////////////////////////////////////
223 root 1.27 //
224     // VERY EXPERIMENTAL HEIGHTMAP
225    
226     struct geometry_heightfield : geometry
227     {
228     struct node;
229    
230     node *tree;
231    
232 root 1.29 GLfloat sx, sy, sm;
233    
234 root 1.27 void update ();
235     void draw (view &ctx);
236 root 1.28 geometry_heightfield (GLfloat sx, GLfloat sy);
237 root 1.27 };
238    
239 root 1.1 #endif
240    
241    
242