Skip to content

Commit 79b32bd

Browse files
authored
Merge pull request #2 from simulation-tree/dev/clean-up
Clean up
2 parents ec3d4ed + 724a255 commit 79b32bd

14 files changed

Lines changed: 534 additions & 435 deletions

README.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,57 @@
11
# Transforms
2-
Calculates 3D transformations for objects within a hierarchy.
32

4-
### Dependencies
5-
* [Simulation](https://github.com/simulation-tree/simulation)
3+
For representing a hierarchy of objects in 3D space.
64

75
### Behaviour
8-
Entities with an `IsTransform` component will have a `LocalToWorld` component built
9-
using data from these components (relative to the parent entity), whenever the `TransformUpdate` event
10-
is polled:
6+
7+
Entities with the `IsTransform` tag will have a `LocalToWorld` component calculated
8+
using data from these components, relative to the parent:
119
* `Position`
1210
* `Rotation`
1311
* `Scale`
12+
* `Anchor`
13+
* `Pivot`
14+
15+
### Axis convention
16+
17+
This is only relevant for rotations when working with them manually:
18+
* X axis is right (pitch)
19+
* Y axis is up (yaw)
20+
* Z axis is forward (roll)
1421

15-
### Example
22+
### Anchoring to corners
23+
24+
The `Anchor` component is able to describe both relative and absolute values. The example
25+
below makes the child transform have a 10 pixel border inside the parent:
1626
```cs
17-
eint parentObj = world.CreateEntity();
18-
world.AddComponent(parentObj, new IsTransform());
19-
world.AddComponent(parentObj, new Scale(2, 2, 2));
27+
Transform parent = new(world);
28+
parent.LocalScale = new(100, 100, 0);
29+
parent.LocalPosition = new(50, 50, 0);
2030

21-
eint obj = world.CreateEntity(parentObj);
22-
world.AddComponent(obj, new IsTransform());
23-
world.AddComponent(obj, new Position(0, 5, 0));
31+
Transform child = new(world);
32+
child.Anchor = new(10, 10, 0, 10, 10, 0, Anchor.Relativeness.X | Anchor.Relativeness.Y);
2433

25-
world.Submit(new TransformUpdate());
26-
world.Poll();
34+
//after simulating, child will be at position (60, 60) with size (80, 80)
35+
```
2736

28-
LocalToWorld ltw = world.GetComponent<LocalToWorld>(obj));
29-
Vector3 worldPosition = ltw.Position;
30-
Matrix4x4 matrix = ltw.value;
37+
### Reading world state
38+
39+
Accessing world position, rotation or scale is can be done through properties of a transform
40+
entity:
41+
```cs
42+
Transform a = ...
43+
Vector3 position = a.WorldPosition;
44+
Quaternion rotation = a.WorldRotation;
45+
Vector3 scale = a.WorldScale;
3146
```
47+
48+
And optionally, can be accessed directly through components. However, accessing
49+
the world rotation is not possible through the `LocalToWorld` component and must
50+
be done through `WorldRotation`:
51+
```cs
52+
uint a = ...
53+
LocalToWorld ltw = world.GetComponent<LocalToWorld>(a);
54+
Vector3 position = ltw.Position;
55+
Vector3 scale = ltw.Scale;
56+
Quaternion rotation = world.GetComponent<WorldRotation>(a).value;
57+
```

0 commit comments

Comments
 (0)