190607 c1

- Add Pilz.Drawing.Drawing3D.OpenGLFactory
- Fix small bugs in Pilz.UI.PaintingControl
This commit is contained in:
2019-06-07 20:56:19 +02:00
parent ef15e45df7
commit 2f09834fa0
65 changed files with 6670 additions and 118 deletions

View File

@@ -0,0 +1,570 @@
Imports System.Windows.Forms
Imports OpenTK
Namespace CameraN
Public Class Camera
Public Event NeedSelectedObject(e As NeedSelectedObjectEventArgs)
'P R I V A T E F I E L D S
Private ReadOnly TAU As Single = Math.PI * 2
Private myCamMode As CameraMode = CameraMode.FLY
Private pos As New Vector3(-5000.0F, 3000.0F, 4000.0F)
Private myLookat As New Vector3(0F, 0F, 0F)
Private myFarPoint As New Vector3(0F, 0F, 0F)
Private myNearPoint As New Vector3(0F, 0F, 0F)
Private lastMouseX As Integer = -1, lastMouseY As Integer = -1
Private CamAngleX As Single = 0F, CamAngleY As Single = -(Math.PI / 2)
Private resetMouse As Boolean = True
Private orbitDistance As Single = 500.0F
Private orbitTheta As Single = 0.0F, orbitPhi As Single = 0.0F
Private currentLookDirection As LookDirection
Private lookPositions() As Vector3 = {
New Vector3(0, 12500, 0),
New Vector3(0, -12500, 0),
New Vector3(-12500, 0, 0),
New Vector3(12500, 0, 0),
New Vector3(0, 0, 12500),
New Vector3(0, 0, -12500)
}
'A U T O M A T I C P R O P E R T I E S
Public Property CamSpeedMultiplier As Single = 1
'P R O P E R T I E S
Public ReadOnly Property CamMode As CameraMode
Get
Return myCamMode
End Get
End Property
Public ReadOnly Property Yaw As Single
Get
Return CamAngleX
End Get
End Property
Public ReadOnly Property Pitch As Single
Get
Return CamAngleY
End Get
End Property
Public ReadOnly Property Yaw_Degrees As Single
Get
Return CamAngleX * (180.0F / 3.14159274F)
End Get
End Property
Public ReadOnly Property Pitch_Degrees As Single
Get
Return CamAngleY * (180.0F / 3.14159274F)
End Get
End Property
Public Property Position As Vector3
Get
Return pos
End Get
Set(value As Vector3)
pos = value
End Set
End Property
Public Property LookAt As Vector3
Get
Return myLookat
End Get
Set(value As Vector3)
myLookat = value
End Set
End Property
Public Property NearPoint As Vector3
Get
Return myNearPoint
End Get
Set(value As Vector3)
myNearPoint = value
End Set
End Property
Public Property FarPoint As Vector3
Get
Return myFarPoint
End Get
Set(value As Vector3)
myFarPoint = value
End Set
End Property
'C O N S T R U C T O R
Public Sub New()
SetRotationFromLookAt()
End Sub
'F E A T U R E S
Private Function Clampf(value As Single, min As Single, max As Single) As Single
Return If(value > max, max, If(value < min, min, value))
End Function
Private Sub OrientateCam(ang As Single, ang2 As Single)
Dim CamLX As Single = CSng(Math.Sin(ang)) * CSng(Math.Sin(-ang2))
Dim CamLY As Single = CSng(Math.Cos(ang2))
Dim CamLZ As Single = CSng(-Math.Cos(ang)) * CSng(Math.Sin(-ang2))
myLookat.X = pos.X + (-CamLX) * 100.0F
myLookat.Y = pos.Y + (-CamLY) * 100.0F
myLookat.Z = pos.Z + (-CamLZ) * 100.0F
End Sub
Private Sub OffsetCam(xAmt As Integer, yAmt As Integer, zAmt As Integer)
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim CamLX As Single = CSng(Math.Sin(CamAngleX)) * CSng(Math.Cos(-pitch_Renamed))
Dim CamLY As Single = CSng(Math.Sin(pitch_Renamed))
Dim CamLZ As Single = CSng(-Math.Cos(CamAngleX)) * CSng(Math.Cos(-pitch_Renamed))
pos.X = pos.X + xAmt * (CamLX) * CamSpeedMultiplier
pos.Y = pos.Y + yAmt * (CamLY) * CamSpeedMultiplier
pos.Z = pos.Z + zAmt * (CamLZ) * CamSpeedMultiplier
End Sub
Public Sub Move(y As Single, ByRef camMtx As Matrix4)
OffsetCam(0, y, 0)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(camMtx)
End Sub
Public Sub Move(x As Single, z As Single, ByRef camMtx As Matrix4)
UpdateCameraOffsetDirectly(x, z, camMtx)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(camMtx)
End Sub
Public Sub SetRotationFromLookAt()
Dim x_diff As Single = myLookat.X - pos.X
Dim y_diff As Single = myLookat.Y - pos.Y
Dim z_diff As Single = myLookat.Z - pos.Z
Dim dist As Single = CSng(Math.Sqrt(x_diff * x_diff + y_diff * y_diff + z_diff * z_diff))
If z_diff = 0 Then
z_diff = 0.001F
End If
Dim nxz_ratio As Single = -x_diff / z_diff
If z_diff < 0 Then
CamAngleX = CSng(Math.Atan(nxz_ratio) + Math.PI)
Else
CamAngleX = CSng(Math.Atan(nxz_ratio))
End If
CamAngleY = -3.1459F - (CSng(Math.Asin(y_diff / dist)) - 1.57F)
End Sub
Public Sub ResetOrbitToSelectedObject()
Dim objs As ICameraPoint() = GetSelectedObject()
If objs?.Length > 0 Then
orbitTheta = -(CalculateCenterYRotationOfObjects(objs) * (CSng(Math.PI) / 180.0F))
orbitPhi = -0.3F
orbitDistance = 1200.0F
End If
End Sub
Public Sub UpdateOrbitCamera(ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT Then
Dim objs As ICameraPoint() = GetSelectedObject()
If objs?.Length > 0 Then
Dim centerPos As Numerics.Vector3 = CalculateCenterPositionOfObjects(objs)
pos.X = centerPos.X + CSng(Math.Cos(orbitPhi) * -Math.Sin(orbitTheta) * orbitDistance)
pos.Y = centerPos.Y + CSng(-Math.Sin(orbitPhi) * orbitDistance)
pos.Z = centerPos.Z + CSng(Math.Cos(orbitPhi) * Math.Cos(orbitTheta) * orbitDistance)
myLookat.X = centerPos.X
myLookat.Y = centerPos.Y
myLookat.Z = centerPos.Z
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
End If
End If
End Sub
Public Function IsOrbitCamera() As Boolean
Return myCamMode = CameraMode.ORBIT
End Function
Public Sub SetCameraMode(mode As CameraMode, ByRef cameraMatrix As Matrix4)
myCamMode = mode
If IsOrbitCamera() Then
ResetOrbitToSelectedObject()
UpdateOrbitCamera(cameraMatrix)
End If
End Sub
Public Sub SetCameraMode_LookDirection(dir As LookDirection, ByRef cameraMatrix As Matrix4)
myCamMode = CameraMode.LOOK_DIRECTION
currentLookDirection = dir
Select Case currentLookDirection
Case LookDirection.Top
pos = lookPositions(CInt(LookDirection.Top))
myLookat = New Vector3(pos.X, -25000, pos.Z - 1)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Bottom
pos = lookPositions(CInt(LookDirection.Bottom))
myLookat = New Vector3(pos.X, 25000, pos.Z + 1)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Left
pos = lookPositions(CInt(LookDirection.Left))
myLookat = New Vector3(25000, pos.Y, pos.Z)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Right
pos = lookPositions(CInt(LookDirection.Right))
myLookat = New Vector3(-25000, pos.Y, pos.Z)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Front
pos = lookPositions(CInt(LookDirection.Front))
myLookat = New Vector3(pos.X, pos.Y, -25000)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
Case LookDirection.Back
pos = lookPositions(CInt(LookDirection.Back))
myLookat = New Vector3(pos.X, pos.Y, 25000)
UpdateMatrix(cameraMatrix)
SetRotationFromLookAt()
End Select
End Sub
Public Sub UpdateCameraMatrixWithMouse(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then
UpdateCameraMatrixWithMouse_ORBIT(mouseX, mouseY, cameraMatrix)
ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then
UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, cameraMatrix)
Else
UpdateCameraMatrixWithMouse_FLY(mouseX, mouseY, cameraMatrix)
End If
End Sub
Public Sub UpdateCameraOffsetWithMouse(orgPos As Vector3, mouseX As Integer, mouseY As Integer, w As Integer, h As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then
UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, cameraMatrix)
ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then
UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, cameraMatrix)
Else
UpdateCameraOffsetWithMouse_FLY(orgPos, mouseX, mouseY, w, h, cameraMatrix)
End If
End Sub
Public Sub UpdateCameraMatrixWithScrollWheel(amt As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then
UpdateCameraMatrixWithScrollWheel_ORBIT(amt, cameraMatrix)
ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then
UpdateCameraMatrixWithScrollWheel_LOOK(amt, cameraMatrix)
Else
UpdateCameraMatrixWithScrollWheel_FLY(amt, cameraMatrix)
End If
End Sub
Private Sub UpdateCameraMatrixWithScrollWheel_FLY(amt As Integer, ByRef cameraMatrix As Matrix4)
OffsetCam(amt, amt, amt)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
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)
End Sub
Private Sub UpdateCameraMatrixWithScrollWheel_LOOK(amt As Integer, ByRef cameraMatrix As Matrix4)
OffsetCam(amt, amt, amt)
OrientateCam(CamAngleX, CamAngleY)
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)
Case LookDirection.Bottom
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z + 1, 0, 1, 0)
Case Else
UpdateMatrix(cameraMatrix)
End Select
End Sub
Private Sub UpdateCameraMatrixWithMouse_LOOK(orgPos As Vector3, mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = mouseX - lastMouseX
Dim MousePosY As Integer = mouseY - lastMouseY
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2)
Dim CamLX As Single = CSng(Math.Sin(yaw_Renamed))
Dim CamLY As Single = CSng(Math.Cos(pitch_Renamed))
Dim CamLZ As Single = CSng(-Math.Cos(yaw_Renamed))
Dim m As Single = 8.0F
Select Case currentLookDirection
Case LookDirection.Top
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) - ((MousePosY * CamSpeedMultiplier) * (CamLZ) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) - ((MousePosY * CamSpeedMultiplier) * (CamLX) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y - 1000, pos.Z - 1, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Bottom
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) + ((MousePosY * CamSpeedMultiplier) * (CamLZ) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) + ((MousePosY * CamSpeedMultiplier) * (CamLX) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y + 1000, pos.Z + 1, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Left
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X + 12500, pos.Y, pos.Z, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Right
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X - 12500, pos.Y, pos.Z, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Front
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z - 12500, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
Case LookDirection.Back
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m)
cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z + 12500, 0, 1, 0)
lookPositions(CInt(currentLookDirection)) = pos
End Select
lastMouseX = mouseX
lastMouseY = mouseY
'Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY);
'setRotationFromLookAt();
End Sub
Private Sub UpdateCameraMatrixWithMouse_FLY(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = mouseX - lastMouseX
Dim MousePosY As Integer = mouseY - lastMouseY
CamAngleX = CamAngleX + (0.01F * MousePosX)
' This next part isn't neccessary, but it keeps the Yaw rotation value within [0, 2*pi] which makes debugging simpler.
If CamAngleX > TAU Then
CamAngleX -= TAU
ElseIf CamAngleX < 0 Then
CamAngleX += TAU
End If
' Lock pitch rotation within the bounds of [-3.1399.0, -0.0001], otherwise the LookAt function will snap to the
' opposite side and reverse mouse looking controls.
CamAngleY = Clampf((CamAngleY + (0.01F * MousePosY)), -3.1399F, -0.0001F)
lastMouseX = mouseX
lastMouseY = mouseY
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
'Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY);
'setRotationFromLookAt();
End Sub
Private Sub UpdateCameraOffsetWithMouse_FLY(orgPos As Vector3, mouseX As Integer, mouseY As Integer, w As Integer, h As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = (-mouseX) + lastMouseX
Dim MousePosY As Integer = (-mouseY) + lastMouseY
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2)
Dim CamLX As Single = Math.Sin(yaw_Renamed)
Dim CamLZ As Single = -Math.Cos(yaw_Renamed)
pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * 6.0F)
pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * 6.0F)
pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * 6.0F)
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
End Sub
Public Sub UpdateCameraOffsetDirectly(horz_amount As Integer, vert_amount As Integer, ByRef cameraMatrix As Matrix4)
If myCamMode = CameraMode.ORBIT Then
UpdateCameraOffsetDirectly_ORBIT(horz_amount / 5, vert_amount / 5, cameraMatrix)
Else
'Console.WriteLine(MousePosX+","+ MousePosY);
Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2)
Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2)
Dim CamLX As Single = CSng(Math.Sin(yaw_Renamed))
' float CamLY = (float)Math.Cos(pitch);
Dim CamLZ As Single = CSng(-Math.Cos(yaw_Renamed))
pos.X += ((horz_amount * CamSpeedMultiplier) * (CamLX))
pos.Y += ((vert_amount * CamSpeedMultiplier) * (-1.0F))
pos.Z += ((horz_amount * CamSpeedMultiplier) * (CamLZ))
OrientateCam(CamAngleX, CamAngleY)
UpdateMatrix(cameraMatrix)
End If
End Sub
Private Sub UpdateCameraOffsetDirectly_ORBIT(moveSpeedX As Integer, moveSpeedY As Integer, ByRef cameraMatrix As Matrix4)
Dim MousePosX As Integer = moveSpeedX
Dim MousePosY As Integer = moveSpeedY
orbitTheta += MousePosX * 0.01F * CamSpeedMultiplier
orbitPhi -= MousePosY * 0.01F * CamSpeedMultiplier
orbitPhi = Clampf(orbitPhi, -1.57F, 1.57F)
UpdateOrbitCamera(cameraMatrix)
End Sub
Private Sub UpdateCameraMatrixWithMouse_ORBIT(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, cameraMatrix)
End Sub
Private Sub UpdateCameraOffsetWithMouse_ORBIT(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4)
If resetMouse Then
lastMouseX = mouseX
lastMouseY = mouseY
resetMouse = False
End If
Dim MousePosX As Integer = (-mouseX) + lastMouseX
Dim MousePosY As Integer = (-mouseY) + lastMouseY
orbitTheta += MousePosX * 0.01F * CamSpeedMultiplier
orbitPhi -= MousePosY * 0.01F * CamSpeedMultiplier
orbitPhi = Clampf(orbitPhi, -1.57F, 1.57F)
UpdateOrbitCamera(cameraMatrix)
lastMouseX = mouseX
lastMouseY = mouseY
End Sub
Private Sub UpdateCameraMatrixWithScrollWheel_ORBIT(amt As Integer, ByRef cameraMatrix As Matrix4)
orbitDistance -= amt
If orbitDistance < 300.0F Then
orbitDistance = 300.0F
End If
UpdateOrbitCamera(cameraMatrix)
End Sub
Public Sub ResetMouseStuff()
resetMouse = True
End Sub
Private Function CalculateCenterPositionOfObjects(objs As ICameraPoint()) As Numerics.Vector3
If objs.Length <= 1 Then
Dim obj As ICameraPoint = objs.FirstOrDefault
If obj Is Nothing Then
Return Numerics.Vector3.Zero
Else
Return New Numerics.Vector3(obj.Position.X,
obj.Position.Y,
obj.Position.Z)
End If
End If
Dim maxX As Single? = Nothing
Dim maxY As Single? = Nothing
Dim maxZ As Single? = Nothing
Dim minX As Single? = Nothing
Dim minY As Single? = Nothing
Dim minZ As Single? = Nothing
For Each obj As ICameraPoint In objs
Dim pos As Numerics.Vector3 = obj.Position
If maxX Is Nothing OrElse pos.X > maxX Then maxX = pos.X
If maxY Is Nothing OrElse pos.Y > maxY Then maxY = pos.Y
If maxZ Is Nothing OrElse pos.Z > maxZ Then maxZ = pos.Z
If minX Is Nothing OrElse pos.X < minX Then minX = pos.X
If minY Is Nothing OrElse pos.Y < minY Then minY = pos.Y
If minZ Is Nothing OrElse pos.Z < minZ Then minZ = pos.Z
Next
If maxX Is Nothing Then maxX = 0
If maxY Is Nothing Then maxY = 0
If maxZ Is Nothing Then maxZ = 0
If minX Is Nothing Then minX = 0
If minY Is Nothing Then minY = 0
If minZ Is Nothing Then minZ = 0
Dim upper As New Numerics.Vector3(maxX, maxY, maxZ)
Dim lower As New Numerics.Vector3(minX, minY, minZ)
Dim middle As Numerics.Vector3 = (upper + lower) / 2
Return middle
End Function
Private Function CalculateCenterYRotationOfObjects(objs As ICameraPoint()) As Single
If objs.Length <= 1 Then
Dim obj As ICameraPoint = objs.FirstOrDefault
If obj Is Nothing Then
Return 0
Else
Return obj.Rotation.Y
End If
End If
Dim yRot As New List(Of Single)
For Each obj As ICameraPoint In objs
yRot.Add(obj.Rotation.Y)
Next
Return yRot.Average
End Function
Private Function GetSelectedObject() As ICameraPoint()
Dim e As New NeedSelectedObjectEventArgs
RaiseEvent NeedSelectedObject(e)
Dim stopw As New Stopwatch
stopw.Start()
Do Until e.HasObjectSetted OrElse stopw.ElapsedMilliseconds > 1000
Application.DoEvents()
Loop
stopw.Stop()
Return e.Points
End Function
'C A P S E L T C L A S S E S
Public Class NeedSelectedObjectEventArgs
Inherits EventArgs
Private _HasObjectSetted As Boolean = False
Public ReadOnly Property HasObjectSetted As Boolean
Get
Return _HasObjectSetted
End Get
End Property
Private _Points As ICameraPoint() = Nothing
Public Property Points As ICameraPoint()
Get
Return _Points
End Get
Set(value As ICameraPoint())
_Points = value
_HasObjectSetted = True
End Set
End Property
End Class
End Class
End Namespace

