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

Comparing libgender/entity.h (file contents):
Revision 1.6 by root, Sun Oct 3 03:17:09 2004 UTC vs.
Revision 1.17 by root, Tue Oct 5 03:39:47 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};
68
69struct entity_affine : entity_filter {
70 //matrix m;
71}; 71};
72 72
73struct vertex1d { 73struct vertex1d {
74 colour c; // colour 74 colour c; // colour
75 point p; // vertex 75 point p; // vertex
83 vertex2d () { }; 83 vertex2d () { };
84 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) { };
85}; 85};
86 86
87struct entity_opengl : entity_base { 87struct entity_opengl : entity_base {
88 GLuint list;
89
90 entity_opengl ();
91 ~entity_opengl ();
88}; 92};
89 93
90template<GLenum type> 94template<GLenum type>
91struct entity_opengl1d : entity_opengl, vector<vertex1d> { 95struct entity_opengl1d : entity_opengl, vector<vertex1d> {
92 void update_bbox (); 96 void update ();
93 void show (const sector &sec);
94 void draw (const draw_context &ctx); 97 void draw (draw_context &ctx);
95}; 98};
96 99
97template<GLenum type> 100template<GLenum type>
98struct entity_opengl2d : entity_opengl, vector<vertex2d> { 101struct entity_opengl2d : entity_opengl {
99 material m; 102 material m;
100 103
101 void update_bbox (); 104 void set (const vector<vertex2d> &v);
102 void show (const sector &sec);
103 void draw (const draw_context &ctx); 105 void draw (draw_context &ctx);
104}; 106};
105 107
106typedef entity_opengl1d<GL_POINTS> entity_points; 108typedef entity_opengl1d<GL_POINTS> entity_points;
107typedef entity_opengl1d<GL_LINES> entity_lines; 109typedef entity_opengl1d<GL_LINES> entity_lines;
108typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; 110typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
112typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; 114typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
113typedef entity_opengl2d<GL_QUADS> entity_quads; 115typedef entity_opengl2d<GL_QUADS> entity_quads;
114typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; 116typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
115typedef entity_opengl2d<GL_POLYGON> entity_polygon; 117typedef entity_opengl2d<GL_POLYGON> entity_polygon;
116 118
117struct view { 119struct entity_transform : entity_filter {
118 point p; 120protected:
119 vec3 d, u; 121 matrix m;
120 float fov; 122 void renormalize ();
121 int w, h; 123public:
122 124
125 entity_transform ();
126
127 void update ();
128 void show ();
123 void draw (const draw_context &ctx); 129 void draw (draw_context &ctx);
130 void set_matrix (const matrix &xfrm);
131 void update (const matrix &xfrm);
132};
133
134struct entity_anim : entity_transform {
135 GLfloat vx, vy, vz;
136 void draw (draw_context &ctx);
124}; 137};
125 138
126#endif 139#endif
127 140
128 141

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines