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

Comparing libgender/entity.h (file contents):
Revision 1.3 by root, Sun Oct 3 01:14:40 2004 UTC vs.
Revision 1.5 by root, Sun Oct 3 02:38:33 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 *> {
29 void add (entity_base *e) { push_back (e); e->parent = this; }
80 void update_bbox (); 30 void update_bbox ();
81 void show (const sector &sec); 31 void show (const sector &sec);
82 void draw (); 32 void draw (const draw_context &ctx);
83 ~entity_container (); 33 ~entity_container ();
84}; 34};
85 35
86struct entity_filter : entity_base { 36struct entity_filter : entity_base {
87protected: 37protected:
102 52
103 entity_base *content () { return e; }; 53 entity_base *content () { return e; };
104 54
105 void update_bbox (); 55 void update_bbox ();
106 void show (const sector &sec); 56 void show (const sector &sec);
107 void draw (); 57 void draw (const draw_context &ctx);
108 ~entity_filter (); 58 ~entity_filter ();
109}; 59};
110 60
111struct entity : entity_filter { 61struct entity : entity_filter {
112 sector sec; 62 sector sec;
113 63
114 void show (const sector &sec); 64 void show (const sector &sec);
115 void show (); 65 void show ();
116 void draw (); 66 void draw (const draw_context &ctx);
117}; 67};
118 68
119struct entity_affine : entity_filter { 69struct entity_affine : entity_filter {
120 //matrix m; 70 //matrix m;
121}; 71};
137 87
138template<GLenum type> 88template<GLenum type>
139struct entity_opengl1d : entity_base, vector<vertex1d> { 89struct entity_opengl1d : entity_base, vector<vertex1d> {
140 void update_bbox (); 90 void update_bbox ();
141 void show (const sector &sec); 91 void show (const sector &sec);
142 void draw (); 92 void draw (const draw_context &ctx);
143}; 93};
144 94
145template<GLenum type> 95template<GLenum type>
146struct entity_opengl2d : entity_base, vector<vertex2d> { 96struct entity_opengl2d : entity_base, vector<vertex2d> {
147 void update_bbox (); 97 void update_bbox ();
148 void show (const sector &sec); 98 void show (const sector &sec);
149 void draw (); 99 void draw (const draw_context &ctx);
150}; 100};
151 101
152typedef entity_opengl1d<GL_POINTS> entity_points; 102typedef entity_opengl1d<GL_POINTS> entity_points;
153typedef entity_opengl1d<GL_LINES> entity_lines; 103typedef entity_opengl1d<GL_LINES> entity_lines;
154typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; 104typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip;
158typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; 108typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan;
159typedef entity_opengl2d<GL_QUADS> entity_quads; 109typedef entity_opengl2d<GL_QUADS> entity_quads;
160typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; 110typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip;
161typedef entity_opengl2d<GL_POLYGON> entity_polygon; 111typedef entity_opengl2d<GL_POLYGON> entity_polygon;
162 112
163struct light {
164 point p;
165 colour c;
166 GLfloat intensity;
167 GLfloat radius;
168};
169
170struct draw_context {
171 enum { DEPTH, AMBIENT, LIGHTED } mode;
172 light *l;
173};
174
175struct view { 113struct view {
176 point p; 114 point p;
177 vec3 d, u; 115 vec3 d, u;
178 float fov; 116 float fov;
179 int w, h; 117 int w, h;
180 118
181 void draw (const draw_context &c); 119 void draw (const draw_context &ctx);
182}; 120};
183 121
184#endif 122#endif
185 123
186 124

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines