Skip to content

Instantly share code, notes, and snippets.

@Dawilly
Last active August 23, 2023 21:36
Show Gist options
  • Save Dawilly/8f3a71c4bfbfea39ca1e5f0925417dc7 to your computer and use it in GitHub Desktop.
Save Dawilly/8f3a71c4bfbfea39ca1e5f0925417dc7 to your computer and use it in GitHub Desktop.
Transformation Matricies for skew/shear in 3D

Transformation Matricies for Skew/Shear effects in 3D games

While working on a game project that involves 2D sprites in 3D space, applying a skew/shear effect resulted in unexpected behaviour as I overlooked (more accurately put, I temporarily forgot) that even though the sprites are in 3D space, the game is being rendered with an orthographic projection. Additionally the game is set up where the Y-axis is up. Thus the creation of this gist to act as a digital post-it note to remind myself and to allow anyone developing their own game / game engine to do the same.

The numeric order of the matricies match with the image visualizing the effects.


1) Skew along the X-Axis, relative to the Y-Axis

matrix_1[] =
{
  1,      0,      0,      0,
  tan(a), 1,      0,      0,
  0,      0,      1,      0,
  0,      0,      0,      1
};

2) Skew along the X-Axis, relative to the Z-Axis

matrix_2[] =
{
  1,      0,      0,      0,
  0,      1,      0,      0,
  tan(a), 0,      1,      0,
  0,      0,      0,      0
};

3) Skew along the Y-Axis, relative to the X-Axis

matrix_3[] =
{
  1,      tan(a), 0,      0,
  0,      1,      0,      0,
  0,      0,      1,      0,
  0,      0,      0,      1
};

4) Skew along the Y-Axis, relative to the Z-Axis

matrix_4[] =
{
  1,      0,      0,      0,
  0,      1,      0,      0,
  0,      tan(a), 1,      0,
  0,      0,      0,      1
};

5) Skew along the Z-Axis, relative to the X-Axis

matrix_5[] =
{
  1,      0,      tan(a), 0,
  0,      1,      0,      0,
  0,      0,      1,      0,
  0,      0,      0,      1
};

6) Skew along the Z-Axis, relative to the Y-Axis

matrix_6[] =
{
  1,      0,      0,      0,
  0,      1,      tan(a), 0,
  0,      0,      1,      0,
  0,      0,      0,      1
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment