如何在HelixToolkit中旋转文本

huangapple go评论102阅读模式
英文:

How to rotate a Text In HelixToolkit

问题

I understand your request. Here's the translated code portion:

我正在尝试插入一个带有旋转对齐的TextVisual3D如果原点是零没有问题但当原点位于其他位置时变换会移动两倍的距离
我已经尝试了许多方法但没有成功
我正在使用"Up"视图UpDirection使用矢量(0, 1, 0)来放置文本

var text = new TextVisual3D();
text.Foreground = Brushes.Cyan;

text.FontSize = size / 4;
text.Height = size * 2;
text.Text = value;
text.UpDirection = new Vector3D(0, 1, 0);
text.HorizontalAlignment = horizontal;
text.VerticalAlignment = vertical;
text.Position = origin.GetPoint3D();

if (Rotation != 0)
{
    var angle = Rotation.Round(0);
    if (angle.Abs() != 360)
    {
        var axis = new Vector3D(0, 0, 1);
        var matrix = text.Transform.Value;
        matrix.Rotate(new Quaternion(axis, angle));
        text.Transform = new MatrixTransform3D(matrix);
    }
}

return text;

Please let me know if you need any further assistance.

英文:

I'm trying to insert a TextVisual3D with rotated alignment. If the origin point is zero, no problem, but when the origin is in other location, the transform moves 2 times the distance.
I've tried many ways, with no success.
I'm using the "Up" view, the UpDirection is using the Vector (0, 1, 0), to plain the text.

        var text = new TextVisual3D();
        text.Foreground = Brushes.Cyan;

        text.FontSize = size / 4;
        text.Height = size * 2;
        text.Text = value;
        text.UpDirection = new Vector3D(0, 1, 0);
        text.HorizontalAlignment = horizontal;
        text.VerticalAlignment = vertical;
        text.Position = origin.GetPoint3D();


        if (Rotation!=0)
        {
            var angle = Rotation.Round(0);
            if(angle.Abs()!=360)
            {
                var axis = new Vector3D(0,0,1);
                var matrix = text.Transform.Value;
                matrix.Rotate(new Quaternion(axis, angle));
                text.Transform = new MatrixTransform3D(matrix);
            }
        }

        return text;

The Result:

如何在HelixToolkit中旋转文本

Expected:

如何在HelixToolkit中旋转文本

答案1

得分: 0

以下是您要翻译的部分:

"After so many attempts, I've discovered the solution.

var text = new TextVisual3D();
text.Foreground = Brushes.Cyan;
text.FontSize = size / 4;
text.Height = size * 2;
text.Text = value;
text.UpDirection = new Vector3D(0, 1, 0);
text.HorizontalAlignment = horizontal;
text.VerticalAlignment = vertical;
text.Position = origin.GetPoint3D();

if (Rotation != 0)
{
var angle = Rotation.Round(0);
if (angle.Abs() != 360)
{
var axis = new Vector3D(0, 0, 1);
var matrix = text.Transform.Value;

    var rotate = new RotateTransform3D();
    var angle_axis = new AxisAngleRotation3D();
    angle_axis.Angle = angle;
    angle_axis.Axis = axis;
    rotate.Rotation = angle_axis;
    rotate.CenterX = origin.X;
    rotate.CenterY = origin.Y;
    text.Transform = rotate;
}

}

return text;"

结果:

如何在HelixToolkit中旋转文本

参考链接:
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/3-d-transformations-overview?view=netframeworkdesktop-4.8

英文:

After so many attempts, I've discovered the solution.

        var text = new TextVisual3D();
        text.Foreground = Brushes.Cyan;
        text.FontSize = size / 4;
        text.Height = size * 2;
        text.Text = value;
        text.UpDirection = new Vector3D(0, 1, 0);
        text.HorizontalAlignment = horizontal;
        text.VerticalAlignment = vertical;
        text.Position = origin.GetPoint3D();


        if (Rotation != 0)
        {
            var angle = Rotation.Round(0);
            if (angle.Abs() != 360)
            {
                var axis = new Vector3D(0, 0, 1);
                var matrix = text.Transform.Value;


                var rotate = new RotateTransform3D();
                var angle_axis = new AxisAngleRotation3D();
                angle_axis.Angle = angle;
                angle_axis.Axis = axis;
                rotate.Rotation = angle_axis;
                rotate.CenterX = origin.X;
                rotate.CenterY = origin.Y;
                text.Transform = rotate;
            }
        }

        return text;

Result:

如何在HelixToolkit中旋转文本

Reference:
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/3-d-transformations-overview?view=netframeworkdesktop-4.8

huangapple
  • 本文由 发表于 2023年5月18日 04:21:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76275932.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定