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

Comparing libgender/util.h (file contents):
Revision 1.36 by root, Sun Oct 10 02:40:19 2004 UTC vs.
Revision 1.37 by root, Sun Oct 10 14:15:16 2004 UTC

1#ifndef UTIL_H 1#ifndef UTIL_H
2#define UTIL_H 2#define UTIL_H
3 3
4#include <SDL/SDL.h>
5#include <SDL/SDL_image.h>
6#include <cmath> 4#include <cmath>
7#include <cfloat> 5#include <cfloat>
8#include <vector> 6#include <vector>
9#include <string> 7#include <string>
10 8
11#include <Cg/cg.h>
12#include <Cg/cgGL.h>
13
14#include <GL/gl.h>
15#include <GL/glext.h>
16#include "gldebug.h" 9#include "opengl.h"
10
11#include <SDL/SDL_image.h>
17 12
18using namespace std; 13using namespace std;
19 14
20extern CGcontext cgc; 15extern CGcontext cgc;
21extern CGprogram vsh; 16extern CGprogram vsh;
28#define OFFS_BITS 31 23#define OFFS_BITS 31
29#define SOFFS_MIN (soffs)-(1LL << (OFFS_BITS - 2)) 24#define SOFFS_MIN (soffs)-(1LL << (OFFS_BITS - 2))
30#define SOFFS_MAX (soffs)+(1LL << (OFFS_BITS - 2)) 25#define SOFFS_MAX (soffs)+(1LL << (OFFS_BITS - 2))
31#define MAXEXTENT (1ULL << (OFFS_BITS - 1)) 26#define MAXEXTENT (1ULL << (OFFS_BITS - 1))
32 27
33struct sector { 28struct sector
29{
34 soffs x, y, z; 30 soffs x, y, z;
35 31
36 sector (soffs x, soffs y, soffs z) : x(x), y(y), z(z) { }; 32 sector (soffs x, soffs y, soffs z) : x(x), y(y), z(z) { };
37 sector (soffs xyz = 0) : x(xyz), y(xyz), z(xyz) { }; 33 sector (soffs xyz = 0) : x(xyz), y(xyz), z(xyz) { };
38 34
77inline sector abs (const sector &s) 73inline sector abs (const sector &s)
78{ 74{
79 return sector (abs (s.x), abs (s.y), abs (s.z)); 75 return sector (abs (s.x), abs (s.y), abs (s.z));
80} 76}
81 77
82struct vec3 { 78struct vec3
79{
83 GLfloat x, y, z; 80 GLfloat x, y, z;
84 vec3 () { }; 81 vec3 () { };
85 vec3 (GLfloat s) : x(s), y(s), z(s) { }; 82 vec3 (GLfloat s) : x(s), y(s), z(s) { };
86 vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; 83 vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { };
87 vec3 (const sector &s) : x(s.x), y(s.y), z(s.z) { }; 84 vec3 (const sector &s) : x(s.x), y(s.y), z(s.z) { };
116inline const GLfloat abs (const vec3 &v) 113inline const GLfloat abs (const vec3 &v)
117{ 114{
118 return sqrtf (dot (v, v)); 115 return sqrtf (dot (v, v));
119} 116}
120 117
121struct matrix { 118struct matrix
119{
122 GLfloat data[4][4]; 120 GLfloat data[4][4];
123 121
124 const GLfloat operator ()(int i, int j) const { return data[j][i]; }; 122 const GLfloat operator ()(int i, int j) const { return data[j][i]; };
125 GLfloat &operator ()(int i, int j) { return data[j][i]; }; 123 GLfloat &operator ()(int i, int j) { return data[j][i]; };
126 124
143const vec3 operator *(const matrix &a, const vec3 &v); 141const vec3 operator *(const matrix &a, const vec3 &v);
144 142
145typedef vec3 point; 143typedef vec3 point;
146 144
147// a generic plane 145// a generic plane
148struct plane { 146struct plane
147{
149 vec3 n; 148 vec3 n;
150 GLfloat d; 149 GLfloat d;
151 150
152 GLfloat distance (const point &p) const 151 GLfloat distance (const point &p) const
153 { 152 {
158 plane (GLfloat a, GLfloat b, GLfloat c, GLfloat d); 157 plane (GLfloat a, GLfloat b, GLfloat c, GLfloat d);
159}; 158};
160 159
161void renormalize (sector &s, point &p); 160void renormalize (sector &s, point &p);
162 161
163struct colour { 162struct colour
163{
164 GLfloat r, g, b, a; 164 GLfloat r, g, b, a;
165 colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1., GLfloat a = 1.) : r(r), g(g), b(b), a(a) { }; 165 colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1., GLfloat a = 1.) : r(r), g(g), b(b), a(a) { };
166}; 166};
167 167
168struct texc { 168struct texc
169{
169 GLfloat s, t; 170 GLfloat s, t;
170 texc () { }; 171 texc () { };
171 texc (GLfloat s, GLfloat t) : s(s), t(t) { }; 172 texc (GLfloat s, GLfloat t) : s(s), t(t) { };
172}; 173};
173 174
174struct box { 175struct box
176{
175 point a, b; 177 point a, b;
176 178
177 box() { }; 179 box() { };
178 180
179 void reset () 181 void reset ()
184 186
185 void add (const box &o); 187 void add (const box &o);
186 void add (const point &p); 188 void add (const point &p);
187}; 189};
188 190
189struct light {
190 point p;
191 colour c;
192 GLfloat intensity;
193 GLfloat radius;
194};
195
196struct material {
197 colour diffuse, specular, emission;
198 GLfloat shininess;
199
200 material ()
201 {
202 diffuse = colour (1, 0, 1, 1);
203 specular = colour (1, 0, 1, 1);
204 emission = colour (1, 0, 1, 1);
205 shininess = 1;
206 }
207};
208
209struct entity; 191struct entity;
210struct geometry; 192struct geometry;
211struct view; 193struct view;
212struct octant; 194struct octant;
213 195
214extern struct timer { 196extern struct timer
197{
215 static double now; 198 static double now;
216 static double diff; 199 static double diff;
217 200
218 static void frame (); 201 static void frame ();
219 timer (); 202 timer ();
220} timer; 203} timer;
221 204
222/* 205/*
223#define MAX_EVENT_TYPES 10 206#define MAX_EVENT_TYPES 10
224enum event_type { TIMER_EV }; 207enum event_type { TIMER_EV };
225struct event { 208struct event
209{
226 event_type type; 210 event_type type;
227}; 211};
228 212
229typedef callback1<void, event&> event_cb; 213typedef callback1<void, event&> event_cb;
230 214
231class skedjuhlar { 215class skedjuhlar
232 216{
233 public: 217 public:
234// only 10 types for now 218// only 10 types for now
235 private: 219 private:
236 vector <list<event_cb> > event_lists; 220 vector <list<event_cb> > event_lists;
237 221
262}; 246};
263 247
264extern skedjuhlar main_scheduler; 248extern skedjuhlar main_scheduler;
265*/ 249*/
266 250
267namespace gl { 251namespace gl
252{
268 void draw_box (const view &ctx, const sector &a, const sector &b); 253 void draw_box (const view &ctx, const sector &a, const sector &b);
269 254
270 extern int nesting; 255 extern int nesting;
271 void errchk (const char *name, const char *args, const char *file, int line); 256 void errchk (const char *name, const char *args, const char *file, int line);
272} 257}
282 value <<= 1; 267 value <<= 1;
283 } 268 }
284 return value; 269 return value;
285} 270}
286 271
287struct TextureExecption { 272struct TextureExecption
273{
288 TextureExecption (string s) : msg(s) { } 274 TextureExecption (string s) : msg(s) { }
289 string msg; 275 string msg;
290}; 276};
291 277
292struct Texture { 278struct Texture
279{
293 SDL_Surface *image; 280 SDL_Surface *image;
294 GLuint texture; 281 GLuint texture;
295 GLfloat texcoord[4]; 282 GLfloat texcoord[4];
296 283
297public: 284public:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines