1 |
root |
1.1 |
#ifndef ENTITY_H |
2 |
|
|
#define ENTITY_H |
3 |
|
|
|
4 |
|
|
#include <GL/gl.h> |
5 |
|
|
|
6 |
|
|
#include <vector> |
7 |
|
|
|
8 |
root |
1.5 |
#include "util.h" |
9 |
root |
1.1 |
#include "oct.h" |
10 |
root |
1.8 |
#include "view.h" |
11 |
root |
1.1 |
|
12 |
|
|
using namespace std; |
13 |
|
|
|
14 |
|
|
struct entity_base { |
15 |
|
|
struct entity_base *parent; |
16 |
root |
1.10 |
sector orig; |
17 |
root |
1.1 |
vector<octant *> o; |
18 |
|
|
box bbox; |
19 |
|
|
|
20 |
|
|
virtual void update_bbox (); |
21 |
root |
1.11 |
virtual void show () { world.add (this); }; |
22 |
root |
1.1 |
void hide (); |
23 |
root |
1.10 |
void display (draw_context &ctx); |
24 |
root |
1.8 |
virtual void draw (draw_context &ctx) = 0; |
25 |
root |
1.10 |
|
26 |
|
|
entity_base (); |
27 |
|
|
virtual ~entity_base (); |
28 |
root |
1.1 |
}; |
29 |
|
|
|
30 |
|
|
struct entity_container : entity_base, protected vector<entity_base *> { |
31 |
root |
1.15 |
void add (entity_base *e) |
32 |
|
|
{ |
33 |
|
|
push_back (e); |
34 |
|
|
e->parent = this; |
35 |
|
|
update_bbox (); |
36 |
|
|
} |
37 |
|
|
|
38 |
root |
1.1 |
void update_bbox (); |
39 |
root |
1.10 |
void show (); |
40 |
root |
1.8 |
void draw (draw_context &ctx); |
41 |
root |
1.1 |
~entity_container (); |
42 |
|
|
}; |
43 |
|
|
|
44 |
|
|
struct entity_filter : entity_base { |
45 |
|
|
protected: |
46 |
|
|
entity_base *e; |
47 |
|
|
public: |
48 |
|
|
|
49 |
|
|
void set (entity_base *e) |
50 |
|
|
{ |
51 |
|
|
this->e = e; |
52 |
|
|
e->parent = this; |
53 |
root |
1.15 |
update_bbox (); |
54 |
root |
1.1 |
} |
55 |
|
|
|
56 |
|
|
void remove () |
57 |
|
|
{ |
58 |
|
|
this->e->parent = 0; |
59 |
|
|
this->e = 0; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
entity_base *content () { return e; }; |
63 |
|
|
|
64 |
|
|
void update_bbox (); |
65 |
root |
1.10 |
void show (); |
66 |
root |
1.8 |
void draw (draw_context &ctx); |
67 |
root |
1.1 |
~entity_filter (); |
68 |
|
|
}; |
69 |
|
|
|
70 |
|
|
struct entity : entity_filter { |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
|
struct vertex1d { |
74 |
root |
1.3 |
colour c; // colour |
75 |
root |
1.2 |
point p; // vertex |
76 |
root |
1.1 |
}; |
77 |
|
|
|
78 |
|
|
struct vertex2d { |
79 |
root |
1.6 |
point p; // vertex |
80 |
|
|
vec3 n; // normal |
81 |
|
|
texc t; // texture |
82 |
root |
1.3 |
|
83 |
|
|
vertex2d () { }; |
84 |
root |
1.6 |
vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; |
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
struct entity_opengl : entity_base { |
88 |
root |
1.13 |
GLuint list; |
89 |
|
|
|
90 |
|
|
entity_opengl (); |
91 |
|
|
~entity_opengl (); |
92 |
root |
1.1 |
}; |
93 |
|
|
|
94 |
|
|
template<GLenum type> |
95 |
root |
1.6 |
struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
96 |
root |
1.1 |
void update_bbox (); |
97 |
root |
1.8 |
void draw (draw_context &ctx); |
98 |
root |
1.1 |
}; |
99 |
|
|
|
100 |
|
|
template<GLenum type> |
101 |
root |
1.13 |
struct entity_opengl2d : entity_opengl { |
102 |
root |
1.6 |
material m; |
103 |
|
|
|
104 |
root |
1.13 |
void set (const vector<vertex2d> &v); |
105 |
root |
1.8 |
void draw (draw_context &ctx); |
106 |
root |
1.1 |
}; |
107 |
|
|
|
108 |
|
|
typedef entity_opengl1d<GL_POINTS> entity_points; |
109 |
|
|
typedef entity_opengl1d<GL_LINES> entity_lines; |
110 |
root |
1.2 |
typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
111 |
|
|
typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop; |
112 |
root |
1.1 |
typedef entity_opengl2d<GL_TRIANGLES> entity_triangles; |
113 |
root |
1.2 |
typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip; |
114 |
|
|
typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
115 |
root |
1.1 |
typedef entity_opengl2d<GL_QUADS> entity_quads; |
116 |
|
|
typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
117 |
|
|
typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
118 |
root |
1.11 |
|
119 |
|
|
struct entity_transform : entity_filter { |
120 |
|
|
gl_matrix m; |
121 |
|
|
|
122 |
|
|
entity_transform (); |
123 |
|
|
|
124 |
|
|
void update_bbox (); |
125 |
|
|
void show (); |
126 |
|
|
void draw (draw_context &ctx); |
127 |
|
|
}; |
128 |
root |
1.1 |
|
129 |
root |
1.12 |
struct entity_anim : entity_transform { |
130 |
|
|
GLfloat vx, vy, vz; |
131 |
|
|
void draw (draw_context &ctx); |
132 |
|
|
}; |
133 |
|
|
|
134 |
root |
1.1 |
#endif |
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|