ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.20
Committed: Fri Oct 8 16:52:49 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.19: +10 -0 lines
Log Message:
*** empty log message ***

File Contents

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