问题描述
大家好,我目前正在Win7上使用地形和飞机的WPF游戏中.相机绑定在飞机上,我可以使用键盘WQSE向前,向左,向后和向右移动它.现在,我要使用键盘键"A"& 'D'和鼠标 旋转相机,以便我可以在环境中环顾四周,有人可以提供解决方案吗?有关如何设置音高和音量的教程详细地偏转或演示将非常好,因为我是C#的新手,我不想使用XNA.我知道如何用OpenGL制作 C ++,但实际上不知道如何在WPF中使用C#来实现. THX很多!!
Hi all, I'm currently working on a WPF game on Win7, with a terrain and an aircraft. The camera is bound to the aircraft and i can use keyboard WQSE to move it forward, left, back and right. Now I want to use keyboad 'A' & 'D' and mouse to rotate the camera so I can look around in the environment, anybody could give solutions? A tutorial of how to set pitch & yaw in detail or a demo would be very nice, cuz I'm new to C# and I don't want to use XNA. I know how to make it with OpenGL C++, but really don't know how to make it with C# in WPF. THX alot !!
推荐答案
根据您的描述,我同意XNA可能是3D情况的最佳解决方案,但是原生3D支持和硬件加速渲染也是WPF和XAML的绝佳功能.
According to your description, i agree that maybe XNA would be the best solution for 3D situations, but native 3D support and hardware-accelerated rendering are also fantastic features of WPF and XAML.
这里有两个链接:
#在WPF中对3D摄像机的位置进行动画处理
http://blogs.microsoft. co.il/blogs/davids/archive/2009/06/22/rotate-a-camera-with-point3danimationusingpath.aspx
Here are two links:
#Animating the Position of a 3D Camera in WPF
http://blogs.microsoft.co.il/blogs/davids/archive/2009/06/22/rotate-a-camera-with-point3danimationusingpath.aspx
#用鼠标旋转相机
http://viewport3d.com/trackball.htm
在第一个链接中,有一个示例项目,用于XAML Viewport3D的3D相机非常适合该应用程序,还使用了绑定:
In the first link, there is a sample project, a 3D camer for XAML Viewport3D fits perfectly with the aplication, also using bindings:
<Viewport3D.Camera>
<PerspectiveCamera x:Name="camera"
UpDirection="0,0,1"
LookDirection="{Binding RelativeSource={RelativeSource Self}, Path=Position, Converter={StaticResource lookBackConverter}}"
Position="0,0,0" />
</Viewport3D.Camera>
要让摄像机移动,只需实现IValueConverter:
To let the camera move, just implement the IValueConverter:
public class LookBackConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new Point3D(0,0,0) - (Point3D)value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
这篇关于如何在WPF中使用鼠标(俯仰和偏航)和键盘旋转相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!