|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2020 Photon Storm Ltd. |
| 4 | + * @license {@link https://opensource.org/licenses/MIT|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * Translates the model matrix by the given values. |
| 9 | + * |
| 10 | + * @method Phaser.Renderer.WebGL.MVP.ProjectOrtho |
| 11 | + * @since 3.25.0 |
| 12 | + * |
| 13 | + * @param {Phaser.Renderer.WebGL.Pipelines.ModelViewProjection} model - The Model View Projection object. |
| 14 | + * @param {number} left - The left value. |
| 15 | + * @param {number} right - The right value. |
| 16 | + * @param {number} bottom - The bottom value. |
| 17 | + * @param {number} top - The top value. |
| 18 | + * @param {number} near - The near value. |
| 19 | + * @param {number} far - The far value. |
| 20 | + * |
| 21 | + * @return {Phaser.Renderer.WebGL.Pipelines.ModelViewProjection} The Model View Projection object. |
| 22 | + */ |
| 23 | +var ProjectOrtho = function (model, left, right, bottom, top, near, far) |
| 24 | +{ |
| 25 | + var projectionMatrix = model.projectionMatrix; |
| 26 | + var leftRight = 1 / (left - right); |
| 27 | + var bottomTop = 1 / (bottom - top); |
| 28 | + var nearFar = 1 / (near - far); |
| 29 | + |
| 30 | + projectionMatrix[0] = -2 * leftRight; |
| 31 | + projectionMatrix[1] = 0; |
| 32 | + projectionMatrix[2] = 0; |
| 33 | + projectionMatrix[3] = 0; |
| 34 | + projectionMatrix[4] = 0; |
| 35 | + projectionMatrix[5] = -2 * bottomTop; |
| 36 | + projectionMatrix[6] = 0; |
| 37 | + projectionMatrix[7] = 0; |
| 38 | + projectionMatrix[8] = 0; |
| 39 | + projectionMatrix[9] = 0; |
| 40 | + projectionMatrix[10] = 2 * nearFar; |
| 41 | + projectionMatrix[11] = 0; |
| 42 | + projectionMatrix[12] = (left + right) * leftRight; |
| 43 | + projectionMatrix[13] = (top + bottom) * bottomTop; |
| 44 | + projectionMatrix[14] = (far + near) * nearFar; |
| 45 | + projectionMatrix[15] = 1; |
| 46 | + |
| 47 | + model.projectionMatrixDirty = true; |
| 48 | + |
| 49 | + return model; |
| 50 | +}; |
| 51 | + |
| 52 | +module.exports = ProjectOrtho; |
0 commit comments