ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.21
Committed: Sun Oct 10 00:22:49 2004 UTC (19 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.20: +2 -2 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 root 1.20 #include <GL/glu.h>
6 root 1.1
7     #include <vector>
8    
9 root 1.5 #include "util.h"
10 root 1.1 #include "oct.h"
11 root 1.8 #include "view.h"
12 root 1.1
13     using namespace std;
14    
15 root 1.19 struct geometry {
16     geometry *parent;
17 root 1.1 box bbox;
18    
19 root 1.19 virtual void update ()
20 root 1.15 {
21 root 1.19 if (parent)
22     parent->update ();
23 root 1.15 }
24    
25 root 1.19 virtual void draw (view &ctx) = 0;
26     geometry (geometry *parent = 0) : parent(parent) { };
27     virtual ~geometry ();
28 root 1.1 };
29    
30     struct vertex1d {
31 root 1.3 colour c; // colour
32 root 1.2 point p; // vertex
33 root 1.1 };
34    
35     struct vertex2d {
36 root 1.6 point p; // vertex
37     vec3 n; // normal
38     texc t; // texture
39 root 1.3
40     vertex2d () { };
41 root 1.6 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
42     };
43    
44 root 1.19 struct geometry_opengl : geometry {
45     GLuint list; // TODO: dynamic caching
46 root 1.13
47 root 1.19 geometry_opengl ();
48     ~geometry_opengl ();
49 root 1.1 };
50    
51     template<GLenum type>
52 root 1.19 struct geometry_opengl1d : geometry_opengl, vector<vertex1d> {
53     void set (const vector<vertex1d> &v);
54 root 1.18 void draw (view &ctx);
55 root 1.1 };
56    
57     template<GLenum type>
58 root 1.19 struct geometry_opengl2d : geometry_opengl {
59 root 1.6 material m;
60    
61 root 1.13 void set (const vector<vertex2d> &v);
62 root 1.18 void draw (view &ctx);
63 root 1.1 };
64    
65 root 1.19 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 root 1.20
76     struct geometry_nurbs : geometry, vector<vertex2d> {
77     GLUnurbsObj *nurb;
78 root 1.21 GLUtesselator *tess;
79 root 1.20 GLfloat ctlpoints[4][4][3];
80    
81 root 1.21 geometry_nurbs() : tess(0), nurb(0) { }
82 root 1.20 virtual void draw (view &ctx);
83     void set ();
84     };
85 root 1.11
86 root 1.19 struct geometry_filter : geometry {
87 root 1.16 protected:
88 root 1.19 geometry *g;
89 root 1.16 public:
90 root 1.11
91 root 1.19 void set (geometry *g);
92    
93     geometry *content () { return g; };
94 root 1.11
95 root 1.16 void update ();
96 root 1.11 void show ();
97 root 1.18 void draw (view &ctx);
98 root 1.19 geometry_filter (geometry *g = 0) { set (g); }
99     ~geometry_filter ();
100     };
101    
102     struct geometry_transform : geometry_filter {
103     protected:
104     matrix m;
105     public:
106     void update ();
107    
108     void show ();
109     void draw (view &ctx);
110 root 1.17 void set_matrix (const matrix &xfrm);
111     void update (const matrix &xfrm);
112 root 1.19
113     geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
114     geometry_transform () : geometry_filter(0), m(1) { };
115 root 1.11 };
116 root 1.1
117 root 1.19 struct geometry_anim : geometry_transform {
118 root 1.12 GLfloat vx, vy, vz;
119 root 1.18 void draw (view &ctx);
120 root 1.19 };
121    
122     struct geometry_container : geometry, protected vector<geometry *> {
123     void update ();
124    
125     void add (geometry *g);
126     void draw (view &ctx);
127     ~geometry_container ();
128     };
129    
130     /////////////////////////////////////////////////////////////////////////////
131    
132     struct entity : geometry_filter {
133     sector orig;
134     point p;
135     sector a, b; // bounding box corners
136    
137     vector<octant *> o;
138    
139     void update ();
140     void draw (view &ctx);
141    
142     void move (const vec3 &v);
143    
144     virtual void show () { if (!o.size ()) world.add (this); };
145     void hide ();
146     void display (view &ctx);
147    
148     entity (geometry *g = 0);
149     ~entity ();
150 root 1.12 };
151 root 1.1 #endif
152    
153    
154