Helixtoolkit使用鼠标在所有3个轴上旋转GeometryModel3D

时间:2019-07-11 01:04:47

标签: wpf vb.net helix-3d-toolkit

目标是测量GeometryModel3D边界(宽度,深度,高度),但是在某些情况下模型方向不正确,因此我希望允许用户使用鼠标通过类似于相机控制器的界面来纠正方向(在检查模式下),以便用户正确对齐模型。

我可以使用RotateManipulator类在某种程度上实现这一点,但这仅限于校正一个轴上的方向。此外,我从该类派生并实现了自己的鼠标处理程序以更改RotateTransform3D轴,但结果不是我期望的。

Imports System.Windows.Data
Imports System.Windows.Media.Media3D
Imports System
Imports System.Windows
Imports System.Windows.Input
Imports HelixToolkit
Imports HelixToolkit.Wpf

Public Class RenderRotateManipulator
    Inherits HelixToolkit.Wpf.RotateManipulator

    Private m_model As GeometryModel3D
    Private m_transform As New RotateTransform3D
    Private m_clickedPoint As Point
    Public Sub New(ByRef g As GeometryModel3D)
        MyBase.New
        m_model = g       
        Me.TargetTransform = m_transform
        UpdateGeometry()
    End Sub

    Protected Overrides Sub UpdateGeometry()
         Me.Model.Geometry = m_model.Geometry
         Me.Model.Material = m_model.Material
    End Sub

    Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
        Dim currentPoint As Point = e.GetPosition(Me.ParentViewport)

        MyBase.OnMouseMove(e)

        If (Me.IsMouseCaptured) Then
            Me.Model.Transform = Me.TargetTransform

            If Not IsNothing(m_clickedPoint) Then
                Dim delta As Point = currentPoint - m_clickedPoint
                Dim angle As Double = Math.Atan2(delta.Y, delta.X)
                'Console.WriteLine("Angle=" & angle * Math.PI / 180 & " Clicked point=" & m_clickedPoint.ToString & " CurrentPoint=" & currentPoint.ToString)
                Me.Axis = New Vector3D(0, Math.Sin(angle), Math.Cos(angle))
            End If
        End If
    End Sub

    Protected Overrides Sub OnMouseDown(ByVal e As MouseButtonEventArgs)
        MyBase.OnMouseDown(e)
        m_clickedPoint = e.GetPosition(Me.ParentViewport)
    End Sub
End Class

我正在考虑的另一种方法是使用透视相机控制器,并在移动相机时使用两个相机位置的差异(看起来好像模型在旋转),并根据这两个增量计算转换,我可以应用模型。但是我不确定数学要求。我看过RotateHandler.cs(使用“ Turntable”旋转的旋转摄像机。)但是有些方向将不胜感激。

0 个答案:

没有答案