Updates the control cached transformation matrix (based on bounds).
()
| 523 | /// Updates the control cached transformation matrix (based on bounds). |
| 524 | /// </summary> |
| 525 | [NoAnimate] |
| 526 | public void UpdateTransform() |
| 527 | { |
| 528 | // Actual pivot and negative pivot |
| 529 | //Float2.Multiply(ref _pivot, ref _bounds.Size, out var v1); |
| 530 | //Float2.Negate(ref v1, out var v2); |
| 531 | //Float2.Add(ref v1, ref _bounds.Location, out v1); |
| 532 | var v1 = _pivot * _bounds.Size; |
| 533 | var v2 = -v1; |
| 534 | v1 += _bounds.Location; |
| 535 | |
| 536 | // ------ Matrix3x3 based version: |
| 537 | |
| 538 | /* |
| 539 | // Negative pivot |
| 540 | Matrix3x3 m1, m2; |
| 541 | Matrix3x3.Translation2D(ref v2, out m1); |
| 542 | |
| 543 | // Scale |
| 544 | Matrix3x3.Scaling(_scale.X, _scale.Y, 1, out m2); |
| 545 | Matrix3x3.Multiply(ref m1, ref m2, out m1); |
| 546 | |
| 547 | // Shear |
| 548 | Matrix3x3.Shear(ref _shear, out m2); |
| 549 | Matrix3x3.Multiply(ref m1, ref m2, out m1); |
| 550 | |
| 551 | // Rotation |
| 552 | Matrix3x3.RotationZ(_rotation * Mathf.DegreesToRadians, out m2); |
| 553 | Matrix3x3.Multiply(ref m1, ref m2, out m1); |
| 554 | |
| 555 | // Pivot + Location |
| 556 | Matrix3x3.Translation2D(ref v1, out m2); |
| 557 | Matrix3x3.Multiply(ref m1, ref m2, out _cachedTransform); |
| 558 | */ |
| 559 | |
| 560 | // ------ Matrix2x2 based version: |
| 561 | |
| 562 | // 2D transformation |
| 563 | |
| 564 | //Matrix2x2.Scale(ref _scale, out Matrix2x2 m1); |
| 565 | //Matrix2x2.Shear(ref _shear, out Matrix2x2 m2); |
| 566 | //Matrix2x2.Multiply(ref m1, ref m2, out m1); |
| 567 | |
| 568 | // Scale and Shear |
| 569 | Matrix3x3 m1 = new Matrix3x3 |
| 570 | ( |
| 571 | _scale.X, |
| 572 | _scale.X * (_shear.Y == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(_shear.Y, -89.0f, 89.0f))))), |
| 573 | 0, |
| 574 | _scale.Y * (_shear.X == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(_shear.X, -89.0f, 89.0f))))), |
| 575 | _scale.Y, |
| 576 | 0, 0, 0, 1 |
| 577 | ); |
| 578 | |
| 579 | |
| 580 | //Matrix2x2.Rotation(Mathf.DegreesToRadians * _rotation, out m2); |
| 581 | float sin = Mathf.Sin(Mathf.DegreesToRadians * _rotation); |
| 582 | float cos = Mathf.Cos(Mathf.DegreesToRadians * _rotation); |