ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
(Generate patch)

Comparing libgender/entity.h (file contents):
Revision 1.1 by root, Sat Oct 2 15:54:43 2004 UTC vs.
Revision 1.35 by root, Tue Aug 9 23:58:43 2005 UTC

1#ifndef ENTITY_H 1#ifndef ENTITY_H
2#define ENTITY_H 2#define ENTITY_H
3 3
4#include <GL/gl.h>
5
6#include <vector> 4#include <vector>
7 5
6#include <iostream>
7#include "opengl.h"
8
9#include "util.h"
8#include "oct.h" 10#include "oct.h"
11#include "view.h"
12#include "material.h"
9 13
10using namespace std; 14using namespace std;
15using namespace gl;
11 16
12typedef unsigned int soffs; // 32 bit 17struct geometry
13const soffs soffs_max = 1UL << 31; 18{
19 geometry *parent;
20 box bbox;
14 21
15#define GLFLOAT_MAX 1e30 22 virtual void update ()
16#define GLFLOAT_MIN -1e30
17
18struct sector {
19 soffs x, y, z;
20};
21
22struct point {
23 GLfloat x, y, z;
24};
25
26struct colour {
27 GLfloat r, g, b;
28};
29
30struct vect {
31 GLfloat x, y, z;
32};
33
34struct texc {
35 GLfloat u, v;
36};
37
38struct box {
39 point a, b;
40
41 void reset ()
42 { 23 {
43 a.x = a.y = a.z = GLFLOAT_MAX; 24 if (parent)
44 b.x = b.y = b.z = GLFLOAT_MIN; 25 parent->update ();
45 } 26 }
46 27
47 void add (const box &o); 28 virtual void draw (view &ctx) = 0;
29 geometry (geometry *parent = 0) : parent(parent) { };
30 virtual ~geometry ();
48}; 31};
49 32
50struct entity_base { 33struct geometry_opengl : geometry
51 struct entity_base *parent; 34{
35 GLuint list; // TODO: dynamic caching
36
37 geometry_opengl ();
38 ~geometry_opengl ();
39};
40
41template<GLenum type>
42struct geometry_opengl1d : geometry_opengl, vector<vertex_v3f>
43{
44 void set (const vector<vertex_v3f> &v);
45 void draw (view &ctx);
46};
47
48template<GLenum type>
49struct geometry_opengl2d : geometry_opengl
50{
51 material *m;
52
53 geometry_opengl2d () : m(0) { };
54
55 void set (const vector<vertex_t2f_n3f_v3f> &v);
56 void draw (view &ctx);
57};
58
59typedef geometry_opengl1d<GL_POINTS> geometry_points;
60typedef geometry_opengl1d<GL_LINES> geometry_lines;
61typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip;
62typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop;
63typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles;
64typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip;
65typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan;
66typedef geometry_opengl2d<GL_QUADS> geometry_quads;
67typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip;
68typedef geometry_opengl2d<GL_POLYGON> geometry_polygon;
69
70struct geometry_nurbs : geometry, vector<vertex_t2f_n3f_v3f>
71{
72 GLUnurbsObj *nurb;
73 GLUtesselator *tess;
74 GLfloat ctlpoints[4][4][3];
75
76 geometry_nurbs() : tess(0), nurb(0) { }
77 virtual void draw (view &ctx);
78 void set ();
79};
80
81struct geometry_sphere : geometry
82{
83 material *m;
84 GLfloat radius;
85
86 void update ();
87 void draw (view &ctx);
88 geometry_sphere (material *m, GLfloat radius) : m(m), radius(radius) { update (); };
89};
90
91struct geometry_indexed_2d : geometry
92{
93 material *m;
94
95 GLenum type;
96
97 vertex_buffer vb;
98 index_buffer ib;
99
100 void draw (view &ctx);
101
102 template <typename vertex, typename index>
103 geometry_indexed_2d (material *m, GLenum type, const vector<vertex> &v, const vector<index> &i)
104 : m(m), type(type)
105 {
106 vb.set (v);
107 ib.set (i);
108
109 bbox.reset ();
110 for (typename vector<vertex>::const_iterator i = v.begin () ; i != v.end (); ++i)
111 bbox.add (i->v);
112 }
113
114};
115
116/////////////////////////////////////////////////////////////////////////////
117
118struct geometry_filter : geometry
119{
120protected:
121 geometry *g;
122public:
123
124 void set (geometry *g);
125
126 geometry *content () { return g; };
127
128 void update ();
129 void show ();
130 void draw (view &ctx);
131 geometry_filter (geometry *g = 0) { set (g); }
132 ~geometry_filter ();
133};
134
135struct geometry_transform : geometry_filter
136{
137protected:
138 matrix m;
139public:
140 void update ();
141
142 void show ();
143 void draw (view &ctx);
144 void set_matrix (const matrix &xfrm);
145 void update (const matrix &xfrm);
146
147 geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
148 geometry_transform () : geometry_filter(0), m(1) { };
149};
150
151struct geometry_anim : geometry_transform
152{
153 GLfloat vx, vy, vz;
154 void draw (view &ctx);
155};
156
157struct geometry_container : geometry, protected vector<geometry *>
158{
159 void update ();
160
161 void add (geometry *g);
162 void draw (view &ctx);
163 ~geometry_container ();
164};
165
166/////////////////////////////////////////////////////////////////////////////
167
168struct entity : geometry_filter
169{
170 sector orig;
171 point p;
172 sector a, b; // bounding box corners
173
52 vector<octant *> o; 174 vector<octant *> o;
53 box bbox;
54 175
55 virtual void update_bbox ();
56 virtual void show (const sector &sec) { };
57 void hide ();
58 virtual void draw () = 0;
59 virtual ~entity_base ()
60 {
61 hide ();
62 };
63};
64
65struct entity_container : entity_base, protected vector<entity_base *> {
66 void update_bbox (); 176 void update ();
67 void show (const sector &sec);
68 void draw (); 177 void draw (view &ctx);
69 ~entity_container ();
70};
71 178
179 void move (const vec3 &v);
180
181 virtual void show ();
182 virtual void hide ();
183
184 entity (geometry *g = 0);
185 ~entity ();
186};
187
188struct entity_moveable : entity
189{
190 vec3 v;
191 entity_moveable (geometry *g = 0) : entity (g) { }
192
193 void perform_step (double t);
194};
195
72struct entity_filter : entity_base { 196struct entity_light : entity
73protected: 197{
74 entity_base *e; 198 light *lview;
75public: 199};
76 200
77 void set (entity_base *e) 201/////////////////////////////////////////////////////////////////////////////
78 { 202// not the final API(!)
79 this->e = e;
80 e->parent = this;
81 }
82 203
83 void remove () 204struct skybox
84 { 205{
85 this->e->parent = 0; 206 texture *tex[6];
86 this->e = 0;
87 }
88 207
89 entity_base *content () { return e; }; 208 skybox (
209 const char *left,
210 const char *front,
211 const char *right,
212 const char *back,
213 const char *top,
214 const char *bottom
215 );
90 216
217 ~skybox ();
218
219 void draw (view &ctx);
220};
221
222/////////////////////////////////////////////////////////////////////////////
223//
224// VERY EXPERIMENTAL HEIGHTMAP
225
226struct geometry_heightfield : geometry
227{
228 struct node;
229
230 node *tree;
231
232 GLfloat sx, sy, sm;
233
91 void update_bbox (); 234 void update ();
92 void show (const sector &sec);
93 void draw (); 235 void draw (view &ctx);
94 ~entity_filter (); 236 geometry_heightfield (GLfloat sx, GLfloat sy);
95}; 237};
96
97struct entity : entity_filter {
98 sector sec;
99
100 void show (const sector &sec);
101 void draw ();
102};
103
104struct entity_affine : entity_filter {
105 //matrix m;
106};
107
108struct vertex1d {
109 point v; // vertex
110 colour c; // colour
111};
112
113struct vertex2d {
114 point v; // vertex
115 colour c; // colour
116 vect n; // normal
117 texc t; // texture
118};
119
120template<GLenum type>
121struct entity_opengl1d : entity_base, vector<vertex1d> {
122 void update_bbox ();
123 void show (const sector &sec);
124 void draw ();
125};
126
127template<GLenum type>
128struct entity_opengl2d : entity_base, vector<vertex2d> {
129 void update_bbox ();
130 void show (const sector &sec);
131 void draw ();
132};
133
134typedef entity_opengl1d<GL_POINTS> entity_points;
135typedef entity_opengl1d<GL_LINES> entity_lines;
136typedef entity_opengl1d<GL_LINE_STRIP> entity_linestrip;
137typedef entity_opengl1d<GL_LINE_LOOP> entity_lineloop;
138typedef entity_opengl2d<GL_TRIANGLES> entity_triangles;
139typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_trianglestrip;
140typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_trianglefan;
141typedef entity_opengl2d<GL_QUADS> entity_quads;
142typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
143typedef entity_opengl2d<GL_POLYGON> entity_polygon;
144 238
145#endif 239#endif
146 240
147 241
148 242

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines