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.17 by root, Tue Oct 5 03:39:47 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
13const soffs soffs_max = 1UL << 31;
14
15#define GLFLOAT_MAX 1e30
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 {
43 a.x = a.y = a.z = GLFLOAT_MAX;
44 b.x = b.y = b.z = GLFLOAT_MIN;
45 }
46
47 void add (const box &o);
48};
49
50struct entity_base { 14struct entity_base {
51 struct entity_base *parent; 15 struct entity_base *parent;
16 sector orig;
52 vector<octant *> o; 17 vector<octant *> o;
53 box bbox; 18 box bbox;
54 19
55 virtual void update_bbox (); 20 virtual void update ();
56 virtual void show (const sector &sec) { }; 21 virtual void show () { world.add (this); };
57 void hide (); 22 void hide ();
23 void display (draw_context &ctx);
58 virtual void draw () = 0; 24 virtual void draw (draw_context &ctx) = 0;
25
26 entity_base ();
59 virtual ~entity_base () 27 virtual ~entity_base ();
60 {
61 hide ();
62 };
63}; 28};
64 29
65struct entity_container : entity_base, protected vector<entity_base *> { 30struct entity_container : entity_base, protected vector<entity_base *> {
31 void add (entity_base *e)
32 {
33 push_back (e);
34 e->parent = this;
35 update ();
36 }
37
66 void update_bbox (); 38 void update ();
67 void show (const sector &sec);
68 void draw (); 39 void show ();
40 void draw (draw_context &ctx);
69 ~entity_container (); 41 ~entity_container ();
70}; 42};
71 43
72struct entity_filter : entity_base { 44struct entity_filter : entity_base {
73protected: 45protected:
76 48
77 void set (entity_base *e) 49 void set (entity_base *e)
78 { 50 {
79 this->e = e; 51 this->e = e;
80 e->parent = this; 52 e->parent = this;
53 update ();
81 } 54 }
82 55
83 void remove () 56 void remove ()
84 { 57 {
85 this->e->parent = 0; 58 this->e->parent = 0;
86 this->e = 0; 59 this->e = 0;
87 } 60 }
88 61
89 entity_base *content () { return e; }; 62 entity_base *content () { return e; };
90 63
91 void update_bbox (); 64 void update ();
92 void show (const sector &sec);
93 void draw (); 65 void show ();
66 void draw (draw_context &ctx);
94 ~entity_filter (); 67 ~entity_filter ();
95}; 68};
96 69
97struct entity : entity_filter { 70struct 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}; 71};
107 72
108struct vertex1d { 73struct vertex1d {
109 point v; // vertex
110 colour c; // colour 74 colour c; // colour
75 point p; // vertex
111}; 76};
112 77
113struct vertex2d { 78struct vertex2d {
114 point v; // vertex 79 point p; // vertex
115 colour c; // colour
116 vect n; // normal 80 vec3 n; // normal
117 texc t; // texture 81 texc t; // texture
82
83 vertex2d () { };
84 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
85};
86
87struct entity_opengl : entity_base {
88 GLuint list;
89
90 entity_opengl ();
91 ~entity_opengl ();
118}; 92};
119 93
120template<GLenum type> 94template<GLenum type>
121struct entity_opengl1d : entity_base, vector<vertex1d> { 95struct entity_opengl1d : entity_opengl, vector<vertex1d> {
122 void update_bbox (); 96 void update ();
123 void show (const sector &sec); 97 void draw (draw_context &ctx);
124 void draw ();
125}; 98};
126 99
127template<GLenum type> 100template<GLenum type>
128struct entity_opengl2d : entity_base, vector<vertex2d> { 101struct entity_opengl2d : entity_opengl {
129 void update_bbox (); 102 material m;
130 void show (const sector &sec); 103
131 void draw (); 104 void set (const vector<vertex2d> &v);
105 void draw (draw_context &ctx);
132}; 106};
133 107
134typedef entity_opengl1d<GL_POINTS> entity_points; 108typedef entity_opengl1d<GL_POINTS> entity_points;
135typedef entity_opengl1d<GL_LINES> entity_lines; 109typedef entity_opengl1d<GL_LINES> entity_lines;
136typedef entity_opengl1d<GL_LINE_STRIP> entity_linestrip; 110typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
137typedef entity_opengl1d<GL_LINE_LOOP> entity_lineloop; 111typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop;
138typedef entity_opengl2d<GL_TRIANGLES> entity_triangles; 112typedef entity_opengl2d<GL_TRIANGLES> entity_triangles;
139typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_trianglestrip; 113typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip;
140typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_trianglefan; 114typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
141typedef entity_opengl2d<GL_QUADS> entity_quads; 115typedef entity_opengl2d<GL_QUADS> entity_quads;
142typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; 116typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
143typedef entity_opengl2d<GL_POLYGON> entity_polygon; 117typedef entity_opengl2d<GL_POLYGON> entity_polygon;
118
119struct entity_transform : entity_filter {
120protected:
121 matrix m;
122 void renormalize ();
123public:
124
125 entity_transform ();
126
127 void update ();
128 void show ();
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);
137};
144 138
145#endif 139#endif
146 140
147 141
148 142

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines