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