35 lines
841 B
C++
35 lines
841 B
C++
#pragma once
|
|
|
|
#include <Orange/Math/Common.h>
|
|
|
|
namespace orange
|
|
{
|
|
mat4 translate(const vec3& v)
|
|
{
|
|
mat4 result;
|
|
result[3] = vec4{ v[0], v[1], v[2], 1.0f };
|
|
return result;
|
|
}
|
|
|
|
mat4 scale(const vec3& v)
|
|
{
|
|
return mat4{vec4{v[0], v[1], v[2], 1.0f}};
|
|
}
|
|
|
|
mat4 perspective(const Radian& fovy, float aspect, float zNear, float zFar)
|
|
{
|
|
Assert(fabsf(aspect - Math::Epsilon) > 0.0f && "Math::perspective `fovy` is 0/inf.");
|
|
|
|
const float tanHalfFovy = Math::tan(0.5f * fovy);
|
|
|
|
mat4 result{0.0f};
|
|
result[0][0] = 1.0f / (aspect * tanHalfFovy);
|
|
result[1][1] = 1.0f / (tanHalfFovy);
|
|
result[2][2] = -(zFar + zNear) / (zFar - zNear);
|
|
result[2][3] = -1.0f;
|
|
result[3][2] = -2.0f * zFar * zNear / (zFar - zNear);
|
|
|
|
return result;
|
|
}
|
|
}
|