The Matrix4.makeOrthographic()
method in Three.js is used to create a new orthographic projection matrix. This matrix is typically used in a 3D graphics rendering engine to transform objects onto a two-dimensional surface such as a computer screen.
Matrix4.makeOrthographic(left, right, top, bottom, near, far)
The makeOrthographic()
method creates a new Matrix4 instance with the specified orthographic projection values.
The makeOrthographic()
method creates an orthographic projection matrix using the specified parameters. The resulting matrix can be applied to a camera or object to produce a 2D view of the scene.
The orthographic projection matrix is a transformation matrix that maps 3D coordinates to 2D coordinates. The matrix is composed of six values that describe the size and position of the view frustum. These values are the coordinates of the left, right, top, bottom, near, and far clipping planes.
By default, the coordinate system used in Three.js is right-handed, meaning that positive X is to the right and positive Y is up. To create a left-handed coordinate system, you can specify negative values for the near and far parameters.
To create a new orthographic projection matrix, you can call the makeOrthographic()
method on a new Matrix4 instance. Here is an example that creates an orthographic projection matrix for a 800x600 pixel screen with a 1:1 aspect ratio:
const matrix = new THREE.Matrix4().makeOrthographic(-400, 400, 300, -300, 1, 1000);
This matrix can then be applied to a camera's projection matrix, as shown in this example:
const camera = new THREE.OrthographicCamera(
-400, // left
400, // right
300, // top
-300, // bottom
1, // near
1000 // far
);
camera.matrix.projection = matrix;
The Matrix4.makeOrthographic()
method is a useful tool for creating an orthographic projection matrix that can be used in 3D graphics rendering engines. It allows for 2D projection of 3D scenes onto a screen or other two-dimensional surface. By specifying the size and position of the view frustum, you can control the look and feel of your rendered scene.