2012-01-29 183 views
3

我能夠直接在XAML中設置放置在viewport3d中的透視相機的位置和方向。 但我想知道如何使用鼠標輸入旋轉相機。 我寧願C#lang。 我實際上被困在如何使用鼠標輸入旋轉相機的地步。 請幫幫我。 如果有人給我一個示例代碼會有幫助....如何使用WPF中的鼠標在ViewPort3D中旋轉相機?

+0

我不知道你在做什麼,但你有沒有考慮切換到XNA? – 2012-01-29 01:16:37

+0

@Marc,先生,現在我使用WPF,如果我找不到任何縮放,平移和旋轉3D場景的方式,我會切換到XNA ... – 2012-01-29 06:35:02

回答

1

我認爲這兩個環節可以幫助你很多......

Animating the Position of a 3D Camera in WPF (還有一個示例項目嘗試!)

Rotating the Camera with the Mouse

我同意,也許XNA將是3D的情況下最好的解決辦法,但原生3D支持和硬件加速渲染也是WPF和XAML的神奇的功能!

正如你所看到的,一個3D攝像頭XAML Viewport3D與aplication完全符合,也使用綁定:

<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實現讓移動攝像機:

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; 
    } 
}