Browse Source

Refactor names.

pull/7402/head
Jan-Peter Zurek 5 years ago
parent
commit
0a831b9784
  1. 7
      samples/RenderDemo/Pages/Transform3DPage.axaml
  2. 8
      samples/RenderDemo/ViewModels/Transform3DPageViewModel.cs
  3. 135
      src/Avalonia.Visuals/Media/Transform3D.cs

7
samples/RenderDemo/Pages/Transform3DPage.axaml

@ -54,12 +54,11 @@
<Border Classes="Test" Background="DarkRed"> <Border Classes="Test" Background="DarkRed">
<Border.RenderTransform> <Border.RenderTransform>
<Transform3D RotationY="{Binding RotationY}" <Transform3D RotationY="{Binding RotationY}"
Depth="{Binding Depth}"
RotationX="{Binding RotationX}" RotationX="{Binding RotationX}"
RotationZ="{Binding RotationZ}" RotationZ="{Binding RotationZ}"
X="{Binding X}" CenterX="{Binding X}"
Y="{Binding Y}" CenterY="{Binding Y}"
Z="{Binding Z}" /> CenterZ="{Binding Z}" />
</Border.RenderTransform> </Border.RenderTransform>
</Border> </Border>
<TextBlock>X-Rotation:</TextBlock> <TextBlock>X-Rotation:</TextBlock>

8
samples/RenderDemo/ViewModels/Transform3DPageViewModel.cs

