在C#/XAML中通过滑块旋转模型的问题



晚安,

我目前正在尝试使用缩放范围为0-360'的滑块围绕给定轴旋转"关节1"。我已经绑定了滑块来获取值,并将其放入函数"Move_Joint1"中,该函数应该根据用户输入的滑块对对象应用旋转。然而,当把函数放在我的主窗口中时,但函数似乎没有执行。我曾尝试使用console.writeline来尝试输出该值,但没有输出任何值。没有错误或警告。

如有任何帮助,我们将不胜感激。

下面是XAML和C#代码片段。

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.Media3D;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HelixToolkit.Wpf;
namespace AtlasWPF
{
public partial class MainWindow : Window
{
// Model Group - Contains all parts
Model3DGroup AtlasModel;
// 3D World
BoxVisual3D MyBox;
// Atlas Parts
Model3D Stand;
Model3D Shoulder1;
Model3D Arm1;
Model3D Arm2;
Model3D Wrist1;
Model3D Wrist2;
Model3D Wrist3;

public Model3D our_Model { get; set; }
public MainWindow()
{
InitializeComponent();
//The Importer to load .obj files
ModelImporter importer = new ModelImporter();
//The Material (Color) that is applyed to the importet objects
Material material = new DiffuseMaterial(newSolidColorBrush(Colors.Beige));
importer.DefaultMaterial = material;
//instanciate a new group of 3D Models
AtlasModel = new Model3DGroup();
//load the files
Stand = importer.Load(@"Models/stand.obj");
Shoulder1 = importer.Load(@"Models/GUI Joint Shoulder 1.obj");
Arm1 = importer.Load(@"Models/GUI Full Arm.obj");
Arm2 = importer.Load(@"Models/GUI Full Arm 2.obj");
Wrist1 = importer.Load(@"Models/GUI Joint Wrist 1.obj");
Wrist2 = importer.Load(@"Models/GUI Joint Wrist 2.obj");
Wrist3= importer.Load(@"Models/GUI Tool Tip.obj");
//add them to the group
AtlasModel.Children.Add(Stand);
AtlasModel.Children.Add(Shoulder1);
AtlasModel.Children.Add(Arm1);
AtlasModel.Children.Add(Arm2);
AtlasModel.Children.Add(Wrist1);
AtlasModel.Children.Add(Wrist2);
AtlasModel.Children.Add(Wrist3);
//AtlasModel is complete assign it to the global variable
this.our_Model = AtlasModel;
//instanciate Helper box, uncomment to use it
MyBox = new BoxVisual3D
{
Height = 15,
Width = 15,
Length = 15
};
m_helix_viewport.Children.Add(MyBox);
// Set Joints in correct locations and orientations.
//rotate whole Model to have it upright
RotateTransform3D myRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180));
myRotateTransform.CenterX = 0;
myRotateTransform.CenterY = 0;
myRotateTransform.CenterZ = 0;
AtlasModel.Transform = myRotateTransform;
// Set Shoulder Position
Vector3D axis0 = new Vector3D(0, 0, 1);
Matrix3D transformationMatrix = Shoulder1.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix.Translate(new Vector3D(0, 0, 185));
Shoulder1.Transform = new MatrixTransform3D(transformationMatrix);
// Set Arm1 Position
Vector3D axis1 = new Vector3D(0, 0, 1); //In case you want to rotate it about the x-axis
Matrix3D transformationMatrix1 = Arm1.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix1.Translate(new Vector3D (0,150,253));
Arm1.Transform = new MatrixTransform3D(transformationMatrix1);
transformationMatrix1 = Arm1.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix1.Rotate(new Quaternion(axis1, 270)); //Makes a rotation transformation over this matrix
Arm1.Transform = new MatrixTransform3D(transformationMatrix1);
//Set Arm2 Position
Vector3D axis2 = new Vector3D(0, 0, 1); //In case you want to rotate it about the x-axis
Matrix3D transformationMatrix2 = Arm2.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix2.Translate(new Vector3D(0, 0, 825));
Arm2.Transform = new MatrixTransform3D(transformationMatrix2);
transformationMatrix2 = Arm2.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix2.Rotate(new Quaternion(axis2, 0)); //Makes a rotation transformation over this matrix
Arm2.Transform = new MatrixTransform3D(transformationMatrix2);
// Set Wrist Position
Vector3D axis3 = new Vector3D(0, 1, 0); //In case you want to rotate it about the y-axis
Matrix3D transformationMatrix3 = Wrist1.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix3.Translate(new Vector3D(1280, 0, 60));
Wrist1.Transform = new MatrixTransform3D(transformationMatrix3);
transformationMatrix3 = Wrist1.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix3.Rotate(new Quaternion(axis3,270)); //Makes a rotation transformation over this matrix
Wrist1.Transform = new MatrixTransform3D(transformationMatrix3);
transformationMatrix3 = Wrist1.Transform.Value; //Gets the matrix indicating the current transformation value
axis3 = new Vector3D(0, 0, 1);// To Rotate around Z-axis
transformationMatrix3.Rotate(new Quaternion(axis3, 180)); //Makes a rotation transformation over this matrix
Wrist1.Transform = new MatrixTransform3D(transformationMatrix3); //Apply Transform
// Set Wrist Position 2
Vector3D axis4 = new Vector3D(0, 0, 1); //In case you want to rotate it about the z-axis
Matrix3D transformationMatrix4 = Wrist2.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix4.Translate(new Vector3D(0, -115, 1340));
Wrist2.Transform = new MatrixTransform3D(transformationMatrix4);
transformationMatrix4 = Wrist2.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix4.Rotate(new Quaternion(axis4, 90)); //Makes a rotation transformation over this matrix
Wrist2.Transform = new MatrixTransform3D(transformationMatrix4);
// Set Wrist Position 3 /Tool
Vector3D axis5 = new Vector3D(0, 0, 1); //In case you want to rotate it about the z-axis
Matrix3D transformationMatrix5 = Wrist3.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix5.Translate(new Vector3D(60, -115, 1395)); // Translates to apply .obj
Wrist3.Transform = new MatrixTransform3D(transformationMatrix5); // Translation applied
transformationMatrix5 = Wrist3.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix5.Rotate(new Quaternion(axis5, 90)); //Makes a rotation transformation over this matrix
Wrist3.Transform = new MatrixTransform3D(transformationMatrix5); //Applies New Matrix to previous.
Move_Joint1(slJoint1.Value);
#endregion
Console.WriteLine(slJoint1.Value);
overall_grid.DataContext = this;
}
//Moves Joint 1
public void Move_Joint1(double angle)
{
Output(slJoint1.Value);
Matrix3D transformationMatrix7 = Shoulder1.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix7.Rotate(new Quaternion(new Vector3D(0, 0, 1),angle)); ; //Makes a rotation transformation over this matrix
Shoulder1.Transform = new MatrixTransform3D(transformationMatrix7);
}
private void Output(double context) => Console.WriteLine(context);
private void TextBox_Scroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
{
}
}
}

