I am familiar with the basic concept between transformation matrices, but need some assistance with a specific application. I have objects loaded into a scene graph, and I have enabled translation and rotation with mouse key presses by applying a transformation matrix to the coordinates of the objects’ vertices. Right now, I can rotate and translate my objects to virtually any position.
I have drawn a grid and want my objects to appear to “snap” to grid squares. In order to do this, I need to limit the movement so the rotation is only done in 90 degrees increments (90, 180, or 270 degrees of rotation), and translation is only done in grid-square size increments.
How can I go about this? I am not sure how I can make sure the transformation matrix is such that the object only translates or rotates in grid square units.
I think all you need to do is “snap” x,y and z passed to glRotate to the nearest whole multiple of your grip step. You simply need to do some rounding, e.g. like this: