24 #define PI 3.141592653f
34 vec2(
float X,
float Y) :
x(X),
y(Y){ }
35 explicit vec2(
float S) :
x(S),
y(S) { }
48 const float &
operator [] (
unsigned int i)
const {
return (&
x)[i]; }
58 vec3(
float X,
float Y,
float Z) :
x(X),
y(Y),
z(Z) { }
59 explicit vec3(
float S) :
x(S),
y(S),
z(S) { }
72 const float &
operator [] (
unsigned int i)
const {
return (&
x)[i]; }
84 vec4(
float X,
float Y,
float Z,
float W) :
x(X),
y(Y),
z(Z),
w(W) { }
85 explicit vec4(
float S) :
x(S),
y(S),
z(S),
w(S) { }
99 const float &
operator [] (
unsigned int i)
const {
return (&
x)[i]; }
120 for (
int lrow = 0; lrow < 4; ++lrow)
122 for (
int rcol = 0; rcol < 4; ++rcol)
124 m[rcol][lrow] = 0.0f;
125 for (
int k = 0; k < 4; ++k)
126 m[rcol][lrow] += (*
this)[k][lrow] * rhs[rcol][k];
145 return x * rhs.
x +
y * rhs.
y +
z * rhs.
z +
w * rhs.
w;
156 t = (t - edge0) / (edge1 - edge0);
157 t = t < 0.0f ? 0.0f : (t > 1.0f ? 1.0f : t);
158 return t * t * (3.0f - 2.0f * t);
163 return v / sqrt(v.
x * v.
x + v.
y * v.
y + v.
z * v.
z);
169 float invtf = 1.0f / tan(fovy * 0.5
f);
170 m[0].
x = invtf / aspect;
172 m[2].
z = -(far + near) / (far - near);
174 m[3].
z = (-2.0f * far * near) / (far - near);
182 m[0].
x = 2.0f / (right -
left);
183 m[3].
x = -(right +
left) / (right - left);
184 m[1].
y = 2.0f / (top -
bottom);
185 m[3].
y = -(top +
bottom) / (top - bottom);
186 m[2].
z = -2.0f / (far - near);
187 m[3].
z = -(far + near) / (far - near);
198 inv[0] = m[5] * m[10] * m[15] -
199 m[5] * m[11] * m[14] -
200 m[9] * m[6] * m[15] +
201 m[9] * m[7] * m[14] +
202 m[13] * m[6] * m[11] -
203 m[13] * m[7] * m[10];
205 inv[4] = -m[4] * m[10] * m[15] +
206 m[4] * m[11] * m[14] +
207 m[8] * m[6] * m[15] -
208 m[8] * m[7] * m[14] -
209 m[12] * m[6] * m[11] +
210 m[12] * m[7] * m[10];
212 inv[8] = m[4] * m[9] * m[15] -
213 m[4] * m[11] * m[13] -
214 m[8] * m[5] * m[15] +
215 m[8] * m[7] * m[13] +
216 m[12] * m[5] * m[11] -
219 inv[12] = -m[4] * m[9] * m[14] +
220 m[4] * m[10] * m[13] +
221 m[8] * m[5] * m[14] -
222 m[8] * m[6] * m[13] -
223 m[12] * m[5] * m[10] +
226 inv[1] = -m[1] * m[10] * m[15] +
227 m[1] * m[11] * m[14] +
228 m[9] * m[2] * m[15] -
229 m[9] * m[3] * m[14] -
230 m[13] * m[2] * m[11] +
231 m[13] * m[3] * m[10];
233 inv[5] = m[0] * m[10] * m[15] -
234 m[0] * m[11] * m[14] -
235 m[8] * m[2] * m[15] +
236 m[8] * m[3] * m[14] +
237 m[12] * m[2] * m[11] -
238 m[12] * m[3] * m[10];
240 inv[9] = -m[0] * m[9] * m[15] +
241 m[0] * m[11] * m[13] +
242 m[8] * m[1] * m[15] -
243 m[8] * m[3] * m[13] -
244 m[12] * m[1] * m[11] +
247 inv[13] = m[0] * m[9] * m[14] -
248 m[0] * m[10] * m[13] -
249 m[8] * m[1] * m[14] +
250 m[8] * m[2] * m[13] +
251 m[12] * m[1] * m[10] -
254 inv[2] = m[1] * m[6] * m[15] -
255 m[1] * m[7] * m[14] -
256 m[5] * m[2] * m[15] +
257 m[5] * m[3] * m[14] +
258 m[13] * m[2] * m[7] -
261 inv[6] = -m[0] * m[6] * m[15] +
262 m[0] * m[7] * m[14] +
263 m[4] * m[2] * m[15] -
264 m[4] * m[3] * m[14] -
265 m[12] * m[2] * m[7] +
268 inv[10] = m[0] * m[5] * m[15] -
269 m[0] * m[7] * m[13] -
270 m[4] * m[1] * m[15] +
271 m[4] * m[3] * m[13] +
272 m[12] * m[1] * m[7] -
275 inv[14] = -m[0] * m[5] * m[14] +
276 m[0] * m[6] * m[13] +
277 m[4] * m[1] * m[14] -
278 m[4] * m[2] * m[13] -
279 m[12] * m[1] * m[6] +
282 inv[3] = -m[1] * m[6] * m[11] +
283 m[1] * m[7] * m[10] +
284 m[5] * m[2] * m[11] -
285 m[5] * m[3] * m[10] -
289 inv[7] = m[0] * m[6] * m[11] -
290 m[0] * m[7] * m[10] -
291 m[4] * m[2] * m[11] +
292 m[4] * m[3] * m[10] +
296 inv[11] = -m[0] * m[5] * m[11] +
298 m[4] * m[1] * m[11] -
303 inv[15] = m[0] * m[5] * m[10] -
305 m[4] * m[1] * m[10] +
310 float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
316 return inv_mat * det;
321 float co = cosf(rad);
float si = sinf(rad);
323 m[1][1] = co; m[1][2] = -si; m[2][1] = si; m[2][2] = co;
329 float co = cosf(rad);
float si = sinf(rad);
331 m[0][0] = co; m[0][2] = si; m[2][0] = -si; m[2][2] = co;
337 float co = cosf(rad);
float si = sinf(rad);
339 m[0][0] = co; m[1][0] = -si; m[0][1] = si; m[1][1] = co;
346 m[3][0] =
x; m[3][1] =
y; m[3][2] = z; m[3][3] = 1.0f;
353 m[3][0] = v.
x; m[3][1] = v.
y; m[3][2] = v.
z;
360 m[0][0] =
x; m[1][1] =
y; m[2][2] = z;
366 return scale(s, s, s);
vec4 operator+(const vec4 &rhs) const
static vec3 normalize(const vec3 &v)
vec2 & operator-=(const vec2 &rhs)
static mat4 translate(float x, float y, float z)
vec3 & operator+=(const vec3 &rhs)
vec4 & operator-=(const vec4 &rhs)
vec2 operator*(const vec2 &rhs) const
vec2 & operator+=(const vec2 &rhs)
float & operator[](unsigned int i)
vec2 & operator*=(const float s)
static mat4 scale(float x, float y, float z)
vec2 operator-(const vec2 &rhs) const
vec3 & operator*=(const vec3 &rhs)
vec3 operator*(const vec3 &rhs) const
vec4 operator/(const float s) const
vec4 & operator[](unsigned int i)
const float * value_ptr() const
vec3 & operator-=(const vec3 &rhs)
static mat4 orthographic(float left, float right, float bottom, float top, float near, float far)
static mat4 inverse(const mat4 &op)
GLfloat GLfloat GLfloat w
float & operator[](unsigned int i)
static mat4 rotateX(float rad)
static mat4 rotateZ(float rad)
vec3 operator+(const vec3 &rhs) const
vec4 & operator*=(const float s)
vec4 & operator+=(const vec4 &rhs)
GLint GLint GLint GLint GLint x
vec2 operator+(const vec2 &rhs) const
static float smoothstep(float edge0, float edge1, float t)
vec4 operator*(const vec4 &rhs) const
static mat4 perspective(float fovy, float aspect, float near, float far)
static mat4 rotateY(float rad)
vec3 operator/(const float s) const
mat4 operator*(const mat4 &rhs)
float & operator[](unsigned int i)
vec3(float X, float Y, float Z)
vec4(float X, float Y, float Z, float W)
vec2 operator/(const float s) const