optimize glcontrol camera handling
This commit is contained in:
@@ -5,7 +5,8 @@ Namespace CameraN
|
||||
|
||||
Public Class Camera
|
||||
|
||||
Public Event NeedSelectedObject(e As NeedSelectedObjectEventArgs)
|
||||
Public Event NeedSelectedObject(sender As Object, e As NeedSelectedObjectEventArgs)
|
||||
Public Event PerspectiveChanged(sender As Object, e As EventArgs)
|
||||
|
||||
'P R I V A T E F I E L D S
|
||||
|
||||
@@ -276,8 +277,13 @@ Namespace CameraN
|
||||
UpdateMatrix(cameraMatrix)
|
||||
End Sub
|
||||
|
||||
Public Sub RaisePerspectiveChanged()
|
||||
RaiseEvent PerspectiveChanged(Me, New EventArgs)
|
||||
End Sub
|
||||
|
||||
Public Sub UpdateMatrix(ByRef cameraMatrix As Matrix4)
|
||||
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z, 0, 1, 0)
|
||||
RaisePerspectiveChanged()
|
||||
End Sub
|
||||
|
||||
Private Sub UpdateCameraMatrixWithScrollWheel_LOOK(amt As Integer, ByRef cameraMatrix As Matrix4)
|
||||
@@ -286,8 +292,10 @@ Namespace CameraN
|
||||
Select Case currentLookDirection
|
||||
Case LookDirection.Top
|
||||
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z - 1, 0, 1, 0)
|
||||
RaisePerspectiveChanged()
|
||||
Case LookDirection.Bottom
|
||||
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z + 1, 0, 1, 0)
|
||||
RaisePerspectiveChanged()
|
||||
Case Else
|
||||
UpdateMatrix(cameraMatrix)
|
||||
End Select
|
||||
@@ -347,6 +355,8 @@ Namespace CameraN
|
||||
lookPositions(CInt(currentLookDirection)) = pos
|
||||
End Select
|
||||
|
||||
RaisePerspectiveChanged()
|
||||
|
||||
lastMouseX = mouseX
|
||||
lastMouseY = mouseY
|
||||
'Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY);
|
||||
@@ -526,7 +536,7 @@ Namespace CameraN
|
||||
|
||||
Private Function GetSelectedObject() As ICameraPoint()
|
||||
Dim e As New NeedSelectedObjectEventArgs
|
||||
RaiseEvent NeedSelectedObject(e)
|
||||
RaiseEvent NeedSelectedObject(Me, e)
|
||||
|
||||
Dim stopw As New Stopwatch
|
||||
stopw.Start()
|
||||
|
||||
@@ -15,8 +15,6 @@ Namespace PreviewN
|
||||
|
||||
Public Class ModelPreview
|
||||
|
||||
Public Event WandUpdateView()
|
||||
|
||||
Private WithEvents glControl1 As GLControl
|
||||
Private WithEvents MyCamera As New Camera
|
||||
Private ProjMatrix As Matrix4 = Nothing
|
||||
@@ -26,19 +24,34 @@ Namespace PreviewN
|
||||
Private _isMouseDown As Boolean = False
|
||||
Private isDeactivated As Boolean = False
|
||||
Private ReadOnly myModels As New Dictionary(Of Object3D, Renderer)
|
||||
Private WithEvents RenderTimer As New Timers.Timer(1) With {.AutoReset = True}
|
||||
Private WithEvents RenderTimer As New Timers.Timer(25) With {.AutoReset = True}
|
||||
Private _EnableCameraControlling As Boolean = False
|
||||
|
||||
Public Property RenderWhenWindowsIsInactive As Boolean = False
|
||||
Public Property EnableCameraControlling As Boolean = True
|
||||
Public Property Scaling As Single = 500.0F
|
||||
Public Property ClearColor As Color = Color.CornflowerBlue
|
||||
|
||||
Public Property RenderInterval As Double
|
||||
Public Property EnableCameraControlling As Boolean
|
||||
Get
|
||||
Return renderTimer.Interval
|
||||
Return _EnableCameraControlling
|
||||
End Get
|
||||
Set
|
||||
renderTimer.Interval = Value
|
||||
_EnableCameraControlling = Value
|
||||
If Value Then
|
||||
If Not RenderTimer.Enabled Then
|
||||
RenderTimer.Start()
|
||||
End If
|
||||
ElseIf RenderTimer.Enabled Then
|
||||
RenderTimer.Stop()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property RenderInterval As Double
|
||||
Get
|
||||
Return RenderTimer.Interval
|
||||
End Get
|
||||
Set
|
||||
RenderTimer.Interval = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@@ -122,8 +135,8 @@ Namespace PreviewN
|
||||
Me.glControl1.VSync = False
|
||||
Me.Controls.Add(Me.glControl1)
|
||||
Me.ResumeLayout(False)
|
||||
renderTimer.Start()
|
||||
|
||||
'RenderTimer.SynchronizingObject = Nothing
|
||||
Scaling = scale
|
||||
|
||||
'Toolkit.Init()
|
||||
@@ -132,6 +145,7 @@ Namespace PreviewN
|
||||
AddHandler glControl1.MouseWheel, AddressOf glControl1_Wheel
|
||||
ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControl1.Width / glControl1.Height, 100.0F, 100000.0F)
|
||||
glControl1.Enabled = False
|
||||
|
||||
MyCamera.SetCameraMode(CameraMode.FLY, camMtx)
|
||||
MyCamera.UpdateMatrix(camMtx)
|
||||
|
||||
@@ -149,7 +163,9 @@ Namespace PreviewN
|
||||
End Sub
|
||||
|
||||
Public Sub UpdateView()
|
||||
glControl1.Invalidate()
|
||||
If glControl1.Enabled Then
|
||||
glControl1.Invoke(Sub() glControl1.Invalidate())
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Function AddModel(obj As Object3D) As Renderer
|
||||
@@ -206,17 +222,12 @@ Namespace PreviewN
|
||||
End Sub
|
||||
|
||||
Private Sub RenderTimer_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) Handles RenderTimer.Elapsed
|
||||
If Not isDeactivated OrElse RenderWhenWindowsIsInactive Then
|
||||
RaiseEvent WandUpdateView()
|
||||
glControl1.Invalidate()
|
||||
If Not isDeactivated Then
|
||||
MoveCameraViaWASDQE()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub HandlesOnPaint(sender As Object, e As PaintEventArgs) Handles glControl1.Paint
|
||||
If EnableCameraControlling Then
|
||||
MoveCameraViaWASDQE()
|
||||
End If
|
||||
|
||||
GL.ClearColor(ClearColor)
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit)
|
||||
@@ -306,10 +317,14 @@ Namespace PreviewN
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub Camera_NeedSelectedObject(e As Camera.NeedSelectedObjectEventArgs) Handles MyCamera.NeedSelectedObject
|
||||
Private Sub Camera_NeedSelectedObject(sender As Object, e As Camera.NeedSelectedObjectEventArgs) Handles MyCamera.NeedSelectedObject
|
||||
e.Points = Nothing
|
||||
End Sub
|
||||
|
||||
Private Sub MyCamera_PerspectiveChanged(sender As Object, e As EventArgs) Handles MyCamera.PerspectiveChanged
|
||||
UpdateView()
|
||||
End Sub
|
||||
|
||||
Private Sub ModelPreview_FormDisposed(sender As Object, e As EventArgs) Handles Me.Disposed
|
||||
For Each rndr As Renderer In myModels.Values
|
||||
rndr.ReleaseBuffers()
|
||||
|
||||
Reference in New Issue
Block a user