The Transform components are used to store the Entity position, rotation and scale. In a 2D environment, Transform2D has more properties, such as Opacity, Rectangle, etc…
In WaveEngine 1.4 we have introduced a new Transform2D and Transform3D implementation, with great advantages:
- Real Parent/Child transform hierarchy.
- Local / Global position, rotation and scale properties.
- Apply 3D transforms to 2D entities.
Parent / Child hierarchy
This is one of the most important concepts to understand in the new Transform implementation.
Now, when an Entity is a Parent of another Entity, the Child Entity will move, rotate and scale in the same way as its Parent does. You can think of parent / child hierarchy as being like the relationship between your arms and your body; whenever your body moves, your arms also move along with it. Child objects can also have children. Your hands can be considered as children of your arms, and your fingers are hands children.
The leak of real hierarchy was a weakness in earlier Wave Engine versions, and a requested feature by our users.
Local vs World space
3D and 2D position and transformations exist within a coordinate systems called spaces:
- World Space is the coordinate system for the entire scene. Its origin is at the center of the scene: Position [0, 0, 0], Scale [1, 1, 1] and Rotate [0, 0, 0]. In an entity hierarchy this space is used to get the global position of your body hand (following the example explained above).
- Local Space is the coordinate system where position, rotate and scale is used taking the entity parent as reference.
So, to deal with Local and World spaces, Transform components has new properties:
- LocalPosition, LocalRotation, LocalScale properties are used to set the entity position, rotation and scale in Local Space.
- Position, Rotation, Scale properties are now used to set the entity position, rotation and scale in World Space.
- In Transform2D component, you also have LocalX, LocalY, LocalDrawOrder, LocalXScale, LocalYScale and X, Y, DrawOrder, XScale, YScaleproperties to specify individual values.
When you set a local property, the equivalent world property is set automatically, and vice versa. So, you can place a child object in a global position, and Transform component translate it to local space.
Transform2D component has been suffered several changes:
- DrawOrder property has been suffered a light modification: Traditionally, DrawOrder property had values in [0, 1] range, with a default value of 0.5. In WaveEngine 1.4, default DrawOrder value has been changed to 0. Can have positive and negative values, and the [0, 1] range restriction has been removed. So you can interpret DrawOrder property as the Z coordinate in a 3D space, where the Z = 0 is the reference.
- Vector properties: Now you can specify the 2D position using a Vector2 through LocalPosition and Position property. In earlier versions you need to specify X and Y properties separatedly. Apply the same idea to LocalScale and Scale property to specify the entity scale.
- Transform2D inherit from Transform3D component, so it shares 100 % of its core features. But the public API of the Transform2D has been modified to hide some Transform3D properties for simplification purposes:
- Vector3 properties in Transform3D (LocalPosition, Position for instance) are translated to Vector2 in Transform2D component. Internally, the Vector3 Position is composed using the Vector2 Position + DrawOrder property.
- Vector3 LocalRotation and Rotation properties are translated to Float Local and Rotation property in Transform2D
- You can always access full 3D properties in a Transform2D component through its Transform3D property:
Vector3 position = transform2D.Transform3D.Position;