I have a very simple voxel engine and so far it works based on coordinates, e.g. x, y, z. I was wondering if there is a formula for rotating groups of voxels/coordinates from the x axis(e.g. [0, 1, 0][1, 0, 1] rotates to [1, 0, 0][0, 0, 1] when rotated 90 degrees anticlockwise along the x axis) from a certain point, but I hear it involves matrixes and quaternions which sound scary.


1) The non-scary way to do 90-degree rotations is to swap a set of axes, and negate one of them:

Rotated along x-axis: swap Y/Z to Z/-Y
(a,b,c) -> (a,c,-b)
  • 1
    \$\begingroup\$ The algorithm is to multiply by a matrix of sin(angle) and cosine(angle). The reason this works in particular is because the sin/cosine of a right angle is 1/0 respectively. There's a series of posts that Wolfire did here: blog.wolfire.com/2010/07/… that may be useful for the full formula. \$\endgroup\$ – Jimmy Aug 31 '12 at 18:05

You can't get too far into any 3D programming without matrices or quaternions. It's not too scary though. There are plenty of resources available to you, since you can use some existing resources 3D model transformations. Just think of all your voxel positions as vertex positions.

With that in mind, you can apply a transformation matrix to the voxel positions. However, I imagine you'd want your voxel positions to still align to a grid afterwards, so you'd need to pick your transformations carefully.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.