在WPF应用程序中的HelixViewport3D中旋转对象 [英] Rotate an object in HelixViewport3D in a WPF app
本文介绍了在WPF应用程序中的HelixViewport3D中旋转对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用helixtoolkit在WPF应用程序中显示3d对象,并根据x,y,z轴上的3个变量(用户输入)旋转它.但是我在helix工具包中找不到旋转3d对象的功能.
I'm trying to show a 3d object in a WPF app using helixtoolkit and rotate it according to 3 variables (user inputs) along x,y,z axes. But i coudn't find a function in helix toolkit to to rotate the 3d object.
C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using HelixToolkit.Wpf;
namespace HelixTrial
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ModelImporter importer = new ModelImporter();
Model3D model = importer.Load("D:\\Crate1.obj");
Models.Content = model;
// need to apply rotation to the model using three x,y,z variables
}
}
}
XAML代码
<Window x:Class="HelixTrial.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
Title="MainWindow" Height="500" Width="500">
<Grid Width="400" Height="400">
<HelixToolkit:HelixViewport3D x:Name="Viewport" ZoomExtentsWhenLoaded="True">
<HelixToolkit:SunLight/>
<ModelVisual3D x:Name="Models"/>
</HelixToolkit:HelixViewport3D>
</Grid>
</Window>
推荐答案
You couldn't find it in the toolkit, because it's a standard WPF function. So in your example it would look somewhat like this:
<ModelVisual3D x:Name="Models">
<ModelVisual3D.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="{Binding varX}"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,1,0" Angle="{Binding varY}"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,0,1" Angle="{Binding varZ}"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</ModelVisual3D.Transform>
</ModelVisual3D>
这篇关于在WPF应用程序中的HelixViewport3D中旋转对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文