ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.27
Committed: Fri Oct 29 22:32:49 2004 UTC (19 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.26: +15 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef ENTITY_H
2 #define ENTITY_H
3
4 #include <vector>
5
6 #include "opengl.h"
7
8 #include "util.h"
9 #include "oct.h"
10 #include "view.h"
11 #include "material.h"
12
13 using namespace std;
14 using namespace gl;
15
16 struct geometry
17 {
18 geometry *parent;
19 box bbox;
20
21 virtual void update ()
22 {
23 if (parent)
24 parent->update ();
25 }
26
27 virtual void draw (view &ctx) = 0;
28 geometry (geometry *parent = 0) : parent(parent) { };
29 virtual ~geometry ();
30 };
31
32 struct geometry_opengl : geometry
33 {
34 GLuint list; // TODO: dynamic caching
35
36 geometry_opengl ();
37 ~geometry_opengl ();
38 };
39
40 template<GLenum type>
41 struct geometry_opengl1d : geometry_opengl, vector<vertex_v3f>
42 {
43 void set (const vector<vertex_v3f> &v);
44 void draw (view &ctx);
45 };
46
47 template<GLenum type>
48 struct geometry_opengl2d : geometry_opengl
49 {
50 material *m;
51
52 geometry_opengl2d () : m(0) { };
53
54 void set (const vector<vertex_t2f_n3f_v3f> &v);
55 void draw (view &ctx);
56 };
57
58 typedef geometry_opengl1d<GL_POINTS> geometry_points;
59 typedef geometry_opengl1d<GL_LINES> geometry_lines;
60 typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip;
61 typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop;
62 typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles;
63 typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip;
64 typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan;
65 typedef geometry_opengl2d<GL_QUADS> geometry_quads;
66 typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip;
67 typedef geometry_opengl2d<GL_POLYGON> geometry_polygon;
68
69 struct geometry_nurbs : geometry, vector<vertex_t2f_n3f_v3f>
70 {
71 GLUnurbsObj *nurb;
72 GLUtesselator *tess;
73 GLfloat ctlpoints[4][4][3];
74
75 geometry_nurbs() : tess(0), nurb(0) { }
76 virtual void draw (view &ctx);
77 void set ();
78 };
79
80 struct geometry_sphere : geometry
81 {
82 GLfloat radius;
83
84 void update ();
85 void draw (view &ctx);
86 geometry_sphere (GLfloat radius) : radius(radius) { update (); };
87 };
88
89 /////////////////////////////////////////////////////////////////////////////
90
91 struct geometry_filter : geometry
92 {
93 protected:
94 geometry *g;
95 public:
96
97 void set (geometry *g);
98
99 geometry *content () { return g; };
100
101 void update ();
102 void show ();
103 void draw (view &ctx);
104 geometry_filter (geometry *g = 0) { set (g); }
105 ~geometry_filter ();
106 };
107
108 struct geometry_transform : geometry_filter
109 {
110 protected:
111 matrix m;
112 public:
113 void update ();
114
115 void show ();
116 void draw (view &ctx);
117 void set_matrix (const matrix &xfrm);
118 void update (const matrix &xfrm);
119
120 geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
121 geometry_transform () : geometry_filter(0), m(1) { };
122 };
123
124 struct geometry_anim : geometry_transform
125 {
126 GLfloat vx, vy, vz;
127 void draw (view &ctx);
128 };
129
130 struct geometry_container : geometry, protected vector<geometry *>
131 {
132 void update ();
133
134 void add (geometry *g);
135 void draw (view &ctx);
136 ~geometry_container ();
137 };
138
139 /////////////////////////////////////////////////////////////////////////////
140
141 struct entity : geometry_filter
142 {
143 sector orig;
144 point p;
145 sector a, b; // bounding box corners
146
147 vector<octant *> o;
148
149 void update ();
150 void draw (view &ctx);
151
152 void move (const vec3 &v);
153
154 virtual void show ();
155 virtual void hide ();
156
157 entity (geometry *g = 0);
158 ~entity ();
159 };
160
161 struct light : entity
162 {
163 point p;
164 colour c;
165 GLfloat intensity;
166 GLfloat radius;
167 };
168
169 /////////////////////////////////////////////////////////////////////////////
170 //
171 // VERY EXPERIMENTAL HEIGHTMAP
172
173 struct geometry_heightfield : geometry
174 {
175 struct node;
176
177 node *tree;
178
179 void update ();
180 void draw (view &ctx);
181 geometry_heightfield ();
182 };
183
184 #endif
185
186
187