C# 如何依次沿x、y和z轴旋转ModelVisual3D对象的中心

C# 如何依次沿x、y和z轴旋转ModelVisual3D对象的中心,c#,wpf,xaml,3d,C#,Wpf,Xaml,3d,我有200张图片,我想用200张图片一张一张地构建一个立方体。现在我已经构建了立方体,我想完成的功能是立方体的中心依次沿x y z轴旋转,现在我已经构建了立方体,并设置了视口3D.Camera。我只想旋转立方体,并将立方体保持在摄影机的视野中,使用C#中的代码来完成该函数。 现在我将复制xaml和C中的代码,以帮助您理解我的代码 我在xaml中的代码: Window x:Class="ThreeDemensionsCube.MainWindow" xmlns="http://schema

我有200张图片,我想用200张图片一张一张地构建一个立方体。现在我已经构建了立方体,我想完成的功能是立方体的中心依次沿x y z轴旋转,现在我已经构建了立方体,并设置了
视口3D.Camera
。我只想旋转立方体,并将立方体保持在摄影机的视野中,使用C#中的代码来完成该函数。 现在我将复制xaml和C中的代码,以帮助您理解我的代码

我在xaml中的代码:

Window x:Class="ThreeDemensionsCube.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid Background="Black" >


    <Viewport3D x:Name="viewport" Margin="0"  Height="319" VerticalAlignment="Top" >
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <Model3DGroup x:Name="group">
                    <!--Ligthts-->
                    <AmbientLight Color="Gray" />
                    <DirectionalLight Color="gray" Direction="1,-1,-1" />
                    <DirectionalLight Color="Gray" Direction="-1,1,1" />
                </Model3DGroup>

            </ModelVisual3D.Content>
        </ModelVisual3D>

        <Viewport3D.Camera>

            <PerspectiveCamera x:Name="camera"
                      Position = "30, 30, 90"
                      LookDirection = "-30, -30, -90"
                      UpDirection = "0, 1, 0"
                      FieldOfView = "60">


                <PerspectiveCamera.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D
                                          Axis="0 1 0" 
                                          Angle="{Binding ElementName=hscroll, Path=Value}" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D
                                          Axis="0 0 1" 
                                          Angle="{Binding ElementName=vscroll, Path=Value}" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </Transform3DGroup>
                </PerspectiveCamera.Transform>


            </PerspectiveCamera>
        </Viewport3D.Camera>
    </Viewport3D>
    <Border VerticalAlignment="Top" HorizontalAlignment="Right"  Background="White" BorderBrush="Bisque" BorderThickness="3,5,3,5">
        <StackPanel>
             <Button Content="processImage" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="75"  Margin="5" Click="processImage"/>
             <Button Content="loadImage" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="75" Margin="5" Click="loadProcessedImage"/>

        </StackPanel>


    </Border>
     <DockPanel>
        <ProgressBar x:Name="pBar" DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Height="9"></ProgressBar>

    </DockPanel>

</Grid>
窗口x:Class=“ThreeDimensionsCube.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml" Title=“MainWindow”Height=“350”Width=“525”>

我的C#代码:

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用System.IO;
使用System.Runtime.InteropServices;
使用Emgu.CV;
使用Emgu.CV.Structure;
使用System.Windows.Media.Media3D;
命名空间三维
{
/// 
///MainWindow.xaml交互逻辑
/// 
公共部分类主窗口:窗口
{
字符串appPath=System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase+“图像”;
字符串newAppPath=System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase+“ProcesseImage”;
双a=0;
公共主窗口()
{
初始化组件();
}
私有void imageProc()
{
//定义DirectoryInfo对象
DirectoryInfo dir=新的DirectoryInfo(appPath);
DirectoryInfo[]listDir=dir.GetDirectories();
FileInfo[]listFile=dir.GetFiles(“*.jpg”);
int picNum=listFile.Length;
如果(picNum>0)
{
//创建新文件
字符串newFileName=appPath.Replace(“图像”、“处理图像”);
DirectoryInfo newDir=新的DirectoryInfo(newFileName);
newDir.Create();
对于(int i=0;i0)
{

对于(inti=0;i现在,我将发布我的代码,代码的目的是旋转一个三维立方体对象

xaml中的代码:

 <PerspectiveCamera.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D x:Name="rotate3D" 
                                Axis="1,0,0" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>

                    </Transform3DGroup>
                </PerspectiveCamera.Transform>
xaml中的代码用于创建透视照相机。转换并配置它。 c#中的代码是创建一个双重动画来控制相机

以上内容仅为个人意见,如有疑问请指正。 现在我将展示我的结果和一些问题。

从结果我们可以知道有一些问题,有阴影的一面在坏结果图片,我如何才能消除阴影

 <PerspectiveCamera.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D x:Name="rotate3D" 
                                Axis="1,0,0" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>

                    </Transform3DGroup>
                </PerspectiveCamera.Transform>
DoubleAnimation rotate = new DoubleAnimation();
        rotate.From = 0;
        rotate.To = 360;
        rotate.Duration = TimeSpan.FromSeconds(6);
       // rotate.RepeatBehavior=new RepeatBehavior(2.5);
        rotate.RepeatBehavior = RepeatBehavior.Forever;
        rotate3D.Axis = new Vector3D(0,1,1);
        rotate3D.Angle = 60;
        rotate3D.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotate);