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)
127 m[rcol][lrow] += (*this)[k][lrow] * rhs[rcol][k];
146 return x * rhs.
x +
y * rhs.
y +
z * rhs.
z +
w * rhs.
w;
157 return v / sqrt(v.
x * v.
x + v.
y * v.
y + v.
z * v.
z);
177 float invtf = 1.0f / tan(fovy * 0.5
f);
178 m[0].
x = invtf / aspect;
180 m[2].
z = -(z_far +
z_near) / (z_far - z_near);
182 m[3].
z = (-2.0f * z_far *
z_near) / (z_far - z_near);
190 m[0].
x = 2.0f / (right -
left);
191 m[3].
x = -(right +
left) / (right - left);
192 m[1].
y = 2.0f / (top -
bottom);
193 m[3].
y = -(top +
bottom) / (top - bottom);
194 m[2].
z = -2.0f / (z_far -
z_near);
195 m[3].
z = -(z_far +
z_near) / (z_far - z_near);
201 float co = cosf(rad);
float si = sinf(rad);
203 m[1][1] = co; m[1][2] = -si; m[2][1] = si; m[2][2] = co;
209 float co = cosf(rad);
float si = sinf(rad);
211 m[0][0] = co; m[0][2] = si; m[2][0] = -si; m[2][2] = co;
217 float co = cosf(rad);
float si = sinf(rad);
219 m[0][0] = co; m[1][0] = -si; m[0][1] = si; m[1][1] = co;
226 m[3][0] =
x; m[3][1] =
y; m[3][2] = z; m[3][3] = 1.0f;
233 m[3][0] = v.
x; m[3][1] = v.
y; m[3][2] = v.
z;
240 m[0][0] =
x; m[1][1] =
y; m[2][2] = z;
246 return scale(s, s, s);
static mat4 scale(float x, float y, float z)
vec4 operator+(const vec4 &rhs) const
vec2 & operator-=(const vec2 &rhs)
vec3 & operator+=(const vec3 &rhs)
GLboolean GLboolean GLboolean GLboolean a
static mat4 perspective(float fovy, float aspect, float z_near, float z_far)
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 transpose(const mat4 &m)
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 translate(float x, float y, float z)
GLfloat GLfloat GLfloat w
float & operator[](unsigned int i)
static mat4 rotateY(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
vec4 operator*(const vec4 &rhs) const
static vec3 normalize(const vec3 &v)
GLboolean GLboolean GLboolean b
static mat4 rotateX(float rad)
static mat4 orthographic(float left, float right, float bottom, float top, float z_near, float z_far)
vec3 operator/(const float s) const
mat4 operator*(const mat4 &rhs)
float & operator[](unsigned int i)
static mat4 rotateZ(float rad)
vec3(float X, float Y, float Z)
vec4(float X, float Y, float Z, float W)
vec2 operator/(const float s) const