ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
Revision: 1.22
Committed: Sun Oct 10 14:15:15 2004 UTC (19 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.21: +41 -18 lines
Log Message:
*** empty log message ***

File Contents

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