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:

  1. d3d_transform_set_identity
  2. d3d_transform_set_translation
  3. d3d_transform_set_scaling
  4. d3d_transform_set_rotation_x
  5. d3d_transform_set_rotation_y
  6. d3d_transform_set_rotation_z
  7. d3d_transform_set_rotation_axis
  8. d3d_transform_add_translation
  9. d3d_transform_add_scaling
  10. d3d_transform_add_rotation_x
  11. d3d_transform_add_rotation_y
  12. d3d_transform_add_rotation_z
  13. 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:

  1. d3d_transform_stack_clear
  2. d3d_transform_stack_empty
  3. d3d_transform_stack_push
  4. d3d_transform_stack_pop
  5. d3d_transform_stack_top
  6. 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:

  1. 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:

  1. matrix_get
  2. matrix_set
  3. matrix_build
  4. matrix_multiply
  5. is_matrix

Back: Working With 3D
Next: 3D Lighting and Fog
© Copyright YoYo Games Ltd. 2015 All Rights Reserved