61 lines
811 B
C++
61 lines
811 B
C++
Vec3
|
|
Transform(Vec3 &vec, Mat4 &mat, f32 last = 1.0)
|
|
{
|
|
Vec3 dst = {};
|
|
glm_mat4_mulv3(mat.matrix, vec.v, last, dst.v);
|
|
return dst;
|
|
}
|
|
|
|
f32
|
|
Dot(Vec3 &lhs, Vec3 &rhs)
|
|
{
|
|
return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z;
|
|
}
|
|
|
|
Vec3
|
|
Normalize(Vec3 &vec)
|
|
{
|
|
f32 length = sqrtf(Dot(vec, vec));
|
|
|
|
Vec3 result = vec;
|
|
if(length < 0.00009f)
|
|
{
|
|
result.x = 0.0f;
|
|
result.y = 0.0f;
|
|
result.z = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
result.x *= 1.0f/length;
|
|
result.y *= 1.0f/length;
|
|
result.z *= 1.0f/length;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
Mat4
|
|
Inverse(Mat4 mat)
|
|
{
|
|
Mat4 result;
|
|
glm_mat4_inv(mat.matrix, result.matrix);
|
|
return result;
|
|
}
|
|
|
|
Quat
|
|
AngleAxis(f32 angle, Vec3 axis)
|
|
{
|
|
Quat q;
|
|
glm_quat(q.quat, angle, axis.x, axis.y, axis.z);
|
|
return q;
|
|
}
|
|
|
|
Mat4
|
|
ToMat4(Quat quat)
|
|
{
|
|
Mat4 mat;
|
|
glm_quat_mat4(quat.quat, mat.matrix);
|
|
return mat;
|
|
}
|
|
|