ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.17
Committed: Tue Oct 5 03:39:47 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: knowngood
Changes since 1.16: +3 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef ENTITY_H
2 #define ENTITY_H
3
4 #include <GL/gl.h>
5
6 #include <vector>
7
8 #include "util.h"
9 #include "oct.h"
10 #include "view.h"
11
12 using namespace std;
13
14 struct entity_base {
15 struct entity_base *parent;
16 sector orig;
17 vector<octant *> o;
18 box bbox;
19
20 virtual void update ();
21 virtual void show () { world.add (this); };
22 void hide ();
23 void display (draw_context &ctx);
24 virtual void draw (draw_context &ctx) = 0;
25
26 entity_base ();
27 virtual ~entity_base ();
28 };
29
30 struct entity_container : entity_base, protected vector<entity_base *> {
31 void add (entity_base *e)
32 {
33 push_back (e);
34 e->parent = this;
35 update ();
36 }
37
38 void update ();
39 void show ();
40 void draw (draw_context &ctx);
41 ~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 update ();
54 }
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 ();
65 void show ();
66 void draw (draw_context &ctx);
67 ~entity_filter ();
68 };
69
70 struct entity : entity_filter {
71 };
72
73 struct vertex1d {
74 colour c; // colour
75 point p; // vertex
76 };
77
78 struct vertex2d {
79 point p; // vertex
80 vec3 n; // normal
81 texc t; // texture
82
83 vertex2d () { };
84 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
85 };
86
87 struct entity_opengl : entity_base {
88 GLuint list;
89
90 entity_opengl ();
91 ~entity_opengl ();
92 };
93
94 template<GLenum type>
95 struct entity_opengl1d : entity_opengl, vector<vertex1d> {
96 void update ();
97 void draw (draw_context &ctx);
98 };
99
100 template<GLenum type>
101 struct entity_opengl2d : entity_opengl {
102 material m;
103
104 void set (const vector<vertex2d> &v);
105 void draw (draw_context &ctx);
106 };
107
108 typedef entity_opengl1d<GL_POINTS> entity_points;
109 typedef entity_opengl1d<GL_LINES> entity_lines;
110 typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
111 typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop;
112 typedef entity_opengl2d<GL_TRIANGLES> entity_triangles;
113 typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip;
114 typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
115 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
119 struct entity_transform : entity_filter {
120 protected:
121 matrix m;
122 void renormalize ();
123 public:
124
125 entity_transform ();
126
127 void update ();
128 void show ();
129 void draw (draw_context &ctx);
130 void set_matrix (const matrix &xfrm);
131 void update (const matrix &xfrm);
132 };
133
134 struct entity_anim : entity_transform {
135 GLfloat vx, vy, vz;
136 void draw (draw_context &ctx);
137 };
138
139 #endif
140
141
142