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.19 by root, Thu Oct 7 23:39:43 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines