Skip to content

Commit

Permalink
libdeng2|Matrix: Perspective projection with a FOV angle
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 28, 2013
1 parent 7d96079 commit 08502ef
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions doomsday/libdeng2/include/de/matrix.h
Expand Up @@ -322,15 +322,27 @@ class Matrix4
static Matrix4 ortho(Type left, Type right, Type top, Type bottom,
Type near = -1.f, Type far = 1.f) {
Matrix4 m;
m.at(0, 0) = 2.f / (right - left);
m.at(1, 1) = 2.f / (top - bottom);
m.at(2, 2) = -2.f / (far - near);
m.at(0, 0) = Type(2) / (right - left);
m.at(1, 1) = Type(2) / (top - bottom);
m.at(2, 2) = -Type(2) / (far - near);
m[12] = -(right + left) / (right - left);
m[13] = -(top + bottom) / (top - bottom);
m[14] = -(far + near) / (far - near);
return m;
}
static Matrix4 perspective(Type width, Type height, Type near = 1.f, Type far = 1000.f, Type zoom = 1.f) {
static Matrix4 perspective(Type fov, Type aspectRatio, Type near = 1.f, Type far = 1000.f) {
Type const halfWidth = std::tan(Type(.5) * degreeToRadian(fov));
Type const halfHeight = halfWidth / aspectRatio;
Type const depth = far - near;
Matrix4 m(Zero);
m.at(0, 0) = Type(1) / halfWidth;
m.at(1, 1) = Type(1) / halfHeight;
m.at(2, 2) = -(far + near) / depth;
m.at(2, 3) = -Type(1);
m.at(3, 2) = -Type(2) * far * near / depth;
return m;
}
static Matrix4 perspectiveZoom(Type width, Type height, Type near = 1.f, Type far = 1000.f, Type zoom = 1.f) {
Type const zoomHalf = zoom / 2;
Type const aspect = width / height;
Type const left = -zoomHalf;
Expand Down Expand Up @@ -403,7 +415,7 @@ class Matrix4
m[8] = s.z;
m[9] = u.z;
m[10] = -f.z;
m[15] = 1;
m[15] = Type(1);
return m * translate(-eyePos);
}

Expand Down

0 comments on commit 08502ef

Please sign in to comment.