Files
TestEIn/Scene.vb
T
Dario Sassi 2b91dc0c7f TestEIn 1.5h1 :
- primo commit.
2014-08-31 10:33:23 +00:00

173 lines
5.8 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_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_PrevPoint = Point.Empty
Cursor = New Cursor(Me.GetType(), "Pointer.cur")
End Sub
Public Sub Init()
EgtSetLog(0, "TestEngine.log")
EgtSetFont("C:\EgtProg\Fonts", "ModernProp.Nfe")
EgtInit(Handle, 3, True, 24, 32)
EgtSetDefaultMaterial(255, 165, 0)
EgtSetBackground(140, 154, 168, 40, 44, 48)
End Sub
Protected Overrides Sub OnHandleDestroyed(e As EventArgs)
EgtExit()
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
EgtDraw()
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(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()
EgtZoomWin(m_PrevPoint.X, m_PrevPoint.Y, e.Location.X, e.Location.Y)
Invalidate()
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_PrevPoint.X, m_PrevPoint.Y, e.Location.X, e.Location.Y)
Invalidate()
'Il punto di riferimento deve rimanere quello originale
ElseIf m_nStatus = ST.ROT Then
Cursor = New Cursor(Me.GetType(), "Rotate.cur")
EgtRotateCamera(m_PrevPoint.X, m_PrevPoint.Y, e.Location.X, e.Location.Y)
Invalidate()
m_PrevPoint = e.Location
ElseIf m_nStatus = ST.PAN Then
Cursor = New Cursor(Me.GetType(), "Pan.cur")
EgtPanCamera(m_PrevPoint.X, m_PrevPoint.Y, e.Location.X, e.Location.Y)
Invalidate()
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(e.X, e.Y, dCoeff)
Invalidate()
End Sub
Private Sub ShowCursorPos(ByVal WinXY As Point)
'ricavo punto 3d
Dim ptWorld As Point3d
EgtUnProject(WinXY.X, WinXY.Y, ptWorld)
'ricavo direzione di vista
Dim nDir As Integer
EgtGetCameraDir(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