9d43c71eec
- aggiunti treeview degli oggetti e aboutbox.
176 lines
6.0 KiB
VB.net
176 lines
6.0 KiB
VB.net
Imports System.Math
|
|
Imports System.Globalization
|
|
Imports TestEIn.EgtInterface
|
|
|
|
Public Class Scene
|
|
|
|
Private m_nStatus As Integer
|
|
Private Enum ST As Integer
|
|
NULL = 0
|
|
PAN = 1
|
|
ROT = 2
|
|
ZOOMWIN = 3
|
|
End Enum
|
|
Private m_nGseContext As Integer
|
|
Private m_PrevPoint As Point
|
|
|
|
Sub New()
|
|
' Chiamata richiesta dalla finestra di progettazione.
|
|
InitializeComponent()
|
|
' Istruzioni di inizializzazione.
|
|
SetStyle(ControlStyles.Opaque, True)
|
|
SetStyle(ControlStyles.UserPaint, True)
|
|
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
|
|
m_nStatus = ST.NULL
|
|
m_nGseContext = 0
|
|
m_PrevPoint = Point.Empty
|
|
Cursor = New Cursor(Me.GetType(), "Pointer.cur")
|
|
End Sub
|
|
|
|
Public Sub Init()
|
|
EgtInit(0, "TestEngine.log")
|
|
EgtSetFont("C:\EgtProg\Fonts", "ModernProp.Nfe")
|
|
m_nGseContext = EgtInitGeomDB()
|
|
EgtSetDefaultMaterial(m_nGseContext, 255, 165, 0)
|
|
EgtInitScene(m_nGseContext, Handle, 3, True, 24, 32)
|
|
EgtSetBackground(m_nGseContext, 140, 154, 168, 40, 44, 48, False)
|
|
EgtInitTscExec(m_nGseContext)
|
|
End Sub
|
|
|
|
Public Function GetCtx() As Integer
|
|
Return m_nGseContext
|
|
End Function
|
|
|
|
Protected Overrides Sub OnHandleDestroyed(e As EventArgs)
|
|
EgtExit()
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnPaint(e As PaintEventArgs)
|
|
MyBase.OnPaint(e)
|
|
EgtDraw(m_nGseContext)
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnPaintBackground(pevent As PaintEventArgs)
|
|
MyBase.OnPaintBackground(pevent)
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnResize(e As System.EventArgs)
|
|
MyBase.OnResize(e)
|
|
EgtResize(m_nGseContext, Width, Height)
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnMouseEnter(e As System.EventArgs)
|
|
MyBase.OnMouseEnter(e)
|
|
Focus()
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
|
|
If e.Button = Windows.Forms.MouseButtons.Middle Then
|
|
If (Control.ModifierKeys And Keys.Shift) = Keys.Shift Then
|
|
m_nStatus = ST.ZOOMWIN
|
|
Cursor = New Cursor(Me.GetType(), "ZoomWin.cur")
|
|
ElseIf (Control.ModifierKeys And Keys.Control) = Keys.Control Then
|
|
m_nStatus = ST.ROT
|
|
Cursor = New Cursor(Me.GetType(), "Rotate.cur")
|
|
Else
|
|
m_nStatus = ST.PAN
|
|
Cursor = New Cursor(Me.GetType(), "Pan.cur")
|
|
End If
|
|
m_PrevPoint = e.Location
|
|
Else
|
|
MyBase.OnMouseDown(e)
|
|
End If
|
|
Focus()
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnMouseUp(e As System.Windows.Forms.MouseEventArgs)
|
|
If e.Button = Windows.Forms.MouseButtons.Middle Then
|
|
If m_nStatus = ST.ZOOMWIN Then
|
|
EgtResetWinRect(m_nGseContext, False)
|
|
EgtZoomWin(m_nGseContext, m_PrevPoint, e.Location)
|
|
End If
|
|
If m_nStatus <> ST.NULL Then
|
|
m_nStatus = ST.NULL
|
|
Cursor = New Cursor(Me.GetType(), "Pointer.cur")
|
|
End If
|
|
Else
|
|
MyBase.OnMouseUp(e)
|
|
End If
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnMouseMove(e As System.Windows.Forms.MouseEventArgs)
|
|
'Visualizzo le coordinate del mouse
|
|
ShowCursorPos(e.Location)
|
|
'Secondo lo stato...
|
|
If e.Button = Windows.Forms.MouseButtons.Middle Then
|
|
If m_nStatus = ST.ZOOMWIN Then
|
|
Cursor = New Cursor(Me.GetType(), "ZoomWin.cur")
|
|
EgtSetWinRect(m_nGseContext, m_PrevPoint, e.Location)
|
|
'Il punto di riferimento deve rimanere quello originale
|
|
ElseIf m_nStatus = ST.ROT Then
|
|
Cursor = New Cursor(Me.GetType(), "Rotate.cur")
|
|
EgtRotateCamera(m_nGseContext, m_PrevPoint, e.Location)
|
|
m_PrevPoint = e.Location
|
|
ElseIf m_nStatus = ST.PAN Then
|
|
Cursor = New Cursor(Me.GetType(), "Pan.cur")
|
|
EgtPanCamera(m_nGseContext, m_PrevPoint, e.Location)
|
|
m_PrevPoint = e.Location
|
|
Else
|
|
m_nStatus = ST.NULL
|
|
Cursor = New Cursor(Me.GetType(), "Pointer.cur")
|
|
End If
|
|
Else
|
|
MyBase.OnMouseMove(e)
|
|
End If
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnMouseWheel(e As System.Windows.Forms.MouseEventArgs)
|
|
If Abs(e.Delta) < 30 Then
|
|
Return
|
|
End If
|
|
' calcolo coefficiente
|
|
Const WHEEL_DELTA As Double = 120
|
|
Dim dCoeff As Double = 1 - 0.1 * Abs(e.Delta) / WHEEL_DELTA
|
|
If e.Delta < 0 Then
|
|
dCoeff = 1 / dCoeff
|
|
End If
|
|
' eseguo zoom
|
|
EgtZoomOnPoint(m_nGseContext, e.Location, dCoeff)
|
|
End Sub
|
|
|
|
Private Sub ShowCursorPos(ByVal WinXY As Point)
|
|
'ricavo punto 3d
|
|
Dim ptWorld As Point3d
|
|
EgtUnProjectPoint(m_nGseContext, WinXY, ptWorld)
|
|
'ricavo direzione di vista
|
|
Dim nDir As Integer
|
|
EgtGetCameraDir(m_nGseContext, nDir)
|
|
'costruisco stringa con dati
|
|
Dim sCursorPos As New System.Text.StringBuilder
|
|
Select Case nDir
|
|
Case CT_TOP, CT_BOTTOM
|
|
sCursorPos.Append("X=")
|
|
sCursorPos.Append(ptWorld.x.ToString("F4", CultureInfo.InvariantCulture))
|
|
sCursorPos.Append(" Y=")
|
|
sCursorPos.Append(ptWorld.y.ToString("F4", CultureInfo.InvariantCulture))
|
|
Case CT_FRONT, CT_BACK
|
|
sCursorPos.Append("X=")
|
|
sCursorPos.Append(ptWorld.x.ToString("F4", CultureInfo.InvariantCulture))
|
|
sCursorPos.Append(" Z=")
|
|
sCursorPos.Append(ptWorld.z.ToString("F4", CultureInfo.InvariantCulture))
|
|
Case CT_LEFT, CT_RIGHT
|
|
sCursorPos.Append("Y=")
|
|
sCursorPos.Append(ptWorld.y.ToString("F4", CultureInfo.InvariantCulture))
|
|
sCursorPos.Append(" Z=")
|
|
sCursorPos.Append(ptWorld.z.ToString("F4", CultureInfo.InvariantCulture))
|
|
Case Else
|
|
sCursorPos.Append(" ")
|
|
End Select
|
|
' lancio l'evento per visualizzare la stringa
|
|
RaiseEvent CursorPos(Me, sCursorPos.ToString)
|
|
End Sub
|
|
|
|
Public Event CursorPos(ByVal sender As Object, ByVal sCursorPos As String)
|
|
|
|
End Class
|