ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.8
Committed: Sun Oct 3 05:10:45 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.7: +9 -16 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 vector<octant *> o;
17 box bbox;
18
19 virtual void update_bbox ();
20 virtual void show (const sector &sec) { };
21 void hide ();
22 virtual void draw (draw_context &ctx) = 0;
23 void try_draw (draw_context &ctx) { if (ctx.may_draw (this)) draw (ctx); }
24 virtual ~entity_base ()
25 {
26 hide ();
27 };
28 };
29
30 struct entity_container : entity_base, protected vector<entity_base *> {
31 void add (entity_base *e) { push_back (e); e->parent = this; }
32 void update_bbox ();
33 void show (const sector &sec);
34 void draw (draw_context &ctx);
35 ~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 void show (const sector &sec);
59 void draw (draw_context &ctx);
60 ~entity_filter ();
61 };
62
63 struct entity : entity_filter {
64 sector sec;
65
66 void show (const sector &sec);
67 void show ();
68 void draw (draw_context &ctx);
69 };
70
71 #if 0
72 struct entity_affine : entity_filter {
73 GLfloat m[4][4];
74
75 void draw (draw_context &ctx);
76 };
77 #endif
78
79 struct vertex1d {
80 colour c; // colour
81 point p; // vertex
82 };
83
84 struct vertex2d {
85 point p; // vertex
86 vec3 n; // normal
87 texc t; // texture
88
89 vertex2d () { };
90 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
91 };
92
93 struct entity_opengl : entity_base {
94 };
95
96 template<GLenum type>
97 struct entity_opengl1d : entity_opengl, vector<vertex1d> {
98 void update_bbox ();
99 void show (const sector &sec);
100 void draw (draw_context &ctx);
101 };
102
103 template<GLenum type>
104 struct entity_opengl2d : entity_opengl, vector<vertex2d> {
105 material m;
106
107 void update_bbox ();
108 void show (const sector &sec);
109 void draw (draw_context &ctx);
110 };
111
112 typedef entity_opengl1d<GL_POINTS> entity_points;
113 typedef entity_opengl1d<GL_LINES> entity_lines;
114 typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
115 typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop;
116 typedef entity_opengl2d<GL_TRIANGLES> entity_triangles;
117 typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip;
118 typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
119 typedef entity_opengl2d<GL_QUADS> entity_quads;
120 typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
121 typedef entity_opengl2d<GL_POLYGON> entity_polygon;
122
123 #endif
124
125
126