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

Comparing libgender/util.h (file contents):
Revision 1.31 by root, Sat Oct 9 11:15:00 2004 UTC vs.
Revision 1.32 by root, Sat Oct 9 16:36:31 2004 UTC

28#define OFFS_BITS 31 28#define OFFS_BITS 31
29#define SOFFS_MIN (soffs)-(1 << (OFFS_BITS - 2)) 29#define SOFFS_MIN (soffs)-(1 << (OFFS_BITS - 2))
30#define SOFFS_MAX (soffs)+(1 << (OFFS_BITS - 2)) 30#define SOFFS_MAX (soffs)+(1 << (OFFS_BITS - 2))
31#define MAXEXTENT (1UL << (OFFS_BITS - 1)) 31#define MAXEXTENT (1UL << (OFFS_BITS - 1))
32 32
33#define GLFLOAT_MAX 1e30
34#define GLFLOAT_MIN -1e30
35
36struct vec3 {
37 GLfloat x, y, z;
38 vec3 () { };
39 vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { };
40
41 const vec3 operator -() const
42 { return vec3 (-x, -y, -z); }
43};
44
45const vec3 normalize (const vec3 &v);
46const vec3 cross (const vec3 &a, const vec3 &b);
47
48inline const vec3 operator *(const vec3 &a, GLfloat s)
49{
50 return vec3 (a.x * s, a.y * s, a.z * s);
51}
52
53inline const vec3 operator +(const vec3 &a, const vec3 &b)
54{
55 return vec3 (a.x + b.x, a.y + b.y, a.z + b.z);
56}
57
58inline const vec3 operator -(const vec3 &a, const vec3 &b)
59{
60 return vec3 (a.x - b.x, a.y - b.y, a.z - b.z);
61}
62
63inline GLfloat dot (const vec3 &a, const vec3 &b)
64{
65 return a.x * b.x + a.y * b.y + a.z * b.z;
66}
67
68inline const GLfloat abs (const vec3 &v)
69{
70 return sqrtf (dot (v, v));
71}
72
73struct matrix {
74 GLfloat data[4][4];
75
76 const GLfloat operator ()(int i, int j) const { return data[j][i]; };
77 GLfloat &operator ()(int i, int j) { return data[j][i]; };
78
79 void diagonal (GLfloat v);
80 void clear () { diagonal (0.); };
81 void identity () { diagonal (1.); };
82
83 void print (); // ugly
84
85 static const matrix translation (const vec3 &v);
86 static const matrix rotation (GLfloat degrees, const vec3 &axis);
87
88 matrix () { };
89 matrix (GLfloat diag) { diagonal (diag); };
90};
91
92const matrix operator *(const matrix &a, const matrix &b);
93const vec3 operator *(const matrix &a, const vec3 &v);
94
95typedef vec3 point;
96
97// a generic plane
98struct plane {
99 vec3 n;
100 GLfloat d;
101
102 GLfloat distance (const point &p) const
103 {
104 return dot (n, p) + d;
105 }
106
107 plane () { };
108 plane (GLfloat a, GLfloat b, GLfloat c, GLfloat d);
109};
110
111struct sector { 33struct sector {
112 soffs x, y, z; 34 soffs x, y, z;
113 35
114 sector (soffs x, soffs y, soffs z) : x(x), y(y), z(z) { }; 36 sector (soffs x, soffs y, soffs z) : x(x), y(y), z(z) { };
115 sector (soffs xyz = 0) : x(xyz), y(xyz), z(xyz) { }; 37 sector (soffs xyz = 0) : x(xyz), y(xyz), z(xyz) { };
154 76
155inline sector abs (const sector &s) 77inline sector abs (const sector &s)
156{ 78{
157 return sector (abs (s.x), abs (s.y), abs (s.z)); 79 return sector (abs (s.x), abs (s.y), abs (s.z));
158} 80}
81
82struct vec3 {
83 GLfloat x, y, z;
84 vec3 () { };
85 vec3 (GLfloat s) : x(s), y(s), z(s) { };
86 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) { };
88
89 const vec3 operator -() const
90 { return vec3 (-x, -y, -z); }
91};
92
93const vec3 normalize (const vec3 &v);
94const vec3 cross (const vec3 &a, const vec3 &b);
95
96inline const vec3 operator *(const vec3 &a, GLfloat s)
97{
98 return vec3 (a.x * s, a.y * s, a.z * s);
99}
100
101inline const vec3 operator +(const vec3 &a, const vec3 &b)
102{
103 return vec3 (a.x + b.x, a.y + b.y, a.z + b.z);
104}
105
106inline const vec3 operator -(const vec3 &a, const vec3 &b)
107{
108 return vec3 (a.x - b.x, a.y - b.y, a.z - b.z);
109}
110
111inline GLfloat dot (const vec3 &a, const vec3 &b)
112{
113 return a.x * b.x + a.y * b.y + a.z * b.z;
114}
115
116inline const GLfloat abs (const vec3 &v)
117{
118 return sqrtf (dot (v, v));
119}
120
121struct matrix {
122 GLfloat data[4][4];
123
124 const GLfloat operator ()(int i, int j) const { return data[j][i]; };
125 GLfloat &operator ()(int i, int j) { return data[j][i]; };
126
127 void diagonal (GLfloat v);
128 void clear () { diagonal (0.F); };
129 void identity () { diagonal (1.F); };
130
131 void print (); // ugly
132
133 static const matrix translation (const vec3 &v);
134 static const matrix rotation (GLfloat degrees, const vec3 &axis);
135
136 matrix () { };
137 matrix (GLfloat diag) { diagonal (diag); };
138};
139
140const matrix operator *(const matrix &a, const matrix &b);
141const vec3 operator *(const matrix &a, const vec3 &v);
142
143typedef vec3 point;
144
145// a generic plane
146struct plane {
147 vec3 n;
148 GLfloat d;
149
150 GLfloat distance (const point &p) const
151 {
152 return dot (n, p) + d;
153 }
154
155 plane () { };
156 plane (GLfloat a, GLfloat b, GLfloat c, GLfloat d);
157};
159 158
160void renormalize (sector &s, point &p); 159void renormalize (sector &s, point &p);
161 160
162struct colour { 161struct colour {
163 GLfloat r, g, b, a; 162 GLfloat r, g, b, a;
206}; 205};
207 206
208struct entity; 207struct entity;
209struct geometry; 208struct geometry;
210struct view; 209struct view;
210struct octant;
211 211
212extern struct timer { 212extern struct timer {
213 static double now; 213 static double now;
214 static double diff; 214 static double diff;
215 215

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines