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

Comparing libgender/entity.h (file contents):
Revision 1.17 by root, Tue Oct 5 03:39:47 2004 UTC vs.
Revision 1.24 by root, Sat Oct 16 23:23:21 2004 UTC

1#ifndef ENTITY_H 1#ifndef ENTITY_H
2#define ENTITY_H 2#define ENTITY_H
3 3
4#include <GL/gl.h> 4#include <vector>
5 5
6#include <vector> 6#include "opengl.h"
7 7
8#include "util.h" 8#include "util.h"
9#include "oct.h" 9#include "oct.h"
10#include "view.h" 10#include "view.h"
11#include "material.h"
11 12
12using namespace std; 13using namespace std;
14using namespace gl;
13 15
14struct entity_base { 16struct geometry
15 struct entity_base *parent; 17{
16 sector orig; 18 geometry *parent;
17 vector<octant *> o;
18 box bbox; 19 box bbox;
19 20
20 virtual void update (); 21 virtual void update ()
21 virtual void show () { world.add (this); }; 22 {
22 void hide (); 23 if (parent)
23 void display (draw_context &ctx); 24 parent->update ();
24 virtual void draw (draw_context &ctx) = 0; 25 }
25 26
26 entity_base (); 27 virtual void draw (view &ctx) = 0;
27 virtual ~entity_base (); 28 geometry (geometry *parent = 0) : parent(parent) { };
29 virtual ~geometry ();
28}; 30};
29 31
30struct entity_container : entity_base, protected vector<entity_base *> { 32struct geometry_opengl : geometry
31 void add (entity_base *e) 33{
32 { 34 GLuint list; // TODO: dynamic caching
33 push_back (e); 35
34 e->parent = this; 36 geometry_opengl ();
37 ~geometry_opengl ();
38};
39
40template<GLenum type>
41struct geometry_opengl1d : geometry_opengl, vector<vertex_v3f>
42{
43 void set (const vector<vertex_v3f> &v);
44 void draw (view &ctx);
45};
46
47template<GLenum type>
48struct geometry_opengl2d : geometry_opengl
49{
50 material *m;
51
52 geometry_opengl2d () : m(0) { };
53
54 void set (const vector<vertex_t2f_n3f_v3f> &v);
55 void draw (view &ctx);
56};
57
58typedef geometry_opengl1d<GL_POINTS> geometry_points;
59typedef geometry_opengl1d<GL_LINES> geometry_lines;
60typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip;
61typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop;
62typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles;
63typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip;
64typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan;
65typedef geometry_opengl2d<GL_QUADS> geometry_quads;
66typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip;
67typedef geometry_opengl2d<GL_POLYGON> geometry_polygon;
68
69struct geometry_nurbs : geometry, vector<vertex_t2f_n3f_v3f>
70{
71 GLUnurbsObj *nurb;
72 GLUtesselator *tess;
73 GLfloat ctlpoints[4][4][3];
74
75 geometry_nurbs() : tess(0), nurb(0) { }
76 virtual void draw (view &ctx);
77 void set ();
78};
79
80struct geometry_sphere : geometry
81{
82 GLfloat radius;
83
35 update (); 84 void update ();
36 } 85 void draw (view &ctx);
86 geometry_sphere (GLfloat radius) : radius(radius) { update (); };
87};
88
89/////////////////////////////////////////////////////////////////////////////
90
91struct geometry_filter : geometry
92{
93protected:
94 geometry *g;
95public:
96
97 void set (geometry *g);
98
99 geometry *content () { return g; };
37 100
38 void update (); 101 void update ();
39 void show (); 102 void show ();
40 void draw (draw_context &ctx); 103 void draw (view &ctx);
41 ~entity_container (); 104 geometry_filter (geometry *g = 0) { set (g); }
105 ~geometry_filter ();
42}; 106};
43 107
44struct entity_filter : entity_base { 108struct geometry_transform : geometry_filter
109{
45protected: 110protected:
46 entity_base *e; 111 matrix m;
47public: 112public:
113 void update ();
48 114
49 void set (entity_base *e) 115 void show ();
50 { 116 void draw (view &ctx);
51 this->e = e; 117 void set_matrix (const matrix &xfrm);
52 e->parent = this; 118 void update (const matrix &xfrm);
53 update ();
54 }
55 119
56 void remove () 120 geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
57 { 121 geometry_transform () : geometry_filter(0), m(1) { };
58 this->e->parent = 0; 122};
59 this->e = 0;
60 }
61 123
62 entity_base *content () { return e; }; 124struct geometry_anim : geometry_transform
125{
126 GLfloat vx, vy, vz;
127 void draw (view &ctx);
128};
129
130struct geometry_container : geometry, protected vector<geometry *>
131{
132 void update ();
133
134 void add (geometry *g);
135 void draw (view &ctx);
136 ~geometry_container ();
137};
138
139/////////////////////////////////////////////////////////////////////////////
140
141struct entity : geometry_filter
142{
143 sector orig;
144 point p;
145 sector a, b; // bounding box corners
146
147 vector<octant *> o;
63 148
64 void update (); 149 void update ();
150 void draw (view &ctx);
151
152 void move (const vec3 &v);
153
65 void show (); 154 virtual void show ();
66 void draw (draw_context &ctx); 155 virtual void hide ();
156 void display (view &ctx);
157
158 entity (geometry *g = 0);
67 ~entity_filter (); 159 ~entity ();
68}; 160};
69 161
70struct entity : entity_filter { 162struct light : entity
71}; 163{
72 164 point p;
73struct vertex1d { 165 colour c;
74 colour c; // colour 166 GLfloat intensity;
75 point p; // vertex 167 GLfloat radius;
76};
77
78struct vertex2d {
79 point p; // vertex
80 vec3 n; // normal
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 ();
92};
93
94template<GLenum type>
95struct entity_opengl1d : entity_opengl, vector<vertex1d> {
96 void update ();
97 void draw (draw_context &ctx);
98};
99
100template<GLenum type>
101struct entity_opengl2d : entity_opengl {
102 material m;
103
104 void set (const vector<vertex2d> &v);
105 void draw (draw_context &ctx);
106};
107
108typedef entity_opengl1d<GL_POINTS> entity_points;
109typedef entity_opengl1d<GL_LINES> entity_lines;
110typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
111typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop;
112typedef entity_opengl2d<GL_TRIANGLES> entity_triangles;
113typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip;
114typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
115typedef entity_opengl2d<GL_QUADS> entity_quads;
116typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
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}; 168};
138 169
139#endif 170#endif
140 171
141 172

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines