24 #define PI 3.141592653f 33 vec2() : x(0.0f), y(0.0f) { }
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]; }
57 vec3() : x(0.0f), y(0.0f), z(0.0f) { }
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]; }
82 vec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) { }
83 vec4(
vec3 V,
float W) : x(V.x), y(V.y), z(V.z), w(W) { }
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]; }
109 explicit mat4(
float s) : x(0.0f), y(0.0f), z(0.0f), w(0.0f)
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.5f);
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);
187 static mat4 orthographic(
float left,
float right,
float bottom,
float top,
float z_near,
float z_far)
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);
vec2 & operator-=(const vec2 &rhs)
static mat4 perspective(float fovy, float aspect, float z_near, float z_far)
static mat4 scale(float x, float y, float z)
static mat4 rotateZ(float rad)
vec2 operator*(const vec2 &rhs) const
static mat4 rotateX(float rad)
static mat4 rotateY(float rad)
vec2 & operator+=(const vec2 &rhs)
float & operator[](unsigned int i)
static vec3 normalize(const vec3 &v)
vec2 & operator*=(const float s)
vec2 operator-(const vec2 &rhs) const
const float * value_ptr() const
static mat4 orthographic(float left, float right, float bottom, float top, float z_near, float z_far)
static mat4 translate(float x, float y, float z)
vec2 operator+(const vec2 &rhs) const
static mat4 transpose(const mat4 &m)
vec3(float X, float Y, float Z)
vec4(float X, float Y, float Z, float W)
vec2 operator/(const float s) const