ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/entity.h
Revision: 1.19
Committed: Thu Oct 7 23:39:43 2004 UTC (22 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.18: +76 -74 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 root 1.8 #include "view.h"
11 root 1.1
12     using namespace std;
13    
14 root 1.19 struct geometry {
15     geometry *parent;
16 root 1.1 box bbox;
17    
18 root 1.19 virtual void update ()
19 root 1.15 {
20 root 1.19 if (parent)
21     parent->update ();
22 root 1.15 }
23    
24 root 1.19 virtual void draw (view &ctx) = 0;
25     geometry (geometry *parent = 0) : parent(parent) { };
26     virtual ~geometry ();
27 root 1.1 };
28    
29     struct vertex1d {
30 root 1.3 colour c; // colour
31 root 1.2 point p; // vertex
32 root 1.1 };
33    
34     struct vertex2d {
35 root 1.6 point p; // vertex
36     vec3 n; // normal
37     texc t; // texture
38 root 1.3
39     vertex2d () { };
40 root 1.6 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
41     };
42    
43 root 1.19 struct geometry_opengl : geometry {
44     GLuint list; // TODO: dynamic caching
45 root 1.13
46 root 1.19 geometry_opengl ();
47     ~geometry_opengl ();
48 root 1.1 };
49    
50     template<GLenum type>
51 root 1.19 struct geometry_opengl1d : geometry_opengl, vector<vertex1d> {
52     void set (const vector<vertex1d> &v);
53 root 1.18 void draw (view &ctx);
54 root 1.1 };
55    
56     template<GLenum type>
57 root 1.19 struct geometry_opengl2d : geometry_opengl {
58 root 1.6 material m;
59    
60 root 1.13 void set (const vector<vertex2d> &v);
61 root 1.18 void draw (view &ctx);
62 root 1.1 };
63    
64 root 1.19 typedef geometry_opengl1d<GL_POINTS> geometry_points;
65     typedef geometry_opengl1d<GL_LINES> geometry_lines;
66     typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip;
67     typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop;
68     typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles;
69     typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip;
70     typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan;
71     typedef geometry_opengl2d<GL_QUADS> geometry_quads;
72     typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip;
73     typedef geometry_opengl2d<GL_POLYGON> geometry_polygon;
74 root 1.11
75 root 1.19 struct geometry_filter : geometry {
76 root 1.16 protected:
77 root 1.19 geometry *g;
78 root 1.16 public:
79 root 1.11
80 root 1.19 void set (geometry *g);
81    
82     geometry *content () { return g; };
83 root 1.11
84 root 1.16 void update ();
85 root 1.11 void show ();
86 root 1.18 void draw (view &ctx);
87 root 1.19 geometry_filter (geometry *g = 0) { set (g); }
88     ~geometry_filter ();
89     };
90    
91     struct geometry_transform : geometry_filter {
92     protected:
93     matrix m;
94     public:
95     void update ();
96    
97     void show ();
98     void draw (view &ctx);
99 root 1.17 void set_matrix (const matrix &xfrm);
100     void update (const matrix &xfrm);
101 root 1.19
102     geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
103     geometry_transform () : geometry_filter(0), m(1) { };
104 root 1.11 };
105 root 1.1
106 root 1.19 struct geometry_anim : geometry_transform {
107 root 1.12 GLfloat vx, vy, vz;
108 root 1.18 void draw (view &ctx);
109 root 1.19 };
110    
111     struct geometry_container : geometry, protected vector<geometry *> {
112     void update ();
113    
114     void add (geometry *g);
115     void draw (view &ctx);
116     ~geometry_container ();
117     };
118    
119     /////////////////////////////////////////////////////////////////////////////
120    
121     struct entity : geometry_filter {
122     sector orig;
123     point p;
124     sector a, b; // bounding box corners
125    
126     vector<octant *> o;
127    
128     void update ();
129     void draw (view &ctx);
130    
131     void move (const vec3 &v);
132    
133     virtual void show () { if (!o.size ()) world.add (this); };
134     void hide ();
135     void display (view &ctx);
136    
137     entity (geometry *g = 0);
138     ~entity ();
139 root 1.12 };
140    
141 root 1.1 #endif
142    
143    
144