ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.7
Committed: Sun Oct 3 03:19:56 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.6: +5 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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    
11     using namespace std;
12    
13     struct entity_base {
14     struct entity_base *parent;
15     vector<octant *> o;
16     box bbox;
17    
18     virtual void update_bbox ();
19     virtual void show (const sector &sec) { };
20     void hide ();
21 root 1.5 virtual void draw (const draw_context &ctx) = 0;
22 root 1.1 virtual ~entity_base ()
23     {
24     hide ();
25     };
26     };
27    
28     struct entity_container : entity_base, protected vector<entity_base *> {
29 root 1.4 void add (entity_base *e) { push_back (e); e->parent = this; }
30 root 1.1 void update_bbox ();
31     void show (const sector &sec);
32 root 1.5 void draw (const draw_context &ctx);
33 root 1.1 ~entity_container ();
34     };
35    
36     struct entity_filter : entity_base {
37     protected:
38     entity_base *e;
39     public:
40    
41     void set (entity_base *e)
42     {
43     this->e = e;
44     e->parent = this;
45     }
46    
47     void remove ()
48     {
49     this->e->parent = 0;
50     this->e = 0;
51     }
52    
53     entity_base *content () { return e; };
54    
55     void update_bbox ();
56     void show (const sector &sec);
57 root 1.5 void draw (const draw_context &ctx);
58 root 1.1 ~entity_filter ();
59     };
60    
61     struct entity : entity_filter {
62     sector sec;
63    
64     void show (const sector &sec);
65 root 1.3 void show ();
66 root 1.5 void draw (const draw_context &ctx);
67 root 1.1 };
68    
69 root 1.7 #if 0
70 root 1.1 struct entity_affine : entity_filter {
71 root 1.7 GLfloat m[4][4];
72    
73     void draw (const draw_context &ctx);
74 root 1.1 };
75 root 1.7 #endif
76 root 1.1
77     struct vertex1d {
78 root 1.3 colour c; // colour
79 root 1.2 point p; // vertex
80 root 1.1 };
81    
82     struct vertex2d {
83 root 1.6 point p; // vertex
84     vec3 n; // normal
85     texc t; // texture
86 root 1.3
87     vertex2d () { };
88 root 1.6 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
89     };
90    
91     struct entity_opengl : entity_base {
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     void show (const sector &sec);
98 root 1.5 void draw (const draw_context &ctx);
99 root 1.1 };
100    
101     template<GLenum type>
102 root 1.6 struct entity_opengl2d : entity_opengl, vector<vertex2d> {
103     material m;
104    
105 root 1.1 void update_bbox ();
106     void show (const sector &sec);
107 root 1.5 void draw (const draw_context &ctx);
108 root 1.1 };
109    
110     typedef entity_opengl1d<GL_POINTS> entity_points;
111     typedef entity_opengl1d<GL_LINES> entity_lines;
112 root 1.2 typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
113     typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop;
114 root 1.1 typedef entity_opengl2d<GL_TRIANGLES> entity_triangles;
115 root 1.2 typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip;
116     typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
117 root 1.1 typedef entity_opengl2d<GL_QUADS> entity_quads;
118     typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
119     typedef entity_opengl2d<GL_POLYGON> entity_polygon;
120 root 1.2
121     struct view {
122     point p;
123 root 1.3 vec3 d, u;
124 root 1.2 float fov;
125 root 1.3 int w, h;
126 root 1.2
127 root 1.5 void draw (const draw_context &ctx);
128 root 1.2 };
129 root 1.1
130     #endif
131    
132    
133