View File

@@ -0,0 +1,9 @@
Namespace CameraN
Public Enum CameraMode
FLY = 0
ORBIT = 1
LOOK_DIRECTION = 2
End Enum
End Namespace

View File

@@ -0,0 +1,10 @@
Namespace CameraN
Public Interface ICameraPoint
Property Position As Numerics.Vector3
Property Rotation As Numerics.Vector3
End Interface
End Namespace

View File

@@ -0,0 +1,12 @@
Namespace CameraN
Public Enum LookDirection
Top
Bottom
Left
Right
Front
Back
End Enum
End Namespace

View File

@@ -0,0 +1,120 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class ModelPreview
Inherits DevComponents.DotNetBar.OfficeForm
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ModelPreview))
Me.PanelEx1 = New DevComponents.DotNetBar.PanelEx()
Me.PanelEx2 = New DevComponents.DotNetBar.PanelEx()
Me.DoubleInput1 = New DevComponents.Editors.DoubleInput()
Me.LabelX1 = New DevComponents.DotNetBar.LabelX()
Me.PanelEx2.SuspendLayout()
CType(Me.DoubleInput1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'PanelEx1
'
Me.PanelEx1.CanvasColor = System.Drawing.Color.Empty
Me.PanelEx1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled
Me.PanelEx1.DisabledBackColor = System.Drawing.Color.Empty
Me.PanelEx1.Dock = System.Windows.Forms.DockStyle.Fill
Me.PanelEx1.Location = New System.Drawing.Point(0, 47)
Me.PanelEx1.Name = "PanelEx1"
Me.PanelEx1.Size = New System.Drawing.Size(880, 491)
Me.PanelEx1.Style.Alignment = System.Drawing.StringAlignment.Center
Me.PanelEx1.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
Me.PanelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
Me.PanelEx1.Style.GradientAngle = 90
Me.PanelEx1.TabIndex = 0
'
'PanelEx2
'
Me.PanelEx2.CanvasColor = System.Drawing.Color.Empty
Me.PanelEx2.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled
Me.PanelEx2.Controls.Add(Me.DoubleInput1)
Me.PanelEx2.Controls.Add(Me.LabelX1)
Me.PanelEx2.DisabledBackColor = System.Drawing.Color.Empty
Me.PanelEx2.Dock = System.Windows.Forms.DockStyle.Top
Me.PanelEx2.Location = New System.Drawing.Point(0, 0)
Me.PanelEx2.Name = "PanelEx2"
Me.PanelEx2.Size = New System.Drawing.Size(880, 47)
Me.PanelEx2.Style.Alignment = System.Drawing.StringAlignment.Center
Me.PanelEx2.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
Me.PanelEx2.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
Me.PanelEx2.Style.GradientAngle = 90
Me.PanelEx2.TabIndex = 7
Me.PanelEx2.Visible = False
'
'DoubleInput1
'
'
'
'
Me.DoubleInput1.BackgroundStyle.Class = "DateTimeInputBackground"
Me.DoubleInput1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square
Me.DoubleInput1.ButtonFreeText.Shortcut = DevComponents.DotNetBar.eShortcut.F2
Me.DoubleInput1.Increment = 1.0R
Me.DoubleInput1.Location = New System.Drawing.Point(62, 13)
Me.DoubleInput1.Name = "DoubleInput1"
Me.DoubleInput1.ShowUpDown = True
Me.DoubleInput1.Size = New System.Drawing.Size(80, 20)
Me.DoubleInput1.TabIndex = 0
'
'LabelX1
'
'
'
'
Me.LabelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square
Me.LabelX1.Location = New System.Drawing.Point(12, 12)
Me.LabelX1.Name = "LabelX1"
Me.LabelX1.Size = New System.Drawing.Size(44, 23)
Me.LabelX1.TabIndex = 1
Me.LabelX1.Text = "Scaling:"
'
'ModelPreview
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(880, 538)
Me.Controls.Add(Me.PanelEx1)
Me.Controls.Add(Me.PanelEx2)
Me.DoubleBuffered = True
Me.EnableGlass = False
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.KeyPreview = True
Me.Name = "ModelPreview"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "ModelPreview"
Me.TopLeftCornerSize = 0
Me.TopRightCornerSize = 0
Me.PanelEx2.ResumeLayout(False)
CType(Me.DoubleInput1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
Friend WithEvents PanelEx1 As DevComponents.DotNetBar.PanelEx
Friend WithEvents PanelEx2 As DevComponents.DotNetBar.PanelEx
Friend WithEvents DoubleInput1 As DevComponents.Editors.DoubleInput
Friend WithEvents LabelX1 As DevComponents.DotNetBar.LabelX
End Class

View File

@@ -0,0 +1,13 @@
'------------------------------------------------------------------------------
' <auto-generated>
' Dieser Code wurde von einem Tool generiert.
' Laufzeitversion:4.0.30319.42000
'
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
' der Code erneut generiert wird.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>false</MySubMain>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>1</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

View File

@@ -0,0 +1,35 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' Allgemeine Informationen über eine Assembly werden über die folgenden
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
' die einer Assembly zugeordnet sind.
' Werte der Assemblyattribute überprüfen
<Assembly: AssemblyTitle("OpenGLRenderer")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Pilzinsel64")>
<Assembly: AssemblyProduct("OpenGLRenderer")>
<Assembly: AssemblyCopyright("Copyright © Pilzinsel64 2018")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
<Assembly: Guid("03d57392-1aac-468d-b5c9-30d927e685b5")>
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
'
' Hauptversion
' Nebenversion
' Buildnummer
' Revision
'
' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@@ -0,0 +1,63 @@
'------------------------------------------------------------------------------
' <auto-generated>
' Dieser Code wurde von einem Tool generiert.
' Laufzeitversion:4.0.30319.42000
'
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
' der Code erneut generiert wird.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Imports System
Namespace My.Resources
'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
'-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
'''<summary>
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Drawing.Drawing3D.OpenGLFactory.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set
resourceCulture = value
End Set
End Property
End Module
End Namespace

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,73 @@
'------------------------------------------------------------------------------
' <auto-generated>
' Dieser Code wurde von einem Tool generiert.
' Laufzeitversion:4.0.30319.42000
'
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
' der Code erneut generiert wird.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
#Region "Automatische My.Settings-Speicherfunktion"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.Pilz.Drawing.Drawing3D.OpenGLFactory.My.MySettings
Get
Return Global.Pilz.Drawing.Drawing3D.OpenGLFactory.My.MySettings.Default
End Get
End Property
End Module
End Namespace

View File

@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@@ -0,0 +1,25 @@
<configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
<!-- XQuartz compatibility (X11 on Mac) -->
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
</configuration>

View File

@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Pilz.Drawing.Drawing3D.OpenGLFactory</RootNamespace>
<AssemblyName>Pilz.Drawing.Drawing3D.OpenGLFactory</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>Pilz.Drawing.Drawing3D.OpenGLFactory.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>Pilz.Drawing.Drawing3D.OpenGLFactory.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=3.0.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\packages\OpenTK.3.0.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="OpenTK.GLControl, Version=3.0.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\packages\OpenTK.GLControl.3.0.1\lib\net20\OpenTK.GLControl.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\portable-net45+win8+wp8+wpa81\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="Camera\Camera.vb" />
<Compile Include="Camera\CameraMode.vb" />
<Compile Include="Camera\LookDirection.vb" />
<Compile Include="Preview\ModelPreview.Designer.vb">
<DependentUpon>ModelPreview.vb</DependentUpon>
</Compile>
<Compile Include="Preview\ModelPreview.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="Rendering\BoundingBox.vb" />
<Compile Include="Camera\CameraPoint.vb" />
<Compile Include="Rendering\ContentPipe.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Rendering\Renderer.vb" />
<Compile Include="Rendering\RenderMode.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Preview\ModelPreview.resx">
<DependentUpon>ModelPreview.vb</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.vbproj">
<Project>{ac955819-7910-450c-940c-7c1989483d4b}</Project>
<Name>Pilz.Simple3DFileParser</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>

View File

@@ -0,0 +1,42 @@
Namespace PreviewN
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class ModelPreview
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ModelPreview))
Me.SuspendLayout()
'
'ModelPreview
'
Me.ClientSize = New System.Drawing.Size(880, 538)
Me.DoubleBuffered = True
Me.Name = "ModelPreview"
Me.Text = "ModelPreview"
Me.ResumeLayout(False)
End Sub
End Class
End Namespace

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,341 @@
Imports System.Drawing
Imports System.Windows.Forms
Imports Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
Imports Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Imports Pilz.S3DFileParser
Imports Point = System.Drawing.Point
Namespace PreviewN
Public Class ModelPreview
Public Event WandUpdateView()
Private WithEvents glControl1 As GLControl
Private WithEvents MyCamera As New Camera
Private ProjMatrix As Matrix4 = Nothing
Private FOV As Single = 1.048F
Private camMtx As Matrix4 = Matrix4.Identity
Private savedCamPos As New Vector3
Private _isMouseDown As Boolean = False
Private myPressedKeys As New List(Of Keys)
Private isDeactivated As Boolean = False
Private ReadOnly myModels As New Dictionary(Of Object3D, Renderer)
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 ReadOnly Property PressedKeys As IReadOnlyList(Of Keys)
Get
Return myPressedKeys
End Get
End Property
Public ReadOnly Property Camera As Camera
Get
Return MyCamera
End Get
End Property
Public ReadOnly Property CameraMatrix As Matrix4
Get
Return camMtx
End Get
End Property
Public ReadOnly Property Models As IReadOnlyDictionary(Of Object3D, Renderer)
Get
Return myModels
End Get
End Property
Private ReadOnly Property IsStrgPressed As Boolean
Get
Return myPressedKeys.Contains(Keys.ControlKey)
End Get
End Property
Private ReadOnly Property IsShiftPressed As Boolean
Get
Return myPressedKeys.Contains(Keys.ShiftKey)
End Get
End Property
Public Property IsMouseDown As Boolean
Get
Return _isMouseDown
End Get
Set(value As Boolean)
_isMouseDown = value
glControl1.Refresh()
End Set
End Property
Public Sub New()
Me.New({}, 1.0F)
End Sub
Public Sub New(obj As Object3D)
Me.New(obj, 1.0F)
End Sub
Public Sub New(obj As Object3D, scale As Single)
Me.New({obj}, scale)
End Sub
Public Sub New(objs As Object3D(), scale As Single)
Me.SuspendLayout()
InitializeComponent()
DoubleBuffered = True
'glControl1
Me.glControl1 = New GLControl
Me.glControl1.BackColor = Color.Black
Me.glControl1.Location = New Point(0, 0)
Me.glControl1.MinimumSize = New Size(600, 120)
Me.glControl1.Name = "glControl1"
Me.glControl1.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Bottom
Me.glControl1.Location = New Point(0, 0)
Me.glControl1.Size = Me.ClientSize
Me.glControl1.TabIndex = 0
Me.glControl1.TabStop = False
Me.glControl1.VSync = False
Me.Controls.Add(Me.glControl1)
Me.ResumeLayout(False)
AddHandler Windows.Media.CompositionTarget.Rendering, AddressOf CompositionTarget_Rendering
Scaling = scale
'Toolkit.Init()
glControl1.CreateControl()
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)
Me.ResumeLayout()
For Each obj As Object3D In objs
AddModel(obj)
Next
End Sub
Public Sub UpdateOrbitCamera()
If Camera.IsOrbitCamera Then
Camera.UpdateOrbitCamera(camMtx)
End If
End Sub
Public Sub UpdateView()
glControl1.Invalidate()
'glControl1.Update()
End Sub
Public Function AddModel(obj As Object3D) As Renderer
Dim rndr As New Renderer(obj)
AddModel(rndr)
Return rndr
End Function
Public Sub AddModel(rndr As Renderer)
myModels.Add(rndr.Model, rndr)
End Sub
Public Sub HandlesOnShown(sender As Object, e As EventArgs) Handles MyBase.Shown
glControl1.Enabled = True
RenderModels()
glControl1.Invalidate()
End Sub
Public Sub RenderModels()
For Each rndr As Renderer In myModels.Values
RenderModel(rndr)
Next
End Sub
Public Sub RenderModel(rndr As Renderer)
If myModels.Values.Contains(rndr) Then
rndr.ModelScaling = Scaling
rndr.RenderModel()
End If
End Sub
Private Sub glControl1_Load(sender As Object, e As EventArgs) Handles glControl1.Load
GL.Enable(EnableCap.Blend)
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha)
GL.Enable(EnableCap.DepthTest)
GL.DepthFunc(DepthFunction.Lequal)
GL.Enable(EnableCap.Texture2D)
GL.Enable(EnableCap.AlphaTest)
GL.AlphaFunc(AlphaFunction.Gequal, 0.5F)
GL.Enable(EnableCap.CullFace)
End Sub
Public Sub HandlesOnActivated(sender As Object, e As EventArgs) Handles Me.Activated
If isDeactivated Then
isDeactivated = False
End If
End Sub
Public Sub HandlesOnDeactivate(sender As Object, e As EventArgs) Handles Me.Deactivate
isDeactivated = True
End Sub
Private Sub CompositionTarget_Rendering(sender As Object, e As EventArgs)
If Not isDeactivated OrElse RenderWhenWindowsIsInactive Then
RaiseEvent WandUpdateView()
glControl1.Invalidate()
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)
GL.MatrixMode(MatrixMode.Projection)
GL.LoadMatrix(ProjMatrix)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadMatrix(camMtx)
For Each rndr As Renderer In myModels.Values
If rndr.HasRendered Then
rndr.DrawModel(RenderMode.FillOutline)
End If
Next
glControl1.SwapBuffers()
'If Not IsMouseDown AndAlso obj3d IsNot Nothing Then
' e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
' e.Graphics.DrawString(GetModelInfoAsString, New Font(FontFamily.GenericSerif, 10), New SolidBrush(Panel1.ForeColor), New Drawing.Point(10, 10))
'End If
End Sub
Private Function GetModelInfoAsString() As String
Dim matsCount As Long = 0
Dim facesCount As Long = 0
Dim vertsCount As Long = 0
Dim vcCount As Long = 0
Dim uvCount As Long = 0
For Each obj3d As Object3D In myModels.Keys
matsCount += obj3d.Materials.Count
For Each m As Mesh In obj3d.Meshes
vertsCount += m.Vertices.Count
facesCount += m.Faces.Count
vcCount += m.VertexColors.Count
uvCount += m.UVs.Count
Next
Next
Return String.Format("Materials:{0}{1}
Faces:{0}{0}{2}
Vertices:{0}{3}
Vertex Colors{0}{4}
UVs:{0}{0}{5}",
vbTab, matsCount, facesCount, vertsCount, vcCount, uvCount)
End Function
Private Sub glControl1_Resize(sender As Object, e As EventArgs) Handles glControl1.Resize
glControl1.Context.Update(glControl1.WindowInfo)
GL.Viewport(0, 0, glControl1.Width, glControl1.Height)
ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControl1.Width / glControl1.Height, 100.0F, 100000.0F)
glControl1.Invalidate()
End Sub
Private Sub glControl1_Wheel(sender As Object, e As MouseEventArgs)
MyCamera.ResetMouseStuff()
MyCamera.UpdateCameraMatrixWithScrollWheel(CInt(Math.Truncate(e.Delta * (If(IsShiftPressed, 3.5F, 1.5F)))), camMtx)
savedCamPos = MyCamera.Position
glControl1.Invalidate()
End Sub
Private Sub glControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles glControl1.MouseDown
IsMouseDown = True
savedCamPos = MyCamera.Position
End Sub
Private Sub glControl1_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles glControl1.MouseLeave, glControl1.MouseUp
MyCamera.ResetMouseStuff()
IsMouseDown = False
End Sub
Private Sub glControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles glControl1.MouseMove
If IsMouseDown AndAlso e.Button = MouseButtons.Left Then
If IsShiftPressed Then
MyCamera.UpdateCameraOffsetWithMouse(savedCamPos, e.X, e.Y, glControl1.Width, glControl1.Height, camMtx)
Else
MyCamera.UpdateCameraMatrixWithMouse(e.X, e.Y, camMtx)
End If
glControl1.Invalidate()
End If
End Sub
Public Sub HandlesOnKeyDown(sender As Object, e As KeyEventArgs) Handles glControl1.KeyDown
If Not myPressedKeys.Contains(e.KeyCode) Then myPressedKeys.Add(e.KeyCode)
End Sub
Public Sub HandlesOnKeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
If myPressedKeys.Contains(e.KeyCode) Then myPressedKeys.Remove(e.KeyCode)
End Sub
Public Sub MoveCameraViaWASDQE()
Dim moveSpeed As Integer = Convert.ToInt32(Math.Round((If(IsShiftPressed, 60, 30)) * (MyCamera.CamSpeedMultiplier), 0))
Dim allowCamMove As Boolean = Not (IsMouseDown AndAlso IsShiftPressed)
For Each k As Keys In myPressedKeys
If allowCamMove Then
Select Case k
Case Keys.W
'camera.Move(moveSpeed, moveSpeed, camMtx)
MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, camMtx)
savedCamPos = MyCamera.Position
Case Keys.S
'camera.Move(-moveSpeed, -moveSpeed, camMtx)
MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, camMtx)
savedCamPos = MyCamera.Position
Case Keys.A
'camera.Move(-moveSpeed, 0, camMtx)
MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, camMtx)
Case Keys.D
'camera.Move(moveSpeed, 0, camMtx)
MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, camMtx)
Case Keys.E
'camera.Move(0, -moveSpeed, camMtx)
MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, camMtx)
Case Keys.Q
'camera.Move(0, moveSpeed, camMtx)
MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, camMtx)
End Select
End If
Next
End Sub
Private Sub Camera_NeedSelectedObject(e As Camera.NeedSelectedObjectEventArgs) Handles MyCamera.NeedSelectedObject
e.Points = Nothing
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()
Next
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,105 @@
Imports System.Drawing
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Namespace RenderingN
Public Class BoundingBox
Public Shared Sub DrawSolid(scale As System.Numerics.Vector3, rot As System.Numerics.Quaternion, pos As System.Numerics.Vector3, color As Color, upper As System.Numerics.Vector3, lower As System.Numerics.Vector3)
GL.Disable(EnableCap.Blend)
GL.Disable(EnableCap.Texture2D)
GL.Disable(EnableCap.AlphaTest)
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale.X, scale.Y, scale.Z)
GL.Begin(PrimitiveType.Quads)
GL.Color4(color)
GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-right of top face
GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-left of top face
GL.Vertex3(lower.X, upper.Y, upper.Z) ' Bottom-left of top face
GL.Vertex3(upper.X, upper.Y, upper.Z) ' Bottom-right of top face
GL.Vertex3(upper.X, lower.Y, lower.Z) ' Top-right of bottom face
GL.Vertex3(lower.X, lower.Y, lower.Z) ' Top-left of bottom face
GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-left of bottom face
GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-right of bottom face
GL.Vertex3(upper.X, upper.Y, upper.Z) ' Top-Right of front face
GL.Vertex3(lower.X, upper.Y, upper.Z) ' Top-left of front face
GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-left of front face
GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-right of front face
GL.Vertex3(upper.X, lower.Y, lower.Z) ' Bottom-Left of back face
GL.Vertex3(lower.X, lower.Y, lower.Z) ' Bottom-Right of back face
GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-Right of back face
GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-Left of back face
GL.Vertex3(lower.X, upper.Y, upper.Z) ' Top-Right of left face
GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-Left of left face
GL.Vertex3(lower.X, lower.Y, lower.Z) ' Bottom-Left of left face
GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-Right of left face
GL.Vertex3(upper.X, upper.Y, upper.Z) ' Top-Right of left face
GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-Left of left face
GL.Vertex3(upper.X, lower.Y, lower.Z) ' Bottom-Left of left face
GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-Right of left face
GL.Color4(Color.White)
GL.End()
GL.PopMatrix()
GL.Enable(EnableCap.Blend)
GL.Enable(EnableCap.Texture2D)
GL.Enable(EnableCap.AlphaTest)
End Sub
Public Shared Sub Draw(scale As Numerics.Vector3, rot As Numerics.Quaternion, pos As Numerics.Vector3, color As Color, upper As Numerics.Vector3, lower As Numerics.Vector3)
GL.Disable(EnableCap.Blend)
GL.Disable(EnableCap.Texture2D)
GL.Disable(EnableCap.AlphaTest)
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale.X, scale.Y, scale.Z)
GL.Begin(PrimitiveType.LineLoop)
GL.Color4(color)
GL.Vertex3(upper.X, upper.Y, lower.Z) ' 1
GL.Vertex3(lower.X, upper.Y, lower.Z) ' 2
GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3
GL.Vertex3(upper.X, upper.Y, lower.Z) ' 1
GL.Vertex3(upper.X, upper.Y, upper.Z) ' 4
GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3
GL.Vertex3(lower.X, lower.Y, upper.Z) ' 7
GL.Vertex3(lower.X, lower.Y, lower.Z) ' 6
GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5
GL.Vertex3(lower.X, lower.Y, upper.Z) ' 7
GL.Vertex3(upper.X, lower.Y, upper.Z) ' 8
GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5
GL.Vertex3(lower.X, upper.Y, lower.Z) ' 2
GL.Vertex3(lower.X, lower.Y, lower.Z) ' 6
GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3
GL.Vertex3(upper.X, lower.Y, upper.Z) ' 8
GL.Vertex3(upper.X, upper.Y, upper.Z) ' 4
GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5
GL.Color4(Color.White)
GL.End()
GL.PopMatrix()
GL.Enable(EnableCap.Blend)
GL.Enable(EnableCap.Texture2D)
GL.Enable(EnableCap.AlphaTest)
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,33 @@
Imports System
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Imports System.Drawing
Imports System.Drawing.Imaging
Namespace RenderingN
Public Class ContentPipe
Public Shared Function LoadTexture(filepath As String) As Integer
Dim bitmap As New Bitmap(filepath)
Return LoadTexture(bitmap)
End Function
Public Shared Function LoadTexture(bitmap As Bitmap) As Integer
Dim id As Integer = GL.GenTexture()
LoadTexture(bitmap, id)
Return id
End Function
Public Shared Sub LoadTexture(bitmap As Bitmap, id As Integer)
Dim bmpData As BitmapData = bitmap.LockBits(New Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppArgb)
GL.BindTexture(TextureTarget.Texture2D, id)
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0)
bitmap.UnlockBits(bmpData)
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, CInt(Math.Truncate(TextureMinFilter.Linear)))
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, CInt(Math.Truncate(TextureMagFilter.Linear)))
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,10 @@
Namespace RenderingN
Public Enum RenderMode As Byte
None = &H0
Fill = &H1
Outline = &H2
FillOutline = Fill Or Outline
End Enum
End Namespace

View File

@@ -0,0 +1,456 @@
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Imports OpenTK
Imports OpenTK.Graphics.OpenGL
Imports Pilz.S3DFileParser
Namespace RenderingN
Public Class Renderer
Private obj3d As Object3D
Private dicTextureIDs As New Dictionary(Of Image, Integer)
Private dicColorIDs As New Dictionary(Of Color, Integer)
Private emptyTexture As Bitmap = Nothing
Private lineTexture As Bitmap = Nothing
Private selectedLineTexture As Bitmap = Nothing
Public Property ModelScaling As Single = 1.0F
Public ReadOnly Property HasRendered As Boolean = False
Public ReadOnly Property SelectedElements As List(Of Object)
Private ReadOnly Property VertexBuffers As New Dictionary(Of Mesh, Integer)
Private ReadOnly Property IndicesBuffers As New Dictionary(Of Mesh, List(Of Integer))
Private ReadOnly Property UVBuffers As New Dictionary(Of Mesh, Integer)
Private ReadOnly Property VertexColorBuffers As New Dictionary(Of Mesh, Integer)
Private ReadOnly Property NormalBuffers As New Dictionary(Of Mesh, Integer)
Public ReadOnly Property Model As Object3D
Get
Return obj3d
End Get
End Property
Public Sub New(obj3d As Object3D)
Me.obj3d = obj3d.ToOneMesh
'Set Texture used for faces without texture
emptyTexture = ColorToTexture(Color.LightGray)
'Set Texture used for lines
lineTexture = ColorToTexture(Color.Black)
'Set Texture used for lines of selected faces
selectedLineTexture = ColorToTexture(Color.Orange)
End Sub
Private Function ColorToTexture(color As Color) As Image
Dim tex As New Bitmap(1, 1)
tex.SetPixel(0, 0, color)
Return tex
End Function
''' <summary>
''' Updates the Data of a Vertex in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="v">The Vertex to update.</param>
Public Sub UpdateVertexData(m As Mesh, v As Vertex)
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.Vertices.IndexOf(v) * Vector3.SizeInBytes, IntPtr), Vector3.SizeInBytes, New Vector3(v.X, v.Y, v.Z))
End Sub
''' <summary>
''' Updates the Data of a Normal in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="n">The Normal to update.</param>
Public Sub UpdateNormalData(m As Mesh, n As Normal)
GL.BindBuffer(BufferTarget.ArrayBuffer, NormalBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.Normals.IndexOf(n) * Vector3.SizeInBytes, IntPtr), Vector3.SizeInBytes, New Vector3(n.X, n.Y, n.Z))
End Sub
''' <summary>
''' Updates the Data of a Vertex Color in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="vc">The Vertex Color to update.</param>
Public Sub UpdateVertexColorData(m As Mesh, vc As VertexColor)
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColorBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.VertexColors.IndexOf(vc) * Vector4.SizeInBytes, IntPtr), Vector4.SizeInBytes, New Vector4(vc.R, vc.G, vc.B, vc.A))
End Sub
''' <summary>
''' Updates the Data of a UV in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="uv">The UV to update.</param>
Public Sub UpdateUVData(m As Mesh, uv As UV)
GL.BindBuffer(BufferTarget.ArrayBuffer, UVBuffers(m))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.UVs.IndexOf(uv) * Vector2.SizeInBytes, IntPtr), Vector2.SizeInBytes, New Vector2(uv.U, uv.V))
End Sub
''' <summary>
''' Updates the indicies of a face in the buffer.
''' </summary>
''' <param name="m">The Mesh where the Vertex is listed.</param>
''' <param name="f">The Face to update.</param>
Public Sub UpdateFaceIndicies(m As Mesh, f As Face)
Dim faceIndex As Integer = m.Faces.IndexOf(f)
Dim uintlen As Byte = Len(New UInteger)
Dim indicies As New Vector3(m.Vertices.IndexOf(f.Points(0).Vertex),
m.Vertices.IndexOf(f.Points(1).Vertex),
m.Vertices.IndexOf(f.Points(2).Vertex))
GL.BindBuffer(BufferTarget.ArrayBuffer, IndicesBuffers(m)(faceIndex))
GL.BufferSubData(BufferTarget.ArrayBuffer, CType(uintlen * faceIndex, IntPtr), uintlen, indicies)
End Sub
''' <summary>
''' Replace an Image with a new one.
''' </summary>
''' <param name="oldImage"></param>
''' <param name="newImage"></param>
Public Sub UpdateTexture(oldImage As Image, newImage As Image)
If dicTextureIDs.ContainsKey(oldImage) Then
Dim id As Integer = dicTextureIDs(oldImage)
dicTextureIDs.Remove(oldImage)
dicTextureIDs.Add(newImage, id)
ContentPipe.LoadTexture(newImage, id)
End If
End Sub
''' <summary>
''' Updates an Image.
''' </summary>
''' <param name="image"></param>
Public Sub UpdateTexture(image As Image)
If dicTextureIDs.ContainsKey(image) Then
ContentPipe.LoadTexture(dicTextureIDs(image))
End If
End Sub
''' <summary>
''' Creates the Buffers and store the requied Data.
''' </summary>
Public Sub RenderModel()
ReleaseBuffers()
For Each mesh As Mesh In obj3d.Meshes
Dim nibo As New List(Of Integer)
Dim enablecols As Boolean = mesh.VertexColors.Count > 0
Dim enablenorms As Boolean = (Not enablecols) AndAlso mesh.Normals.Count > 0
Dim verts As New List(Of Vector3)
Dim uvs As New List(Of Vector2)
Dim cols As New List(Of Vector4)
Dim norms As New List(Of Vector3)
Dim curvi As ULong = 0
IndicesBuffers.Add(mesh, nibo)
For i As Integer = 0 To mesh.Faces.Count - 1
With mesh.Faces(i)
Dim indices As New List(Of UInteger)
For Each p As S3DFileParser.Point In .Points
indices.Add(curvi)
curvi += 1
If verts IsNot Nothing Then
verts.Add(New Vector3(p.Vertex.X, p.Vertex.Y, p.Vertex.Z))
Else
verts.Add(New Vector3(0, 0, 0))
End If
If p.UV IsNot Nothing Then
uvs.Add(New Vector2(p.UV.U, p.UV.V))
Else
uvs.Add(New Vector2(0, 0))
End If
If enablecols AndAlso p.VertexColor IsNot Nothing Then
cols.Add(New Vector4(p.VertexColor.R, p.VertexColor.G, p.VertexColor.B, p.VertexColor.A))
Else
cols.Add(New Vector4(1, 1, 1, 1))
End If
If enablenorms AndAlso p.Normal IsNot Nothing Then
norms.Add(New Vector3(p.Normal.X, p.Normal.Y, p.Normal.Z))
Else
norms.Add(New Vector3(1, 1, 1))
End If
Next
nibo.Add(GL.GenBuffer)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, nibo(i))
GL.BufferData(
BufferTarget.ElementArrayBuffer,
CType(Len(New UInteger) * indices.Count, IntPtr),
indices.ToArray,
BufferUsageHint.StaticDraw)
If .Material?.Image IsNot Nothing Then
If Not dicTextureIDs.ContainsKey(.Material.Image) Then
dicTextureIDs.Add(.Material.Image, ContentPipe.LoadTexture(.Material.Image))
End If
ElseIf .Material?.Color IsNot Nothing Then
If Not dicColorIDs.ContainsKey(.Material.Color) Then
dicColorIDs.Add(.Material.Color, ContentPipe.LoadTexture(ColorToTexture(.Material.Color)))
End If
Else
If Not dicTextureIDs.ContainsKey(emptyTexture) Then
dicTextureIDs.Add(emptyTexture, ContentPipe.LoadTexture(emptyTexture))
End If
End If
End With
Next
Dim nvbo As Integer = GL.GenBuffer
VertexBuffers.Add(mesh, nvbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, nvbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector3.SizeInBytes * verts.Count, IntPtr),
verts.ToArray,
BufferUsageHint.StaticDraw
)
Dim ntbo As Integer = GL.GenBuffer
UVBuffers.Add(mesh, ntbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, ntbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector2.SizeInBytes * uvs.Count, IntPtr),
uvs.ToArray,
BufferUsageHint.StaticDraw
)
If enablecols Then
Dim ncbo As Integer = GL.GenBuffer
VertexColorBuffers.Add(mesh, ncbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, ncbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector4.SizeInBytes * cols.Count, IntPtr),
cols.ToArray,
BufferUsageHint.StaticDraw
)
End If
If enablenorms Then
Dim nnbo As Integer = GL.GenBuffer
NormalBuffers.Add(mesh, nnbo)
GL.BindBuffer(BufferTarget.ArrayBuffer, nnbo)
GL.BufferData(
BufferTarget.ArrayBuffer,
CType(Vector3.SizeInBytes * norms.Count, IntPtr),
norms.ToArray,
BufferUsageHint.StaticDraw
)
End If
Next
If Not dicTextureIDs.ContainsKey(lineTexture) Then
dicTextureIDs.Add(lineTexture, ContentPipe.LoadTexture(lineTexture))
End If
_HasRendered = True
End Sub
Public Sub DrawModel(mode As RenderMode)
DrawModel(mode, Vector3.Zero, Quaternion.Identity, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion)
DrawModel(mode, pos, rot, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion, scale As Vector3)
If mode = RenderMode.None Then Return
If Not _HasRendered Then Return
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale) 'GL.Scale(scale.X, scale.Y, scale.Z)
GL.EnableClientState(ArrayCap.VertexArray)
GL.EnableClientState(ArrayCap.TextureCoordArray)
For Each mesh As Mesh In obj3d.Meshes
If VertexColorBuffers.ContainsKey(mesh) Then
GL.EnableClientState(ArrayCap.ColorArray)
ElseIf NormalBuffers.ContainsKey(mesh) Then
GL.EnableClientState(ArrayCap.NormalArray)
End If
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(mesh))
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero)
GL.BindBuffer(BufferTarget.ArrayBuffer, UVBuffers(mesh))
GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero)
If VertexColorBuffers.ContainsKey(mesh) Then
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColorBuffers(mesh))
GL.ColorPointer(4, ColorPointerType.Float, 0, IntPtr.Zero)
ElseIf NormalBuffers.ContainsKey(mesh) Then
GL.BindBuffer(BufferTarget.ArrayBuffer, NormalBuffers(mesh))
GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero)
End If
For i As Integer = 0 To mesh.Faces.Count - 1
Dim l As Face = mesh.Faces(i)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesBuffers(mesh)(i))
Dim texID As Integer
Dim isEmptyTexture As Boolean = l.Material?.Image Is Nothing
Dim isEmptyColor As Boolean = l.Material?.Color Is Nothing
If (mode And RenderMode.Fill) = RenderMode.Fill Then
texID = If(isEmptyTexture, If(isEmptyColor, dicTextureIDs(emptyTexture), dicColorIDs(l.Material.Color)), dicTextureIDs(l.Material.Image))
GL.BindTexture(TextureTarget.Texture2D, texID)
If Not isEmptyTexture Then
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, l.Material.Wrap.X)
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, l.Material.Wrap.Y)
End If
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill)
GL.DrawElements(PrimitiveType.Triangles, l.Points.Count,
DrawElementsType.UnsignedInt, IntPtr.Zero)
End If
If (mode And RenderMode.Outline) = RenderMode.Outline Then
If (mode And RenderMode.Fill) = RenderMode.Fill Then
texID = dicTextureIDs(lineTexture)
GL.BindTexture(TextureTarget.Texture2D, texID)
Else
texID = If(isEmptyTexture, If(isEmptyColor, dicTextureIDs(emptyTexture), dicColorIDs(l.Material.Color)), dicTextureIDs(l.Material.Image))
GL.BindTexture(TextureTarget.Texture2D, texID)
If Not isEmptyTexture Then
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, l.Material.Wrap.X)
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, l.Material.Wrap.Y)
End If
End If
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line)
GL.DrawElements(PrimitiveType.Triangles, l.Points.Count,
DrawElementsType.UnsignedInt, IntPtr.Zero)
End If
Next
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill) 'Reset for RenderEngineOld
If VertexColorBuffers.ContainsKey(mesh) Then
GL.DisableClientState(ArrayCap.ColorArray)
ElseIf NormalBuffers.ContainsKey(mesh) Then
GL.DisableClientState(ArrayCap.NormalArray)
End If
Next
GL.DisableClientState(ArrayCap.VertexArray)
GL.DisableClientState(ArrayCap.TextureCoordArray)
GL.PopMatrix()
End Sub
Public Sub DrawFacePicking()
DrawFacePicking(Vector3.Zero, Quaternion.Identity, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawFacePicking(pos As Vector3, rot As Quaternion)
DrawFacePicking(pos, rot, New Vector3(ModelScaling, ModelScaling, ModelScaling))
End Sub
Public Sub DrawFacePicking(pos As Vector3, rot As Quaternion, scale As Vector3)
If Not _HasRendered Then Return
GL.PushMatrix()
GL.Translate(pos.X, pos.Y, pos.Z)
GL.Rotate(rot.X, 1, 0, 0)
GL.Rotate(rot.Y, 0, 1, 0)
GL.Rotate(rot.Z, 0, 0, 1)
GL.Scale(scale)
GL.EnableClientState(ArrayCap.VertexArray)
For iMesh As Integer = 0 To obj3d.Meshes.Count - 1
Dim mesh As Mesh = obj3d.Meshes(iMesh)
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(mesh))
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero)
For iFace As Integer = 0 To mesh.Faces.Count - 1
Dim l As Face = mesh.Faces(iFace)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesBuffers(mesh)(iFace))
GL.Color4(Color.FromArgb(&H20000000 + (iMesh << 16) + iFace)) 'Color: "2f ff xx xx" -> where 'f' = mesh index and where 'x' is face index
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill)
GL.DrawElements(PrimitiveType.Triangles, l.Points.Count,
DrawElementsType.UnsignedInt, IntPtr.Zero)
Next
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill)
Next
GL.DisableClientState(ArrayCap.VertexArray)
GL.PopMatrix()
End Sub
Public Sub ReleaseBuffers()
If Not HasRendered Then Return
For Each kvp As KeyValuePair(Of Mesh, Integer) In VertexBuffers
GL.DeleteBuffer(kvp.Value)
Next
VertexBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, Integer) In UVBuffers
GL.DeleteBuffer(kvp.Value)
Next
UVBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, Integer) In VertexColorBuffers
GL.DeleteBuffer(kvp.Value)
Next
VertexColorBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, Integer) In NormalBuffers
GL.DeleteBuffer(kvp.Value)
Next
NormalBuffers.Clear()
For Each kvp As KeyValuePair(Of Mesh, List(Of Integer)) In IndicesBuffers
For Each i As Integer In kvp.Value
GL.DeleteBuffer(i)
Next
kvp.Value.Clear()
Next
IndicesBuffers.Clear()
For Each kvp As KeyValuePair(Of Image, Integer) In dicTextureIDs
GL.DeleteBuffer(kvp.Value)
Next
dicTextureIDs.Clear()
For Each kvp As KeyValuePair(Of Color, Integer) In dicColorIDs
GL.DeleteBuffer(kvp.Value)
Next
dicColorIDs.Clear()
_HasRendered = False
End Sub
Protected Overrides Sub Finalize()
'ReleaseBuffers()
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="OpenTK" publicKeyToken="bad199fe84eb3df4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="OpenTK" version="3.0.1" targetFramework="net45" />
<package id="OpenTK.GLControl" version="3.0.1" targetFramework="net45" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net45" />
</packages>