Rotating a scene to simulate turning wheel

I have a picture of a wheel. I used a paint program to rotate it by % and then save it as a sprite screen to use it in a playanimation sequence (12 images).
But it is not rotating equal because there is a little shift in the wheels position. (looks rather funny).
So I thought it would be better if the scene consists of just this picture and then rotate the scene to simulate rotation of the wheel. Is this possible?
(I guess the axe should be perfectly in the middle of the scene to prevent it from shifting position while rotating).
Thanks!

Yes, that’s exactly the way to go. Just make sure center of the wheel is perfectly at the center of the image.

Use Castle Game Engine: CastleTransform: Class TCastleTransform the example at that page rotates the scene exactly around the Z-axis (that is in your 2D case - as you would expect, along the player’s line of sight / depth of the view unless you are applying additional transformations in parent).

Great!
Got it working.
Now I was about to ask how to change rotation direction and speed but already figured it out by changing the pi value.

Location.Props[2].Image.Rotation := Location.Props[2].Image.Rotation + Vector4(0, 0, 0, Pi / -50);
Negative value rotates the image clockwise and decreasing or increasing the value affects speed.
:slight_smile:

1 Like

Note that if you update the rotation every frame, it’s a good idea to also use SecondsPassed * RotationSpeed where RotationSpeed is in radians. Here, just as you do for movement. Pi / -50 actually stands for this rotation per frame but it doesn’t consider SecondsPassed and may result in something unexpected.

1 Like

Consider this shorthand, when you have established rotation axis and do not want to be changing it but only the angle.

or as a patch - Wish, tutorials, 2D - more and earlier about coordinates transformations. · Issue #370 · castle-engine/castle-engine · GitHub - the patch is a bit obsolete though, as the record member var names were changed later, but the fix is trivial.

Personally i believe it would make your programs safer by clearly documenting developer’s intention and reducing boilerplate.

with Location.Props[2].Image do RotationAngle := RotationAngle + Pi/-50;

Michalis is absolutely against this approach, though.
Yet the good thing about opensource - you can easily have your own branch with any tweaks of your own choice :slight_smile:

Such RotationAngle is a shortcut, and it’s a shortcut with non-obvious meaning to the reader (does it set rotation axis to something hardcoded or leaves it unmodified?).

To be clear, I am not “absolutely against this”. I actually added myself in the past to the engine things that are similar (TCastleTransform.TranslationXY being the close analogy). I just don’t see it as justified enough, for now. I may change my mind in the future, depending on the usage of CGE I’ll observe.

…that is exactly why i called it rotationANGLE to stress that it does NOT change the axis - and it actually looks similar to your exampl with translationXY stressing the only coordinates affected :slight_smile:

Granted, it would make yet more syntax sugar to have it as an advancd record with AngleIncrease or RotateCCW methods - but this way we rush into “record copy modification” trap :slight_smile: