BBC BASIC for Windows
Programming >> Graphics and Games >> simple method for rotating graphics
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1381791925

simple method for rotating graphics
Post by gaui65 on Oct 14th, 2013, 9:58pm

Lets say i drew a triangle and wanted to rotate it. It would be great if i could group all the lines forming the triangle and then use a ROTATE(group,x,y,step) where the x and y is the rotation point. This would be a great tool.
Re: simple method for rotating graphics
Post by admin on Oct 14th, 2013, 11:05pm

on Oct 14th, 2013, 9:58pm, gaui65 wrote:
Lets say i drew a triangle and wanted to rotate it. It would be great if i could group all the lines forming the triangle and then use a ROTATE(group,x,y,step) where the x and y is the rotation point. This would be a great tool.

It would be easy enough to do that in the specific case of a triangle. Just write a procedure which receives the X,Y coordinates of the three vertices, the X,Y coordinates of the axis of rotation, plus an angle. The procedure would then plot the triangle rotated about the specified point by the specified angle. It's just simple trigonometry.

You could extend that technique to a larger number of lines, e.g. a rectangle, by passing (for example) arrays containing pairs of X and Y coordinates defining the end-points of the lines.

Another approach might be to use the SetWorldTransform API to get Windows to do the rotation for you. It's rather tricky to use but with a bit of care could perhaps be made to do what you want.

Where it starts to get more difficult is when the rotated 'object' is made up of some filled (solid) areas as well as lines. At that point you may want to use a method which will rotate an arbitrary image; one such would be the Windows API function PlgBlt. Although it's not documented as being specifically suitable for performing rotations, in fact it does so reasonably well.

The program rotateimage.bbc, which you can find in the Graphics folder on the old Yahoo group, uses that technique and could perhaps be adapted.

I should also mention those GFXLIB modules which support rotation, such as plotrotatescalebilinear, which were used to good effect in the BOX2D demonstrations such as the falling crates demo.

Richard.