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

# 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     GLfloat ctlpoints[4][4][3];
79    
80     geometry_nurbs() : nurb(0) { }
81     virtual void draw (view &ctx);
82     void set ();
83     };
84 root 1.11
85 root 1.19 struct geometry_filter : geometry {
86 root 1.16 protected:
87 root 1.19 geometry *g;
88 root 1.16 public:
89 root 1.11
90 root 1.19 void set (geometry *g);
91    
92     geometry *content () { return g; };
93 root 1.11
94 root 1.16 void update ();
95 root 1.11 void show ();
96 root 1.18 void draw (view &ctx);
97 root 1.19 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 root 1.17 void set_matrix (const matrix &xfrm);
110     void update (const matrix &xfrm);
111 root 1.19
112     geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
113     geometry_transform () : geometry_filter(0), m(1) { };
114 root 1.11 };
115 root 1.1
116 root 1.19 struct geometry_anim : geometry_transform {
117 root 1.12 GLfloat vx, vy, vz;
118 root 1.18 void draw (view &ctx);
119 root 1.19 };
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 root 1.12 };
150    
151 root 1.1 #endif
152    
153    
154