Question

I've been playing around for awhile now with directx and can't figure out how to rotate something without rotating it all the way around (0,0,0). The farther I get away from the center of my world the bigger circles in makes during its rotation.

Was it helpful?

Solution

Don't forget the matrix transformations apply to the coordinate system. Let's say you want to move your object upwards on an xy plane by 20 units, and rotate it by 90 degrees. If you rotate by 90 degrees first, you'll be rotating the entire plane by 90 degrees. This means 90 degrees is the new "upwards" when you translate up the y axis.

So, we translate first, so that our object's center is 0,0. Now when we rotate, we should be rotating around the center of the object. Of course, don't forgot to translate back, or clear the matrix somehow.

The order does matter when doing matrix transformations, as I'm sure you know. Usually, you should translate, scale, then rotate.

OTHER TIPS

If you need a rotation α, around a point p located at (x₀,y₀,z₀), you create the matrix :

T(-x₀,-y₀,-z₀) * R(α) * T(x₀,y₀,z₀)

T means Translation and R means rotation. Also, depending on your convention such as row or column matrix, you may have to revert the order of operation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top