|
@ -12,9 +12,28 @@ struct Transform2D { |
|
|
sealed class Transform2DComponent : Component { |
|
|
sealed class Transform2DComponent : Component { |
|
|
public Transform2D transform; |
|
|
public Transform2D transform; |
|
|
|
|
|
|
|
|
public Transform2DComponent() { |
|
|
|
|
|
|
|
|
public Transform2DComponent() |
|
|
|
|
|
: this(0,0,0,0,0,1,1) |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
public Transform2DComponent(float x, float y) |
|
|
|
|
|
: this(x,y,0,0,0,1,1) |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
public Transform2DComponent(float x, float y, float angle) |
|
|
|
|
|
: this(x,y,angle,0,0,1,1) |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
public Transform2DComponent(float x, float y, float angle, float center_x, float center_y) |
|
|
|
|
|
: this(x,y,angle,center_x,center_y,1,1) |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
public Transform2DComponent(float x, float y, float angle, float center_x, float center_y, float scale_x, float scale_y) { |
|
|
transform = new Transform2D(); |
|
|
transform = new Transform2D(); |
|
|
transform.scale = Complex.ImaginaryOne + 1; |
|
|
|
|
|
|
|
|
transform.position = y*Complex.ImaginaryOne + x; |
|
|
|
|
|
transform.angle = angle; |
|
|
|
|
|
transform.anchor = center_y*Complex.ImaginaryOne + center_x; |
|
|
|
|
|
transform.scale = scale_y*Complex.ImaginaryOne + scale_x; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Transform2D AbsoluteTransform() { |
|
|
public Transform2D AbsoluteTransform() { |
|
@ -25,17 +44,12 @@ sealed class Transform2DComponent : Component { |
|
|
var component = up.GetComponent<Transform2DComponent>(); |
|
|
var component = up.GetComponent<Transform2DComponent>(); |
|
|
if(component != null) { |
|
|
if(component != null) { |
|
|
Transform2D combined = component.AbsoluteTransform(); |
|
|
Transform2D combined = component.AbsoluteTransform(); |
|
|
var unscaled_pos = |
|
|
|
|
|
(combined.position + transform.position - combined.anchor) |
|
|
|
|
|
/(Complex.Exp(Complex.ImaginaryOne * combined.angle) - combined.anchor); |
|
|
|
|
|
var normalized_pos = unscaled_pos/unscaled_pos.Magnitude; |
|
|
|
|
|
combined.position = unscaled_pos.Magnitude*(transform.scale.Real*normalized_pos.Real + transform.scale.Imaginary*normalized_pos.Imaginary*Complex.ImaginaryOne); |
|
|
|
|
|
var unscaled_anchor = |
|
|
|
|
|
(combined.position + transform.anchor - combined.anchor) |
|
|
|
|
|
/(Complex.Exp(Complex.ImaginaryOne * combined.angle) - combined.anchor); |
|
|
|
|
|
var normalized_anchor = unscaled_anchor/unscaled_anchor.Magnitude; |
|
|
|
|
|
combined.anchor = unscaled_anchor.Magnitude*(transform.scale.Real*normalized_anchor.Real + transform.scale.Imaginary*normalized_anchor.Imaginary*Complex.ImaginaryOne); |
|
|
|
|
|
combined.scale *= transform.scale; |
|
|
|
|
|
|
|
|
var unscaled_pos = (transform.position - transform.anchor)*Complex.Exp(Complex.ImaginaryOne * combined.angle) + transform.anchor; |
|
|
|
|
|
combined.position = combined.scale.Real*unscaled_pos.Real + combined.scale.Imaginary*unscaled_pos.Imaginary*Complex.ImaginaryOne |
|
|
|
|
|
+ combined.position + combined.anchor; |
|
|
|
|
|
var unscaled_anchor = (transform.anchor - transform.position)*Complex.Exp(Complex.ImaginaryOne * combined.angle) + transform.position; |
|
|
|
|
|
combined.anchor = transform.scale.Real*unscaled_anchor.Real + transform.scale.Imaginary*unscaled_anchor.Imaginary*Complex.ImaginaryOne; |
|
|
|
|
|
combined.scale = transform.scale.Imaginary*combined.scale.Imaginary*Complex.ImaginaryOne + transform.scale.Real * combined.scale.Real; |
|
|
combined.angle += transform.angle; |
|
|
combined.angle += transform.angle; |
|
|
return combined; |
|
|
return combined; |
|
|
} |
|
|
} |
|
|