XAML

<Window x:Class="AtlasWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AtlasWPF"
mc:Ignorable="d"
Title="MainWindow" Height="768" Width="1366" WindowState="Maximized">
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_New" />
<MenuItem Header="_Open" />
<MenuItem Header="_Save" />
<MenuItem Header="_Save_As" />
<Separator />
<MenuItem Header="_Exit" />
</MenuItem>
<MenuItem Header=" _Edit">
<MenuItem Header="_Undo"/>
<MenuItem Header="_Redo"/>
</MenuItem>
<MenuItem Header=" _View">
</MenuItem>
<MenuItem Header="Help">
<MenuItem Header="About Atlas"/>
<MenuItem Header="Documentation"/>
<MenuItem Header="Visit Atlas"/>
</MenuItem>
</Menu>
<StatusBar DockPanel.Dock="Bottom" FontSize="8" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Width="Auto" Height="Auto">
<StatusBarItem VerticalAlignment="Bottom" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
<TextBlock/>
</StatusBarItem>
</StatusBar>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<GroupBox Header="Position" Height="716">
<StackPanel Margin="3,0,-3,0" VerticalAlignment="Stretch">
<TextBlock Padding="3"> Joint 1</TextBlock>
<Slider Maximum="360" Minimum="0" x:Name="slJoint1"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="TbMin1" Padding="3" Grid.Column="0" HorizontalAlignment="Left">Min</TextBlock>
<TextBlock x:Name="TbVal1" Padding="3" Grid.Column="1" HorizontalAlignment="Center">Value</TextBlock>
<TextBlock x:Name="TbMax1" Padding="3" Grid.Column="2" HorizontalAlignment="Right">Max</TextBlock>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text ="{Binding ElementName=slJoint1, Path=Minimum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMinBox1" Padding="0" Grid.Column="0" HorizontalAlignment="Left" Width="50" MaxWidth="50"/>
<TextBox Text ="{Binding ElementName=slJoint1, Path=Value,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbValBox1" Padding="0" Grid.Column="1" HorizontalAlignment="Center" MaxWidth="50" InputScope="Number" Width="50"/>
<TextBox Text ="{Binding ElementName=slJoint1, Path=Maximum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMaxBox1" Padding="0" Grid.Column="2" HorizontalAlignment="Right" Width="50" MaxWidth="50"></TextBox>
</Grid>
<TextBlock Padding="3"> Joint 2</TextBlock>
<Slider  Maximum="360" Minimum="0" x:Name="slJoint2"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="TbMin2" Padding="3" Grid.Column="0" HorizontalAlignment="Left">Min</TextBlock>
<TextBlock x:Name="TbVal2" Padding="3" Grid.Column="1" HorizontalAlignment="Center">Value</TextBlock>
<TextBlock x:Name="TbMax2" Padding="3" Grid.Column="2" HorizontalAlignment="Right">Max</TextBlock>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text ="{Binding ElementName=slJoint2, Path=Minimum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}"  x:Name="TbMinBox2" Padding="0" Grid.Column="0" HorizontalAlignment="Left" Width="50" MaxWidth="50"/>
<TextBox Text="{Binding ElementName=slJoint2, Path=Value,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbValBox2" Padding="0" Grid.Column="1" HorizontalAlignment="Center" Width="50" MaxWidth="50"/>
<TextBox Text ="{Binding ElementName=slJoint2, Path=Maximum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMaxBox2" Padding="0" Grid.Column="2" HorizontalAlignment="Right" Width="50" MaxWidth="50"></TextBox>
</Grid>
<TextBlock Padding="3"> Joint 3</TextBlock>
<Slider Maximum="360" Minimum="0" x:Name="slJoint3"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="TbMin3" Padding="3" Grid.Column="0" HorizontalAlignment="Left">Min</TextBlock>
<TextBlock x:Name="TbVal3" Padding="3" Grid.Column="1" HorizontalAlignment="Center">Value</TextBlock>
<TextBlock x:Name="TbMax3" Padding="3" Grid.Column="2" HorizontalAlignment="Right">Max</TextBlock>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text ="{Binding ElementName=slJoint3, Path=Minimum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}"  x:Name="TbMinBox3" Padding="0" Grid.Column="0" HorizontalAlignment="Left" Width="50" MaxWidth="50"/>
<TextBox Text="{Binding ElementName=slJoint3, Path=Value,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbValBox3" Padding="0" Grid.Column="1" HorizontalAlignment="Center" Width="50" MaxWidth="50"/>
<TextBox Text ="{Binding ElementName=slJoint3, Path=Maximum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMaxBox3" Padding="0" Grid.Column="2" HorizontalAlignment="Right" Width="50" MaxWidth="50"></TextBox>
</Grid>
<TextBlock Padding="3"> Joint 4</TextBlock>
<Slider Maximum="360" Minimum="0" x:Name="slJoint4"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="TbMin4" Padding="3" Grid.Column="0" HorizontalAlignment="Left">Min</TextBlock>
<TextBlock x:Name="TbVal4" Padding="3" Grid.Column="1" HorizontalAlignment="Center">Value</TextBlock>
<TextBlock x:Name="TbMax4" Padding="3" Grid.Column="2" HorizontalAlignment="Right">Max</TextBlock>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text ="{Binding ElementName=slJoint4, Path=Minimum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}"  x:Name="TbMinBox4" Padding="0" Grid.Column="0" HorizontalAlignment="Left" Width="50" MaxWidth="50"/>
<TextBox Text="{Binding ElementName=slJoint4, Path=Value,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbValBox4" Padding="0" Grid.Column="1" HorizontalAlignment="Center" Width="50" MaxWidth="50"/>
<TextBox Text ="{Binding ElementName=slJoint4, Path=Maximum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMaxBox4" Padding="0" Grid.Column="2" HorizontalAlignment="Right" Width="50" MaxWidth="50"></TextBox>
</Grid>
<TextBlock Padding="3"> Joint 5</TextBlock>
<Slider Maximum="360" Minimum="0" x:Name="slJoint5"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="TbMin5" Padding="3" Grid.Column="0" HorizontalAlignment="Left">Min</TextBlock>
<TextBlock x:Name="TbVal5" Padding="3" Grid.Column="1" HorizontalAlignment="Center">Value</TextBlock>
<TextBlock x:Name="TbMax5" Padding="3" Grid.Column="2" HorizontalAlignment="Right">Max</TextBlock>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text ="{Binding ElementName=slJoint5, Path=Minimum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}"  x:Name="TbMinBox5" Padding="0" Grid.Column="0" HorizontalAlignment="Left" Width="50" MaxWidth="50"/>
<TextBox Text="{Binding ElementName=slJoint5, Path=Value,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbValBox5" Padding="0" Grid.Column="1" HorizontalAlignment="Stretch" Width="50" MaxWidth="50"/>
<TextBox Text ="{Binding ElementName=slJoint5, Path=Maximum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMaxBox5" Padding="0" Grid.Column="2" HorizontalAlignment="Right" Width="50" MaxWidth="50"></TextBox>
</Grid>
<TextBlock Padding="3"> Joint 6</TextBlock>
<Slider Maximum="360" Minimum="0" x:Name="slJoint6"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="TbMin6" Padding="3" Grid.Column="0" HorizontalAlignment="Left">Min</TextBlock>
<TextBlock x:Name="TbVal6" Padding="3" Grid.Column="1" HorizontalAlignment="Center">Value</TextBlock>
<TextBlock x:Name="TbMax6" Padding="3" Grid.Column="2" HorizontalAlignment="Right">Max</TextBlock>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text ="{Binding ElementName=slJoint6, Path=Minimum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}"  x:Name="TbMinBox6" Padding="0" Grid.Column="0" HorizontalAlignment="Left" Width="50" MaxWidth="50"/>
<TextBox Text="{Binding ElementName=slJoint6, Path=Value,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbValBox6" Padding="0" Grid.Column="1" HorizontalAlignment="Center" MaxWidth="50" Width="50"/>
<TextBox Text ="{Binding ElementName=slJoint6, Path=Maximum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMaxBox6" Padding="0" Grid.Column="2" HorizontalAlignment="Right" Width="50" MaxWidth="50"></TextBox>
</Grid>
<TextBlock Padding="3"> Tool Tip</TextBlock>
<Slider Maximum="360" Minimum="0" x:Name ="slToolTip"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="TbMin7" Padding="3" Grid.Column="0" HorizontalAlignment="Left">Min</TextBlock>
<TextBlock x:Name="TbVal7" Padding="3" Grid.Column="1" HorizontalAlignment="Center">Value</TextBlock>
<TextBlock x:Name="TbMax7" Padding="3" Grid.Column="2" HorizontalAlignment="Right">Max</TextBlock>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text ="{Binding ElementName=slToolTip, Path=Minimum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}"  x:Name="TbMinBox7" Padding="0" Grid.Column="0" HorizontalAlignment="Left" Width="50" MaxWidth="50"/>
<TextBox Text="{Binding ElementName=slToolTip, Path=Value,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbValBox7" Padding="0" Grid.Column="1" MaxWidth="50" Margin="82,0,87,0"/>
<TextBox Text ="{Binding ElementName=slToolTip, Path=Maximum,StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" x:Name="TbMaxBox7" Padding="0" Grid.Column="2" HorizontalAlignment="Right" Width="50" MaxWidth="50"></TextBox>
</Grid>
<Grid VerticalAlignment="Stretch" Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="BtnAddWaypoint" Padding="3" Grid.Column="0" HorizontalAlignment="Left" Width="213">Add Waypoint</Button>
<Button x:Name ="BtnClear" Padding="3" Grid.Column="1" HorizontalAlignment="Center" Width="203">Clear Last</Button>
<Button x:Name="BtnClearAll" Padding="3" Grid.Column="2" Margin="5,0,5,0" Width="213">Clear All</Button>
</Grid>
<TextBox ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" ScrollBar.Scroll="TextBox_Scroll" Padding ="3" AcceptsReturn="True" AcceptsTab="True" Margin="0,0,5,0" Height="50"/>
</StackPanel>
</GroupBox>
</StackPanel>
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" />
<StackPanel Grid.Column="2">
<GroupBox Height="718">
<TabControl>
<TabItem Header="Simulation">
<Grid Name="overall_grid" Height="669">
<!-- Helper to control the small box in order to find points in the 3D world, made invisible -->

<!-- The HelixViewport3D supports camera manipulation, and can be used just like the Viewport3D -->
<HelixToolkit:HelixViewport3D ZoomExtentsWhenLoaded="True" Margin="0,124,0,0" Name="m_helix_viewport" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="475">
<!-- Remember to add light to the scene -->
<HelixToolkit:SunLight/>
<!-- The content of this visual is defined in MainViewModel.cs -->
<ModelVisual3D Content="{Binding our_Model}"/>
</HelixToolkit:HelixViewport3D>
</Grid>





</TabItem>
<TabItem Header="Setup">
</TabItem>
<TabItem Header="Settings">
</TabItem>
</TabControl>
</GroupBox>
</StackPanel>
</Grid>
</DockPanel>

更新-

检查值已更改的事件,然后在创建的事件处理程序中发布代码以旋转模型似乎已经奏效。然而,0-360似乎让我的模型旋转了不止一圈

private void slJoint1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Matrix3D transformationMatrix7 = Shoulder1.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix7.Rotate(new Quaternion(new Vector3D(0, 0, 1), slJoint1.Value)); ; //Makes a rotation transformation over this matrix
Shoulder1.Transform = new MatrixTransform3D(transformationMatrix7);
}

使用事件,我将角度从GUI传递到代码后面,然后使用下面的代码更新模型的旋转角度。

