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.4 |
void add (entity_base *e) { push_back (e); e->parent = this; } |
32 |
root |
1.1 |
void update_bbox (); |
33 |
root |
1.10 |
void show (); |
34 |
root |
1.8 |
void draw (draw_context &ctx); |
35 |
root |
1.1 |
~entity_container (); |
36 |
|
|
}; |
37 |
|
|
|
38 |
|
|
struct entity_filter : entity_base { |
39 |
|
|
protected: |
40 |
|
|
entity_base *e; |
41 |
|
|
public: |
42 |
|
|
|
43 |
|
|
void set (entity_base *e) |
44 |
|
|
{ |
45 |
|
|
this->e = e; |
46 |
|
|
e->parent = this; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
void remove () |
50 |
|
|
{ |
51 |
|
|
this->e->parent = 0; |
52 |
|
|
this->e = 0; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
entity_base *content () { return e; }; |
56 |
|
|
|
57 |
|
|
void update_bbox (); |
58 |
root |
1.10 |
void show (); |
59 |
root |
1.8 |
void draw (draw_context &ctx); |
60 |
root |
1.1 |
~entity_filter (); |
61 |
|
|
}; |
62 |
|
|
|
63 |
|
|
struct entity : entity_filter { |
64 |
|
|
}; |
65 |
|
|
|
66 |
|
|
struct vertex1d { |
67 |
root |
1.3 |
colour c; // colour |
68 |
root |
1.2 |
point p; // vertex |
69 |
root |
1.1 |
}; |
70 |
|
|
|
71 |
|
|
struct vertex2d { |
72 |
root |
1.6 |
point p; // vertex |
73 |
|
|
vec3 n; // normal |
74 |
|
|
texc t; // texture |
75 |
root |
1.3 |
|
76 |
|
|
vertex2d () { }; |
77 |
root |
1.6 |
vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; |
78 |
|
|
}; |
79 |
|
|
|
80 |
|
|
struct entity_opengl : entity_base { |
81 |
root |
1.13 |
GLuint list; |
82 |
|
|
|
83 |
|
|
entity_opengl (); |
84 |
|
|
~entity_opengl (); |
85 |
root |
1.1 |
}; |
86 |
|
|
|
87 |
|
|
template<GLenum type> |
88 |
root |
1.6 |
struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
89 |
root |
1.1 |
void update_bbox (); |
90 |
root |
1.8 |
void draw (draw_context &ctx); |
91 |
root |
1.1 |
}; |
92 |
|
|
|
93 |
|
|
template<GLenum type> |
94 |
root |
1.13 |
struct entity_opengl2d : entity_opengl { |
95 |
root |
1.6 |
material m; |
96 |
|
|
|
97 |
root |
1.13 |
void set (const vector<vertex2d> &v); |
98 |
root |
1.8 |
void draw (draw_context &ctx); |
99 |
root |
1.1 |
}; |
100 |
|
|
|
101 |
|
|
typedef entity_opengl1d<GL_POINTS> entity_points; |
102 |
|
|
typedef entity_opengl1d<GL_LINES> entity_lines; |
103 |
root |
1.2 |
typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
104 |
|
|
typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop; |
105 |
root |
1.1 |
typedef entity_opengl2d<GL_TRIANGLES> entity_triangles; |
106 |
root |
1.2 |
typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip; |
107 |
|
|
typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
108 |
root |
1.1 |
typedef entity_opengl2d<GL_QUADS> entity_quads; |
109 |
|
|
typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
110 |
|
|
typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
111 |
root |
1.11 |
|
112 |
|
|
struct entity_transform : entity_filter { |
113 |
|
|
gl_matrix m; |
114 |
|
|
|
115 |
|
|
entity_transform (); |
116 |
|
|
|
117 |
|
|
void update_bbox (); |
118 |
|
|
void show (); |
119 |
|
|
void draw (draw_context &ctx); |
120 |
|
|
}; |
121 |
root |
1.1 |
|
122 |
root |
1.12 |
struct entity_anim : entity_transform { |
123 |
|
|
GLfloat vx, vy, vz; |
124 |
|
|
void draw (draw_context &ctx); |
125 |
|
|
}; |
126 |
|
|
|
127 |
root |
1.1 |
#endif |
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|