28 return (a - b).length();
75 +
vec3<T>(M[2][0], M[2][1], M[2][2]) * V.
z +
vec3<T>(M[3][0], M[3][1], M[3][2]);
76 translation[3][0] = res.
x;
77 translation[3][1] = res.
y;
78 translation[3][2] = res.
z;
106 Result[3][0] = -(s *
eye);
107 Result[3][1] = -(u *
eye);
108 Result[3][2] = (f *
eye);
122 mat4<T> ortho(
const float& left,
const float& right,
const float& bottom,
const float& top) {
124 mat[0][0] =
static_cast<T
>(2) / (right - left);
125 mat[1][1] =
static_cast<T
>(2) / (top - bottom);
126 mat[2][2] = -
static_cast<T
>(1);
127 mat[3][0] = -(right + left) / (right - left);
128 mat[3][1] = -(top + bottom) / (top - bottom);
144 perspective(
const float& FOV,
const float& width,
const float& height,
const float& zNear,
const float& zFar) {
145 float halfTanFOV = tanf(FOV /
static_cast<T
>(2));
146 float aspect = width / height;
148 static_cast<T
>(1) / (aspect * halfTanFOV),
153 static_cast<T
>(1) / (halfTanFOV),
158 -(zFar + zNear) / (zFar - zNear),
162 -(
static_cast<T
>(2) * zFar * zNear) / (zFar - zNear),
193 out[0][0] = mat[0][0] * factor[0];
194 out[0][1] = mat[0][1] * factor[0];
195 out[0][2] = mat[0][2] * factor[0];
196 out[0][3] = mat[0][3] * factor[0];
197 out[1][0] = mat[1][0] * factor[1];
198 out[1][1] = mat[1][1] * factor[1];
199 out[1][2] = mat[1][2] * factor[1];
200 out[1][3] = mat[1][3] * factor[1];
201 out[2][0] = mat[2][0] * factor[2];
202 out[2][1] = mat[2][1] * factor[2];
203 out[2][2] = mat[2][2] * factor[2];
204 out[2][3] = mat[2][3] * factor[2];
205 out[3][0] = mat[3][0] *
static_cast<T
>(1.0);
206 out[3][1] = mat[3][1] *
static_cast<T
>(1.0);
207 out[3][2] = mat[3][2] *
static_cast<T
>(1.0);
208 out[3][3] = mat[3][3] *
static_cast<T
>(1.0);
222 template<
typename T,
typename U>
224 mat4<T> Inverse = (proj * model).Inverse();
227 tmp.
x = (tmp.
x - T(viewport[0])) / T(viewport[2]);
228 tmp.
y = (tmp.
y - T(viewport[1])) / T(viewport[3]);
229 tmp.
x = tmp.
x *
static_cast<T
>(2) -
static_cast<T
>(1);
230 tmp.
y = tmp.
y *
static_cast<T
>(2) -
static_cast<T
>(1);
248 T
const cosAngle = cosf(angle);
249 T
const sinAngle = sinf(angle);
252 vec3<T> temp((T(1) - cosAngle) * axis);
255 rot[0][0] = cosAngle + temp[0] * axis[0];
256 rot[0][1] = temp[0] * axis[1] + sinAngle * axis[2];
257 rot[0][2] = temp[0] * axis[2] - sinAngle * axis[1];
259 rot[1][0] = temp[1] * axis[0] - sinAngle * axis[2];
260 rot[1][1] = cosAngle + temp[1] * axis[1];
261 rot[1][2] = temp[1] * axis[2] + sinAngle * axis[0];
263 rot[2][0] = temp[2] * axis[0] + sinAngle * axis[1];
264 rot[2][1] = temp[2] * axis[1] - sinAngle * axis[0];
265 rot[2][2] = cosAngle + temp[2] * axis[2];
267 const vec4<T> out0 =
vec4(m[0]) * rot[0][0] +
vec4(m[1]) * rot[0][1] +
vec4(m[2]) * rot[0][2];
268 const vec4<T> out1 =
vec4(m[0]) * rot[1][0] +
vec4(m[1]) * rot[1][1] +
vec4(m[2]) * rot[1][2];
269 const vec4<T> out2 =
vec4(m[0]) * rot[2][0] +
vec4(m[1]) * rot[2][1] +
vec4(m[2]) * rot[2][2];
271 return mat4<T>(out0, out1, out2, out3);
299 return vec3<T>(ax + v * (p2[0] - ax), ay + v * (p2[1] - ay), az + v * (p2[2] - az));
316 return vec4<T>(ax + v * (p2[0] - ax), ay + v * (p2[1] - ay), az + v * (p2[2] - az), aw + v * (p2[3] - aw));
454 if(d == 0.f)
return 1;
455 return d < 0 ? -1 : 1;
468 if(d < 0.f)
return static_cast<T
>(-1) * d;
float distance(const V &a, const V &b)
Definition: utils.h:27
vec2< T > normalize(const vec2< T > &a)
Definition: utils.h:38
mat4< T > perspective(const float &FOV, const float &width, const float &height, const float &zNear, const float &zFar)
Definition: utils.h:144
mat4< T > rotate(const mat4< T > &m, const float &angle, vec3< T > u)
Definition: utils.h:247
mat4< T > lookAt(const vec3< T > &eye, const vec3< T > ¢er, const vec3< T > &up)
Definition: utils.h:91
mat4< T > translate(const mat4< T > &M, const vec3< T > &V)
Definition: utils.h:72
mat4< T > scale(const mat4< T > &mat, const float &factor)
Definition: utils.h:187
vec3< T > unProject(vec3< T > const &win, mat4< T > const &model, mat4< T > const &proj, vec4< U > const &viewport)
Definition: utils.h:223
vec3< T > lerp(const vec3< T > &p1, const vec3< T > &p2, const float &v)
Definition: utils.h:295
vec3< T > max(const vec3< T > &a, const vec3< T > &b)
Definition: utils.h:282
mat4< T > angleAxis(const float &angle, const vec3< T > &axis)
Definition: utils.h:174
mat4< T > ortho(const float &left, const float &right, const float &bottom, const float &top)
Definition: utils.h:122
Matrix< double > eye(size_t rows, size_t columns=0)
vec2< T > normalize() const
Definition: vec2.h:91
vec3< T > normalize() const
Definition: vec3.h:141
float length() const
Definition: vec3.h:136
vec3< T > cross(const vec3< T > &rhs) const
Definition: vec3.h:124
vec4< T > normalize() const
Definition: vec4.h:118
T abs(const T &d)
Definition: utils.h:467
T sign(const T &d)
Definition: utils.h:453
void * value_ptr(vec2< T > &vec)
Definition: utils.h:327