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

Comparing libgender/entity.h (file contents):
Revision 1.7 by root, Sun Oct 3 03:19:56 2004 UTC vs.
Revision 1.16 by root, Mon Oct 4 23:44:53 2004 UTC

5 5
6#include <vector> 6#include <vector>
7 7
8#include "util.h" 8#include "util.h"
9#include "oct.h" 9#include "oct.h"
10#include "view.h"
10 11
11using namespace std; 12using namespace std;
12 13
13struct entity_base { 14struct entity_base {
14 struct entity_base *parent; 15 struct entity_base *parent;
16 sector orig;
15 vector<octant *> o; 17 vector<octant *> o;
16 box bbox; 18 box bbox;
17 19
18 virtual void update_bbox (); 20 virtual void update ();
19 virtual void show (const sector &sec) { }; 21 virtual void show () { world.add (this); };
20 void hide (); 22 void hide ();
23 void display (draw_context &ctx);
21 virtual void draw (const draw_context &ctx) = 0; 24 virtual void draw (draw_context &ctx) = 0;
25
26 entity_base ();
22 virtual ~entity_base () 27 virtual ~entity_base ();
23 {
24 hide ();
25 };
26}; 28};
27 29
28struct entity_container : entity_base, protected vector<entity_base *> { 30struct entity_container : entity_base, protected vector<entity_base *> {
29 void add (entity_base *e) { push_back (e); e->parent = this; } 31 void add (entity_base *e)
32 {
33 push_back (e);
34 e->parent = this;
35 update ();
36 }
37
30 void update_bbox (); 38 void update ();
31 void show (const sector &sec); 39 void show ();
32 void draw (const draw_context &ctx); 40 void draw (draw_context &ctx);
33 ~entity_container (); 41 ~entity_container ();
34}; 42};
35 43
36struct entity_filter : entity_base { 44struct entity_filter : entity_base {
37protected: 45protected:
40 48
41 void set (entity_base *e) 49 void set (entity_base *e)
42 { 50 {
43 this->e = e; 51 this->e = e;
44 e->parent = this; 52 e->parent = this;
53 update ();
45 } 54 }
46 55
47 void remove () 56 void remove ()
48 { 57 {
49 this->e->parent = 0; 58 this->e->parent = 0;
50 this->e = 0; 59 this->e = 0;
51 } 60 }
52 61
53 entity_base *content () { return e; }; 62 entity_base *content () { return e; };
54 63
55 void update_bbox (); 64 void update ();
56 void show (const sector &sec); 65 void show ();
57 void draw (const draw_context &ctx); 66 void draw (draw_context &ctx);
58 ~entity_filter (); 67 ~entity_filter ();
59}; 68};
60 69
61struct entity : entity_filter { 70struct entity : entity_filter {
62 sector sec;
63
64 void show (const sector &sec);
65 void show ();
66 void draw (const draw_context &ctx);
67}; 71};
68
69#if 0
70struct entity_affine : entity_filter {
71 GLfloat m[4][4];
72
73 void draw (const draw_context &ctx);
74};
75#endif
76 72
77struct vertex1d { 73struct vertex1d {
78 colour c; // colour 74 colour c; // colour
79 point p; // vertex 75 point p; // vertex
80}; 76};
87 vertex2d () { }; 83 vertex2d () { };
88 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; 84 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
89}; 85};
90 86
91struct entity_opengl : entity_base { 87struct entity_opengl : entity_base {
88 GLuint list;
89
90 entity_opengl ();
91 ~entity_opengl ();
92}; 92};
93 93
94template<GLenum type> 94template<GLenum type>
95struct entity_opengl1d : entity_opengl, vector<vertex1d> { 95struct entity_opengl1d : entity_opengl, vector<vertex1d> {
96 void update_bbox (); 96 void update ();
97 void show (const sector &sec);
98 void draw (const draw_context &ctx); 97 void draw (draw_context &ctx);
99}; 98};
100 99
101template<GLenum type> 100template<GLenum type>
102struct entity_opengl2d : entity_opengl, vector<vertex2d> { 101struct entity_opengl2d : entity_opengl {
103 material m; 102 material m;
104 103
105 void update_bbox (); 104 void set (const vector<vertex2d> &v);
106 void show (const sector &sec);
107 void draw (const draw_context &ctx); 105 void draw (draw_context &ctx);
108}; 106};
109 107
110typedef entity_opengl1d<GL_POINTS> entity_points; 108typedef entity_opengl1d<GL_POINTS> entity_points;
111typedef entity_opengl1d<GL_LINES> entity_lines; 109typedef entity_opengl1d<GL_LINES> entity_lines;
112typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; 110typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
116typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; 114typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
117typedef entity_opengl2d<GL_QUADS> entity_quads; 115typedef entity_opengl2d<GL_QUADS> entity_quads;
118typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; 116typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
119typedef entity_opengl2d<GL_POLYGON> entity_polygon; 117typedef entity_opengl2d<GL_POLYGON> entity_polygon;
120 118
121struct view { 119struct entity_transform : entity_filter {
122 point p; 120protected:
123 vec3 d, u; 121 gl_matrix m;
124 float fov; 122 void renormalize ();
125 int w, h; 123public:
126 124
125 entity_transform ();
126
127 void update ();
128 void show ();
127 void draw (const draw_context &ctx); 129 void draw (draw_context &ctx);
130 void set_matrix (const gl_matrix &xfrm);
131 void update (const gl_matrix &xfrm);
132};
133
134struct entity_anim : entity_transform {
135 GLfloat vx, vy, vz;
136 void draw (draw_context &ctx);
128}; 137};
129 138
130#endif 139#endif
131 140
132 141

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines