There’s three concepts in the render script:
-
Viewport - This is the area of the screen to render. Set using
render.set_viewport()
.
-
View - Created from the position of the camera, the direction the camera is facing and an up-vector (to define what is up and what is down). Created using
vmath.matrix4_look_at()
and set using render.set_view()
.
-
Projection - This is how the view is rendered. Orthographic (typically 2D) or perspective (3D). For orthographic there’s the possibility of rendering stretched, zoomed, fixed fit etc. Near and far z planes are also defined in the projection. Created using
vmath.matrix4_orthographic()
or vmath.matrix4_perspective()
and set using render.set_projection()
.
The view combined with the projection defines what is seen on screen.
When the view is set to vmath.matrix4()
the documentation states that it is a “transform with no translation or rotation.”
And when I talk about screen space I mean a view and projection that is rendered without any translation or rotation to match the screen. Meaning that something positioned at 0,0 is rendered in the lower left corner.
World space on the other hand is how the game world is rendered. Take a top-down shooter for instance with a large game world with a camera that follows the player. This means that something positioned at 0,0 in the game world likely isn’t positioned in the lower left corner since the camera is moving with the player. Defold-Orthographic and RenderCam provides functions to convert from screen to world coordinates and vice versa. This is useful when you want to translate a click on the screen into a world space coordinate for instance.