@ -6,7 +6,7 @@ namespace RenderDemo.ViewModels
{ {
public class Transform3DPageViewModel : ViewModelBase public class Transform3DPageViewModel : ViewModelBase
{ {
private double _roationX = 0; private double _rotationX = 0;
private double _rotationY = 0; private double _rotationY = 0;
private double _rotationZ = 0; private double _rotationZ = 0;
@ -16,10 +16,10 @@ namespace RenderDemo.ViewModels
private double _depth = 200; private double _depth = 200;
public double RoationX public double RotationX
{ {
get => _roationX; get => _rotationX;
set => RaiseAndSetIfChanged(ref _roationX, value); set => RaiseAndSetIfChanged(ref _rotationX, value);
} }
public double RotationY public double RotationY

135
src/Avalonia.Visuals/Media/Transform3D.cs

@ -8,58 +8,41 @@ public class Transform3D : Transform
/// <summary> /// <summary>
/// Defines the <see cref="RotationX"/> property. /// Defines the <see cref="RotationX"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<double> s_rotationXProperty = public static readonly StyledProperty<double> RotationXProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(RotationX)); AvaloniaProperty.Register<Transform3D, double>(nameof(RotationX));
/// <summary> /// <summary>
/// Defines the <see cref="RotationY"/> property. /// Defines the <see cref="RotationY"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<double> s_rotationYProperty = public static readonly StyledProperty<double> RotationYProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(RotationY)); AvaloniaProperty.Register<Transform3D, double>(nameof(RotationY));
/// <summary> /// <summary>
/// Defines the <see cref="RotationZ"/> property. /// Defines the <see cref="RotationZ"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<double> s_rotationZProperty = public static readonly StyledProperty<double> RotationZProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(RotationZ)); AvaloniaProperty.Register<Transform3D, double>(nameof(RotationZ));
/// <summary>
/// Defines the <see cref="Depth"/> property.
/// </summary>
public static readonly StyledProperty<double> s_depthProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(Depth));
/// <summary> /// <summary>
/// Defines the <see cref="CenterX"/> property. /// Defines the <see cref="CenterX"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<double> s_centerXProperty = public static readonly StyledProperty<double> CenterXProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(CenterX)); AvaloniaProperty.Register<Transform3D, double>(nameof(CenterX));
/// <summary>
/// Defines the <see cref="CenterY"/> property.
/// </summary>
public static readonly StyledProperty<double> s_centerYProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(CenterY));
/// <summary>
/// Defines the <see cref="CenterY"/> property.
/// </summary>
public static readonly StyledProperty<double> s_xProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(X));
/// <summary> /// <summary>
/// Defines the <see cref="CenterY"/> property. /// Defines the <see cref="CenterY"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<double> s_yProperty = public static readonly StyledProperty<double> CenterYProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(Y)); AvaloniaProperty.Register<Transform3D, double>(nameof(CenterY));
/// <summary> /// <summary>
/// Defines the <see cref="CenterY"/> property. /// Defines the <see cref="CenterZ"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<double> s_zProperty = public static readonly StyledProperty<double> CenterZProperty =
AvaloniaProperty.Register<Transform3D, double>(nameof(Z)); AvaloniaProperty.Register<Transform3D, double>(nameof(CenterZ));
/// <summary> /// <summary>
@ -67,97 +50,93 @@ public class Transform3D : Transform
/// </summary> /// </summary>
public Transform3D() public Transform3D()
{ {
this.GetObservable(s_rotationXProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(RotationXProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_rotationYProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(RotationYProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_rotationZProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(RotationZProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_depthProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(CenterXProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_centerXProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(CenterYProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_centerYProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(CenterXProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_xProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(CenterYProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_yProperty).Subscribe(_ => RaiseChanged()); this.GetObservable(CenterZProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(s_zProperty).Subscribe(_ => RaiseChanged());
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Transform3D"/> class. /// Initializes a new instance of the <see cref="Transform3D"/> class.
/// </summary> /// </summary>
/// <param name="rotationX">The skew angle of X-axis, in degrees.</param> /// <param name="rotationX">The rotation around the X-Axis</param>
/// <param name="rotationY">The skew angle of Y-axis, in degrees.</param> /// <param name="rotationY">The rotation around the Y-Axis</param>
/// <param name="rotationZ"></param> /// <param name="rotationZ">The rotation around the Z-Axis</param>
/// <param name="originCenterX">The origin of the X-Axis</param>
/// <param name="originCenterY">The origin of the Y-Axis</param>
/// <param name="originCenterZ">The origin of the Z-Axis</param>
public Transform3D( public Transform3D(
double rotationX, double rotationX,
double rotationY, double rotationY,
double rotationZ, double rotationZ,
double depth, double originCenterX,
double centerX, double originCenterY,
double centerY) : this() double originCenterZ) : this()
{ {
RotationX = rotationX; RotationX = rotationX;
RotationY = rotationY; RotationY = rotationY;
RotationZ = rotationZ; RotationZ = rotationZ;
Depth = depth; CenterX = originCenterX;
CenterX = centerX; CenterY = originCenterY;
CenterY = centerY; CenterZ = originCenterZ;
} }
/// <summary> /// <summary>
/// Gets or sets the X property. /// Sets the rotation around the X-Axis
/// </summary> /// </summary>
public double RotationX public double RotationX
{ {
get => GetValue(s_rotationXProperty); get => GetValue(RotationXProperty);
set => SetValue(s_rotationXProperty, value); set => SetValue(RotationXProperty, value);
} }
/// <summary> /// <summary>
/// Gets or sets the Y property. /// Sets the rotation around the Y-Axis
/// </summary> /// </summary>
public double RotationY public double RotationY
{ {
get => GetValue(s_rotationYProperty); get => GetValue(RotationYProperty);
set => SetValue(s_rotationYProperty, value); set => SetValue(RotationYProperty, value);
} }
/// <summary>
/// Sets the rotation around the Z-Axis
/// </summary>
public double RotationZ public double RotationZ
{ {
get => GetValue(s_rotationZProperty); get => GetValue(RotationZProperty);
set => SetValue(s_rotationZProperty, value); set => SetValue(RotationZProperty, value);
}
public double Depth
{
get => GetValue(s_depthProperty);
set => SetValue(s_depthProperty, value);
} }
/// <summary>
/// Moves the origin of the X-Axis
/// </summary>
public double CenterX public double CenterX
{ {
get => GetValue(s_centerXProperty); get => GetValue(CenterXProperty);
set => SetValue(s_centerXProperty, value); set => SetValue(CenterXProperty, value);
} }
/// <summary>
/// Moves the origin of the Y-Axis
/// </summary>
public double CenterY public double CenterY
{ {
get => GetValue(s_centerYProperty); get => GetValue(CenterYProperty);
set => SetValue(s_centerYProperty, value); set => SetValue(CenterYProperty, value);
} }
public double X /// <summary>
{ /// Moves the origin of the Z-Axis
get => GetValue(s_xProperty); /// </summary>
set => SetValue(s_xProperty, value); public double CenterZ
}
public double Y
{
get => GetValue(s_yProperty);
set => SetValue(s_yProperty, value);
}
public double Z
{ {
get => GetValue(s_zProperty); get => GetValue(CenterZProperty);
set => SetValue(s_zProperty, value); set => SetValue(CenterZProperty, value);
} }
/// <summary> /// <summary>
@ -169,7 +148,7 @@ public class Transform3D : Transform
{ {
var matrix44 = Matrix4x4.Identity; var matrix44 = Matrix4x4.Identity;
matrix44 *= Matrix4x4.CreateTranslation((float)X, (float)Y, (float)Z); matrix44 *= Matrix4x4.CreateTranslation(-(float)CenterX, -(float)CenterY, -(float)CenterZ);
matrix44 *= Matrix4x4.CreateRotationX((float)Matrix.ToRadians(RotationX)); matrix44 *= Matrix4x4.CreateRotationX((float)Matrix.ToRadians(RotationX));
matrix44 *= Matrix4x4.CreateRotationY((float)Matrix.ToRadians(RotationY)); matrix44 *= Matrix4x4.CreateRotationY((float)Matrix.ToRadians(RotationY));

Loading…
Cancel
Save