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

Comparing libgender/entity.h (file contents):
Revision 1.4 by root, Sun Oct 3 02:37:55 2004 UTC vs.
Revision 1.7 by root, Sun Oct 3 03:19:56 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"
9 10
10using namespace std; 11using namespace std;
11
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 point () { };
26 point (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { };
27};
28
29struct colour {
30 GLfloat r, g, b;
31 colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1.) : r(r), g(g), b(b) { };
32};
33
34struct vec3 {
35 GLfloat x, y, z;
36 vec3 () { };
37 vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { };
38
39 const vec3 operator -() const
40 { return vec3 (-x, -y, -z); }
41};
42
43const vec3 cross (const vec3 &a, const vec3 &b);
44GLfloat dot (const vec3 &a, const vec3 &b);
45
46struct texc {
47 GLfloat s, t;
48 texc () { };
49 texc (GLfloat s, GLfloat t) : s(s), t(t) { };
50};
51
52struct box {
53 point a, b;
54
55 void reset ()
56 {
57 a = point (GLFLOAT_MAX, GLFLOAT_MAX, GLFLOAT_MAX);
58 b = point (GLFLOAT_MIN, GLFLOAT_MIN, GLFLOAT_MIN);
59 }
60
61 void add (const box &o);
62};
63 12
64struct entity_base { 13struct entity_base {
65 struct entity_base *parent; 14 struct entity_base *parent;
66 vector<octant *> o; 15 vector<octant *> o;
67 box bbox; 16 box bbox;
68 17
69 virtual void update_bbox (); 18 virtual void update_bbox ();
70 virtual void show (const sector &sec) { }; 19 virtual void show (const sector &sec) { };
71 void hide (); 20 void hide ();
72 virtual void draw () = 0; 21 virtual void draw (const draw_context &ctx) = 0;
73 virtual ~entity_base () 22 virtual ~entity_base ()
74 { 23 {
75 hide (); 24 hide ();
76 }; 25 };
77}; 26};
78 27
79struct entity_container : entity_base, protected vector<entity_base *> { 28struct entity_container : entity_base, protected vector<entity_base *> {
80 void add (entity_base *e) { push_back (e); e->parent = this; } 29 void add (entity_base *e) { push_back (e); e->parent = this; }
81 void update_bbox (); 30 void update_bbox ();
82 void show (const sector &sec); 31 void show (const sector &sec);
83 void draw (); 32 void draw (const draw_context &ctx);
84 ~entity_container (); 33 ~entity_container ();
85}; 34};
86 35
87struct entity_filter : entity_base { 36struct entity_filter : entity_base {
88protected: 37protected:
103 52
104 entity_base *content () { return e; }; 53 entity_base *content () { return e; };
105 54
106 void update_bbox (); 55 void update_bbox ();
107 void show (const sector &sec); 56 void show (const sector &sec);
108 void draw (); 57 void draw (const draw_context &ctx);
109 ~entity_filter (); 58 ~entity_filter ();
110}; 59};
111 60
112struct entity : entity_filter { 61struct entity : entity_filter {
113 sector sec; 62 sector sec;
114 63
115 void show (const sector &sec); 64 void show (const sector &sec);
116 void show (); 65 void show ();
117 void draw (); 66 void draw (const draw_context &ctx);
118}; 67};
119 68
69#if 0
120struct entity_affine : entity_filter { 70struct entity_affine : entity_filter {
121 //matrix m; 71 GLfloat m[4][4];
72
73 void draw (const draw_context &ctx);
122}; 74};
75#endif
123 76
124struct vertex1d { 77struct vertex1d {
125 colour c; // colour 78 colour c; // colour
126 point p; // vertex 79 point p; // vertex
127}; 80};
128 81
129struct vertex2d { 82struct vertex2d {
130 colour c; // colour
131 point p; // vertex 83 point p; // vertex
132 vec3 n; // normal 84 vec3 n; // normal
133 texc t; // texture 85 texc t; // texture
134 86
135 vertex2d () { }; 87 vertex2d () { };
136 vertex2d (colour c, point p, vec3 n, texc t = texc()) : c(c), p(p), n(n), t(t) { }; 88 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
89};
90
91struct entity_opengl : entity_base {
137}; 92};
138 93
139template<GLenum type> 94template<GLenum type>
140struct entity_opengl1d : entity_base, vector<vertex1d> { 95struct entity_opengl1d : entity_opengl, vector<vertex1d> {
141 void update_bbox (); 96 void update_bbox ();
142 void show (const sector &sec); 97 void show (const sector &sec);
143 void draw (); 98 void draw (const draw_context &ctx);
144}; 99};
145 100
146template<GLenum type> 101template<GLenum type>
147struct entity_opengl2d : entity_base, vector<vertex2d> { 102struct entity_opengl2d : entity_opengl, vector<vertex2d> {
103 material m;
104
148 void update_bbox (); 105 void update_bbox ();
149 void show (const sector &sec); 106 void show (const sector &sec);
150 void draw (); 107 void draw (const draw_context &ctx);
151}; 108};
152 109
153typedef entity_opengl1d<GL_POINTS> entity_points; 110typedef entity_opengl1d<GL_POINTS> entity_points;
154typedef entity_opengl1d<GL_LINES> entity_lines; 111typedef entity_opengl1d<GL_LINES> entity_lines;
155typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; 112typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
159typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; 116typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
160typedef entity_opengl2d<GL_QUADS> entity_quads; 117typedef entity_opengl2d<GL_QUADS> entity_quads;
161typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; 118typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
162typedef entity_opengl2d<GL_POLYGON> entity_polygon; 119typedef entity_opengl2d<GL_POLYGON> entity_polygon;
163 120
164struct light {
165 point p;
166 colour c;
167 GLfloat intensity;
168 GLfloat radius;
169};
170
171struct draw_context {
172 enum { DEPTH, AMBIENT, LIGHTED } mode;
173 light *l;
174};
175
176struct view { 121struct view {
177 point p; 122 point p;
178 vec3 d, u; 123 vec3 d, u;
179 float fov; 124 float fov;
180 int w, h; 125 int w, h;
181 126
182 void draw (const draw_context &c); 127 void draw (const draw_context &ctx);
183}; 128};
184 129
185#endif 130#endif
186 131
187 132

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines