Author |
Topic: simple method for rotating graphics (Read 773 times) |
|
gaui65
New Member
member is offline


Posts: 0
|
 |
simple method for rotating graphics
« Thread started 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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: simple method for rotating graphics
« Reply #1 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.
|
« Last Edit: Oct 15th, 2013, 03:09am by admin » |
Logged
|
|
|
|
|