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.26 by root, Tue Oct 19 15:34:58 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>
5
6#include <vector> 4#include <vector>
7 5
6#include "opengl.h"
7
8#include "util.h"
8#include "oct.h" 9#include "oct.h"
10#include "view.h"
11#include "material.h"
9 12
10using namespace std; 13using namespace std;
14using namespace gl;
11 15
12typedef unsigned int soffs; // 32 bit 16struct geometry
13const soffs soffs_max = 1UL << 31; 17{
18 geometry *parent;
19 box bbox;
14 20
15#define GLFLOAT_MAX 1e30 21 virtual void update ()
16#define GLFLOAT_MIN -1e30 22 {
23 if (parent)
24 parent->update ();
25 }
17 26
18struct sector { 27 virtual void draw (view &ctx) = 0;
19 soffs x, y, z; 28 geometry (geometry *parent = 0) : parent(parent) { };
29 virtual ~geometry ();
20}; 30};
21 31
22struct point { 32struct geometry_opengl : geometry
23 GLfloat x, y, z; 33{
24}; 34 GLuint list; // TODO: dynamic caching
25 35
26struct colour { 36 geometry_opengl ();
27 GLfloat r, g, b; 37 ~geometry_opengl ();
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 {
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;
59 virtual ~entity_base ()
60 {
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};
107
108struct vertex1d {
109 point v; // vertex
110 colour c; // colour
111};
112
113struct vertex2d {
114 point v; // vertex
115 colour c; // colour
116 vect n; // normal
117 texc t; // texture
118}; 38};
119 39
120template<GLenum type> 40template<GLenum type>
121struct entity_opengl1d : entity_base, vector<vertex1d> { 41struct geometry_opengl1d : geometry_opengl, vector<vertex_v3f>
122 void update_bbox (); 42{
123 void show (const sector &sec); 43 void set (const vector<vertex_v3f> &v);
124 void draw (); 44 void draw (view &ctx);
125}; 45};
126 46
127template<GLenum type> 47template<GLenum type>
128struct entity_opengl2d : entity_base, vector<vertex2d> { 48struct geometry_opengl2d : geometry_opengl
129 void update_bbox (); 49{
130 void show (const sector &sec); 50 material *m;
51
52 geometry_opengl2d () : m(0) { };
53
54 void set (const vector<vertex_t2f_n3f_v3f> &v);
131 void draw (); 55 void draw (view &ctx);
132}; 56};
133 57
134typedef entity_opengl1d<GL_POINTS> entity_points; 58typedef geometry_opengl1d<GL_POINTS> geometry_points;
135typedef entity_opengl1d<GL_LINES> entity_lines; 59typedef geometry_opengl1d<GL_LINES> geometry_lines;
136typedef entity_opengl1d<GL_LINE_STRIP> entity_linestrip; 60typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip;
137typedef entity_opengl1d<GL_LINE_LOOP> entity_lineloop; 61typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop;
138typedef entity_opengl2d<GL_TRIANGLES> entity_triangles; 62typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles;
139typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_trianglestrip; 63typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip;
140typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_trianglefan; 64typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan;
141typedef entity_opengl2d<GL_QUADS> entity_quads; 65typedef geometry_opengl2d<GL_QUADS> geometry_quads;
142typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; 66typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip;
143typedef entity_opengl2d<GL_POLYGON> entity_polygon; 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
84 void update ();
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; };
100
101 void update ();
102 void show ();
103 void draw (view &ctx);
104 geometry_filter (geometry *g = 0) { set (g); }
105 ~geometry_filter ();
106};
107
108struct geometry_transform : geometry_filter
109{
110protected:
111 matrix m;
112public:
113 void update ();
114
115 void show ();
116 void draw (view &ctx);
117 void set_matrix (const matrix &xfrm);
118 void update (const matrix &xfrm);
119
120 geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
121 geometry_transform () : geometry_filter(0), m(1) { };
122};
123
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;
148
149 void update ();
150 void draw (view &ctx);
151
152 void move (const vec3 &v);
153
154 virtual void show ();
155 virtual void hide ();
156
157 entity (geometry *g = 0);
158 ~entity ();
159};
160
161struct light : entity
162{
163 point p;
164 colour c;
165 GLfloat intensity;
166 GLfloat radius;
167};
144 168
145#endif 169#endif
146 170
147 171
148 172

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines