matrix_build_projection_ortho


Description

This function builds an orthographic projection matrix based on the specified parameters listed below (this is the default projection method used when you create a room in GameMaker Studio 2 without changing anything). Sometimes you need to switch from a perspective projection to an orthographic projection which is what this function is for. It is typically used to draw an overlay, for example, to show the score or other aspects as this gives a "flat" view of the elements drawn (ie: no perspective) in a 3D game. See the image below to get an idea of the difference between orthographic and perspective views.

NOTE: You may also need to temporarily switch off hidden surface removal if you want the information to be drawn regardless of the current depth value.


Syntax:

matrix_build_projection_ortho(width, height, znear, zfar);


Arguments:

Argument Description
w The width of the projection.
h The height of the projection.
znear The near clipping plane.
zfar The far clipping plane.


Returns:

Matrix index


Example:

viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0);
projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0);
camera_set_view_mat(view_camera[0], viewmat);
camera_set_proj_mat(view_camera[0], projmat);

The above code creates a new look-at matrix and orthographic matrix, stores their IDs in local variables and then uses them to set the view and projection matrices for the camera assigned to view port[0].


Back: Matrix Functions
Next: matrix_build_projection_perspective
© Copyright YoYo Games Ltd. 2018 All Rights Reserved