Esempio n. 1
0
mat4x4 CreateProjectionMatrix( float fovy,

                               float aspect_ratio,

                               float near_plane,

                               float far_plane )
{
    mat4x4 out = { { 0 } };

    const float y_scale = Cotangent(DegreesToRadians(fovy / 2));

    const float x_scale = y_scale / aspect_ratio;

    const float frustum_length = far_plane - near_plane;

    out.m[0] = x_scale;

    out.m[5] = y_scale;

    out.m[10] = -((far_plane + near_plane) / frustum_length);

    out.m[11] = -1;

    out.m[14] = -((2 * near_plane * far_plane) / frustum_length);

    return out;
}
Esempio n. 2
0
Matrix CreateProjectionMatrix(
	float fovy,
	float aspect_ratio,
	float near_plane,
	float far_plane
)
{
	Matrix out = { { 0 } };

	const float
		y_scale = Cotangent((fovy*M_PI/180) / 2),
		x_scale = y_scale / aspect_ratio,
		frustum_length = far_plane - near_plane;

	out.m[0] = x_scale;
	out.m[5] = y_scale;
	out.m[10] = -((far_plane + near_plane) / frustum_length);
	out.m[11] = -1;
	out.m[14] = -((2 * near_plane * far_plane) / frustum_length);
	
	return out;
}