# 3D Transformations

## This section deals with the 3D transformation
functions.

Transformation allow you to change the place where things are
drawn in the world. For example, the function to draw blocks can
only draw axis-parallel blocks, but by first setting a rotation
transformation you can create rotated blocks. Also sprites are
always drawn parallel to the xy-plane, but by setting a
transformation you can change this. There are two types of
functions, functions that *set* the transformation and
functions that *add* transformations, and they are listed
below:

- d3d_transform_set_identity
- d3d_transform_set_translation
- d3d_transform_set_scaling
- d3d_transform_set_rotation_x
- d3d_transform_set_rotation_y
- d3d_transform_set_rotation_z
- d3d_transform_set_rotation_axis
- d3d_transform_add_translation
- d3d_transform_add_scaling
- d3d_transform_add_rotation_x
- d3d_transform_add_rotation_y
- d3d_transform_add_rotation_z
- d3d_transform_add_rotation_axis

Sometimes you temporarily want to save the current
transformation, for example to add an additional transformation and
then restore the old one (this often happens when drawing
hierarchical models). To this end you can push the current
transformation on a stack and later pop it from the stack to make
it the current transformation again. The following functions exist
for this:

- d3d_transform_stack_clear
- d3d_transform_stack_empty
- d3d_transform_stack_push
- d3d_transform_stack_pop
- d3d_transform_stack_top
- d3d_transform_stack_discard

Finally, you have a function that can be used to get the x, y,
and z values for the transformed vertex:

- d3d_transform_vertex

### Matrix Functions

An alternative way to create transforms (and for multiple
transforms this is far more efficient) is to use the matrix
functions. These permit you to get the values of different matrices
(view, projection and world), as well as create your own then
multiply them or change their values and apply them again. The
available matrix functions are listed below:

- matrix_get
- matrix_set
- matrix_build
- matrix_multiply
- is_matrix

##### © Copyright YoYo Games Ltd. 2018 All Rights Reserved