1 |
#ifndef ENTITY_H |
2 |
#define ENTITY_H |
3 |
|
4 |
#include <vector> |
5 |
|
6 |
#include "opengl.h" |
7 |
|
8 |
#include "util.h" |
9 |
#include "oct.h" |
10 |
#include "view.h" |
11 |
#include "material.h" |
12 |
|
13 |
using namespace std; |
14 |
using namespace gl; |
15 |
|
16 |
struct geometry |
17 |
{ |
18 |
geometry *parent; |
19 |
box bbox; |
20 |
|
21 |
virtual void update () |
22 |
{ |
23 |
if (parent) |
24 |
parent->update (); |
25 |
} |
26 |
|
27 |
virtual void draw (view &ctx) = 0; |
28 |
geometry (geometry *parent = 0) : parent(parent) { }; |
29 |
virtual ~geometry (); |
30 |
}; |
31 |
|
32 |
struct geometry_opengl : geometry |
33 |
{ |
34 |
GLuint list; // TODO: dynamic caching |
35 |
|
36 |
geometry_opengl (); |
37 |
~geometry_opengl (); |
38 |
}; |
39 |
|
40 |
template<GLenum type> |
41 |
struct geometry_opengl1d : geometry_opengl, vector<vertex_v3f> |
42 |
{ |
43 |
void set (const vector<vertex_v3f> &v); |
44 |
void draw (view &ctx); |
45 |
}; |
46 |
|
47 |
template<GLenum type> |
48 |
struct geometry_opengl2d : geometry_opengl |
49 |
{ |
50 |
material *m; |
51 |
|
52 |
geometry_opengl2d () : m(0) { }; |
53 |
|
54 |
void set (const vector<vertex_t2f_n3f_v3f> &v); |
55 |
void draw (view &ctx); |
56 |
}; |
57 |
|
58 |
typedef geometry_opengl1d<GL_POINTS> geometry_points; |
59 |
typedef geometry_opengl1d<GL_LINES> geometry_lines; |
60 |
typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip; |
61 |
typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop; |
62 |
typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles; |
63 |
typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip; |
64 |
typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan; |
65 |
typedef geometry_opengl2d<GL_QUADS> geometry_quads; |
66 |
typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip; |
67 |
typedef geometry_opengl2d<GL_POLYGON> geometry_polygon; |
68 |
|
69 |
struct geometry_nurbs : geometry, vector<vertex_t2f_n3f_v3f> |
70 |
{ |
71 |
GLUnurbsObj *nurb; |
72 |
GLUtesselator *tess; |
73 |
GLfloat ctlpoints[4][4][3]; |
74 |
|
75 |
geometry_nurbs() : tess(0), nurb(0) { } |
76 |
virtual void draw (view &ctx); |
77 |
void set (); |
78 |
}; |
79 |
|
80 |
struct geometry_sphere : geometry |
81 |
{ |
82 |
material *m; |
83 |
GLfloat radius; |
84 |
|
85 |
void update (); |
86 |
void draw (view &ctx); |
87 |
geometry_sphere (material *m, GLfloat radius) : m(m), radius(radius) { update (); }; |
88 |
}; |
89 |
|
90 |
///////////////////////////////////////////////////////////////////////////// |
91 |
|
92 |
struct geometry_filter : geometry |
93 |
{ |
94 |
protected: |
95 |
geometry *g; |
96 |
public: |
97 |
|
98 |
void set (geometry *g); |
99 |
|
100 |
geometry *content () { return g; }; |
101 |
|
102 |
void update (); |
103 |
void show (); |
104 |
void draw (view &ctx); |
105 |
geometry_filter (geometry *g = 0) { set (g); } |
106 |
~geometry_filter (); |
107 |
}; |
108 |
|
109 |
struct geometry_transform : geometry_filter |
110 |
{ |
111 |
protected: |
112 |
matrix m; |
113 |
public: |
114 |
void update (); |
115 |
|
116 |
void show (); |
117 |
void draw (view &ctx); |
118 |
void set_matrix (const matrix &xfrm); |
119 |
void update (const matrix &xfrm); |
120 |
|
121 |
geometry_transform (geometry *g) : geometry_filter(g), m(1) { }; |
122 |
geometry_transform () : geometry_filter(0), m(1) { }; |
123 |
}; |
124 |
|
125 |
struct geometry_anim : geometry_transform |
126 |
{ |
127 |
GLfloat vx, vy, vz; |
128 |
void draw (view &ctx); |
129 |
}; |
130 |
|
131 |
struct geometry_container : geometry, protected vector<geometry *> |
132 |
{ |
133 |
void update (); |
134 |
|
135 |
void add (geometry *g); |
136 |
void draw (view &ctx); |
137 |
~geometry_container (); |
138 |
}; |
139 |
|
140 |
///////////////////////////////////////////////////////////////////////////// |
141 |
|
142 |
struct entity : geometry_filter |
143 |
{ |
144 |
sector orig; |
145 |
point p; |
146 |
sector a, b; // bounding box corners |
147 |
|
148 |
vector<octant *> o; |
149 |
|
150 |
void update (); |
151 |
void draw (view &ctx); |
152 |
|
153 |
void move (const vec3 &v); |
154 |
|
155 |
virtual void show (); |
156 |
virtual void hide (); |
157 |
|
158 |
entity (geometry *g = 0); |
159 |
~entity (); |
160 |
}; |
161 |
|
162 |
struct entity_light : entity |
163 |
{ |
164 |
light *lview; |
165 |
}; |
166 |
|
167 |
///////////////////////////////////////////////////////////////////////////// |
168 |
// |
169 |
// VERY EXPERIMENTAL HEIGHTMAP |
170 |
|
171 |
struct geometry_heightfield : geometry |
172 |
{ |
173 |
struct node; |
174 |
|
175 |
node *tree; |
176 |
|
177 |
GLfloat sx, sy, sm; |
178 |
|
179 |
void update (); |
180 |
void draw (view &ctx); |
181 |
geometry_heightfield (GLfloat sx, GLfloat sy); |
182 |
}; |
183 |
|
184 |
#endif |
185 |
|
186 |
|
187 |
|