Adjust parent transform if parent is edited

This commit is contained in:
KillzXGaming 2019-10-15 20:13:17 -04:00
parent 5f7f9c3517
commit ea29db89f5

View file

@ -166,29 +166,32 @@ namespace LayoutBXLYT
public void ApplyNewParentTransform() public void ApplyNewParentTransform()
{ {
//Get the new transform and apply it //Get the new transform and apply it
var transform = GetParentTransform();
// Translate += transform; // Translate += transform;
} }
public void ResetParentTransform(BasePane newParent) public void ResetParentTransform(BasePane newParent)
{ {
//We need to get the difference in the parent transform and remove it to the current transform of this pane //We need to get the difference in the parent transform and remove it to the current transform of this pane
var transform = GetParentTransform(); var transform = GetParentTransform(Parent);
var newParentTransform = newParent.GetParentTransform(); var newParentTransform = GetParentTransform(newParent);
Translate -= transform; Translate += transform;
Translate += newParentTransform; Translate -= newParentTransform;
Console.WriteLine($"newParentTransform {newParentTransform.X} {newParentTransform.Y} {newParentTransform.Z}");
Console.WriteLine($"transform {transform.X} {transform.Y} {transform.Z}");
} }
private Vector3F GetParentTransform() { private Vector3F GetParentTransform(BasePane parent) {
return GetParentTransform(Vector3F.Zero); return GetParentTransform(parent.Translate);
} }
private Vector3F GetParentTransform(Vector3F translate) private Vector3F GetParentTransform(Vector3F translate)
{ {
if (Parent != null) if (Parent != null)
return translate += Parent.GetParentTransform(translate); translate = Parent.Translate + Parent.GetParentTransform(translate);
else
return translate; return translate;
} }
public void KeepChildrenTransform(float newTransX, float newTransY) public void KeepChildrenTransform(float newTransX, float newTransY)