public void Move_Joint1(double angle1,double angle2)
{
Transform3DGroup Joint1Group = new Transform3DGroup();

Joint1Group.Children.Add(new TranslateTransform3D(new Vector3D(0, 0, 185)));
Joint1Group.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), angle1)));
Shoulder1.Transform = Joint1Group;
Move_Joint2(angle1,angle2);
}

public void Move_Joint2(double angle1,double angle2)
{
Transform3DGroup Joint2Group = new Transform3DGroup();
Joint2Group.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), -90)));
Joint2Group.Children.Add(new TranslateTransform3D(new Vector3D(150, 0, 253)));
RotateTransform3D Joint2Rotation1 = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), angle1));
Joint2Rotation1.CenterX = Joint2Group.Transform(new Point3D(0, -150, 0)).X;
Joint2Rotation1.CenterY = Joint2Group.Transform(new Point3D(0, -150, 0)).Y;
Joint2Rotation1.CenterZ = Joint2Group.Transform(new Point3D(0, -150, 0)).Z;
Joint2Group.Children.Add(Joint2Rotation1);
Point3D origin = Joint2Group.Transform(new Point3D(0, 0, -70));
RotateTransform3D Joint2Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0.1, 0, 0), angle2));
Joint2Rotation.CenterX = origin.X;
Joint2Rotation.CenterY = origin.Y;
Joint2Rotation.CenterZ = origin.Z;
Joint2Group.Children.Add(Joint2Rotation);
Arm1.Transform = Joint2Group;
}

相关内容

  • 没有找到相关文章

最新更新