2

The goal is to measure a GeometryModel3D boundary (width, depth, height) but in some situations the model orientation is not correct so I want to allow the user to correct the orientation using the mouse with an interface similar to the camera controller (In inspect mode) in order for the user to correctly align the model.

I was able to achieve this to some extent using the RotateManipulator class but this limits to only correct the orientation in one axis. Furthermore I derived from the class and implemented my own mouse handler to change the RotateTransform3D axis but the result is not what I expect.

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

Another approach I was thinking is to use the perpective camera controller and use the difference of two camera locations as you move the camera (which looks as if the Model is rotating) and calculate the transformation from these two deltas which I can apply to the Model. But I'm not sure the Math required. I had a look at the RotateHandler.cs (Rotate camera using 'Turntable' rotation.) but a bit of direction would be greatly appreciated.

Ivan
  • 21
  • 3

0 Answers0