Class Projection
java.lang.Object
org.flag4j.linalg.transformations.Projection
This class contains methods usefully for computing projection transformation matrices.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix
getOrthogonal
(double xMax, double yMax, double nearClip, double farClip) Creates a4x4
orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e.static Matrix
getOrthogonal
(double xMin, double xMax, double yMin, double yMax, double nearClip, double farClip) Creates a4x4
orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e.static Matrix
getOrthogonal2D
(double xMax, double yMax) Creates a4x4
orthogonal projection matrix to project a 2D point in an orthographic viewing region.static Matrix
getOrthogonal2D
(double xMin, double xMax, double yMin, double yMax) Creates a4x4
orthogonal projection matrix to project a 2D point in an orthographic viewing region.static Matrix
getPerspective
(double fov, double aspectRatio, double nearClip, double farClip) Creates a4x4
perspective projection matrix to transform a 3D point represented in homogeneous coordinates.static Matrix
getPerspective
(double fovX, double fovY, double aspectRatio, double nearClip, double farClip) Creates a4x4
perspective projection matrix to transform a 3D point represented in homogeneous coordinates.
-
Constructor Details
-
Projection
private Projection()
-
-
Method Details
-
getPerspective
public static Matrix getPerspective(double fov, double aspectRatio, double nearClip, double farClip) Creates a4x4
perspective projection matrix to transform a 3D point represented in homogeneous coordinates.- Parameters:
fov
- Field of view in radians (this is the fov in both thex
andy
directions). For distinct field of views seegetPerspective(double, double, double, double, double)
.aspectRatio
- Aspect ratio of the image plane to project to (i.e.width/height
).nearClip
- The distance from the camera to the near clipping plane.farClip
- The distance from the camera to the far clipping plane.- Returns:
- The perspective projection matrix based on the provided attributes.
- Throws:
IllegalArgumentException
- IfaspectRatio
is not positive.AssertionError
- IfnearClip!=farClip
.
-
getPerspective
public static Matrix getPerspective(double fovX, double fovY, double aspectRatio, double nearClip, double farClip) Creates a4x4
perspective projection matrix to transform a 3D point represented in homogeneous coordinates.- Parameters:
fovX
- Field of view, in radians, in thex
direction.fovY
- Field of view, in radians, in they
direction.aspectRatio
- Aspect ratio of the image plane to project to (i.e.width/height
).nearClip
- The distance from the camera to the near clipping plane.farClip
- The distance from the camera to the far clipping plane.- Returns:
- The perspective projection matrix based on the provided attributes.
- Throws:
IllegalArgumentException
- IfaspectRatio
is not positive.AssertionError
- IfnearClip!=farClip
.
-
getOrthogonal
public static Matrix getOrthogonal(double xMin, double xMax, double yMin, double yMax, double nearClip, double farClip) Creates a4x4
orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane). This is an orthographic projection meaning the distance from the virtual camera will not affect the projection.- Parameters:
xMin
- Minimumx
value of image plane to project to.xMax
- Maximumx
value of image plane to project to.yMin
- Minimumy
value of image plane to project to.yMax
- Maximumy
value of image plane to project to.nearClip
- Distance from camera to near clipping plane.farClip
- Distance from camera to far clipping plane.- Returns:
- The orthogonal projection for the specified parameters.
-
getOrthogonal
Creates a4x4
orthogonal projection matrix to project a 3D point in homogeneous coordinates onto the specified 2D coordinate grid (i.e. image plane). Here, the minimumx
andy
values are taken to be zero. This is an orthographic projection meaning the distance from the virtual camera will not affect the projection.- Parameters:
xMax
- Maximumx
value of image plane to project to.yMax
- Maximumy
value of image plane to project to.nearClip
- Distance from camera to near clipping plane.farClip
- Distance from camera to far clipping plane.- Returns:
- The orthogonal projection for the specified parameters.
-
getOrthogonal2D
Creates a4x4
orthogonal projection matrix to project a 2D point in an orthographic viewing region. Equivalent togetOrthogonal(double, double, double, double, double, double)
withnearClip=-1
andfarClip = 1
.- Parameters:
xMin
- Minimumx
value of image plane to project to.xMax
- Maximumx
value of image plane to project to.yMin
- Minimumy
value of image plane to project to.yMax
- Maximumy
value of image plane to project to.- Returns:
- The orthogonal projection for the specified parameters.
-
getOrthogonal2D
Creates a4x4
orthogonal projection matrix to project a 2D point in an orthographic viewing region. the minimumx
andy
values are assumed to be zero. Equivalent togetOrthogonal(double, double, double, double)
withnearClip=-1
andfarClip = 1
.- Parameters:
xMax
- Maximumx
value of image plane to project to.yMax
- Maximumy
value of image plane to project to.- Returns:
- The orthogonal projection for the specified parameters.
-