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);
163 float invtf = 1.0f / tan(fovy * 0.5
f);
164 m[0].
x = invtf / aspect;
166 m[2].
z = -(z_far +
z_near) / (z_far - z_near);
168 m[3].
z = (-2.0f * z_far *
z_near) / (z_far - z_near);
176 m[0].
x = 2.0f / (right -
left);
177 m[3].
x = -(right +
left) / (right - left);
178 m[1].
y = 2.0f / (top -
bottom);
179 m[3].
y = -(top +
bottom) / (top - bottom);
180 m[2].
z = -2.0f / (z_far -
z_near);
181 m[3].
z = -(z_far +
z_near) / (z_far - z_near);
187 float co = cosf(rad);
float si = sinf(rad);
189 m[1][1] = co; m[1][2] = -si; m[2][1] = si; m[2][2] = co;
195 float co = cosf(rad);
float si = sinf(rad);
197 m[0][0] = co; m[0][2] = si; m[2][0] = -si; m[2][2] = co;
203 float co = cosf(rad);
float si = sinf(rad);
205 m[0][0] = co; m[1][0] = -si; m[0][1] = si; m[1][1] = co;
212 m[3][0] =
x; m[3][1] =
y; m[3][2] = z; m[3][3] = 1.0f;
219 m[3][0] = v.
x; m[3][1] = v.
y; m[3][2] = v.
z;
226 m[0][0] =
x; m[1][1] =
y; m[2][2] = z;
232 return scale(s, s, s);
vec4 operator+(const vec4 &rhs) const
vec2 & operator-=(const vec2 &rhs)
vec3 & operator+=(const vec3 &rhs)
vec4 & operator-=(const vec4 &rhs)
vec2 operator*(const vec2 &rhs) const
static mat4 rotateY(float rad)
vec2 & operator+=(const vec2 &rhs)
float & operator[](unsigned int i)
vec2 & operator*=(const float s)
static mat4 perspective(float fovy, float aspect, float z_near, float z_far)
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)
GLfloat GLfloat GLfloat w
static mat4 rotateZ(float rad)
float & operator[](unsigned int i)
static mat4 orthographic(float left, float right, float bottom, float top, float z_near, float z_far)
static vec3 normalize(const vec3 &v)
vec3 operator+(const vec3 &rhs) const
vec4 & operator*=(const float s)
vec4 & operator+=(const vec4 &rhs)
static mat4 rotateX(float rad)
GLint GLint GLint GLint GLint x
vec2 operator+(const vec2 &rhs) const
vec4 operator*(const vec4 &rhs) const
static mat4 translate(float x, float y, float z)
static mat4 scale(float x, float y, float z)
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