Inital Commit.
This commit is contained in:
commit
bd762e9659
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
189
.gitignore
vendored
Normal file
189
.gitignore
vendored
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
x64/
|
||||||
|
build/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
|
||||||
|
# Roslyn cache directories
|
||||||
|
*.ide/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
#NUNIT
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_i.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# JustCode is a .NET coding addin-in
|
||||||
|
.JustCode
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
## TODO: Comment the next line if you want to checkin your
|
||||||
|
## web deploy settings but do note that will include unencrypted
|
||||||
|
## passwords
|
||||||
|
#*.pubxml
|
||||||
|
|
||||||
|
# NuGet Packages Directory
|
||||||
|
packages/*
|
||||||
|
## TODO: If the tool you use requires repositories.config
|
||||||
|
## uncomment the next line
|
||||||
|
#!packages/repositories.config
|
||||||
|
|
||||||
|
# Enable "build/" folder in the NuGet Packages folder since
|
||||||
|
# NuGet packages use it for MSBuild targets.
|
||||||
|
# This line needs to be after the ignore of the build folder
|
||||||
|
# (and the packages folder if the line above has been uncommented)
|
||||||
|
!packages/build/
|
||||||
|
|
||||||
|
# Windows Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Windows Store app package directory
|
||||||
|
AppPackages/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
sql/
|
||||||
|
*.Cache
|
||||||
|
ClientBin/
|
||||||
|
[Ss]tyle[Cc]op.*
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# LightSwitch generated files
|
||||||
|
GeneratedArtifacts/
|
||||||
|
_Pvt_Extensions/
|
||||||
|
ModelManifest.xml
|
343
3DGDIRender/3D.vb
Normal file
343
3DGDIRender/3D.vb
Normal file
@ -0,0 +1,343 @@
|
|||||||
|
Imports System.Drawing
|
||||||
|
|
||||||
|
Public Class Point3D
|
||||||
|
Implements ICoordinate3D
|
||||||
|
Protected _x As Single
|
||||||
|
Protected _y As Single
|
||||||
|
Protected _z As Single
|
||||||
|
Public Sub New(x As Single, y As Single, z As Single)
|
||||||
|
_x = x
|
||||||
|
_y = y
|
||||||
|
_z = z
|
||||||
|
End Sub
|
||||||
|
Public Property X() As Single Implements IPositionable.X
|
||||||
|
Get
|
||||||
|
Return _x
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
_x = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Property Y() As Single Implements IPositionable.Y
|
||||||
|
Get
|
||||||
|
Return _y
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
_y = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Property Z() As Single Implements IPositionable.Z
|
||||||
|
Get
|
||||||
|
Return _z
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
_z = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Sub RotateX(angle As Single) Implements IRotatable.RotateX
|
||||||
|
Dim rad As Single = angle * Math.PI / 180
|
||||||
|
Dim cosa As Single = Math.Cos(rad)
|
||||||
|
Dim sina As Single = Math.Sin(rad)
|
||||||
|
Dim yn As Single = _y * cosa - _z * sina
|
||||||
|
Dim zn As Single = _y * sina + _z * cosa
|
||||||
|
_y = yn
|
||||||
|
_z = zn
|
||||||
|
'Return New Point3D(_x, yn, zn)
|
||||||
|
End Sub
|
||||||
|
Public Sub RotateY(angle As Single) Implements IRotatable.RotateY
|
||||||
|
Dim rad As Single = angle * Math.PI / 180
|
||||||
|
Dim cosa As Single = Math.Cos(rad)
|
||||||
|
Dim sina As Single = Math.Sin(rad)
|
||||||
|
Dim Xn As Single = _z * cosa - _x * sina
|
||||||
|
Dim Zn As Single = _z * sina + _x * cosa
|
||||||
|
_x = Xn
|
||||||
|
_z = Zn
|
||||||
|
'Return New Point3D(Xn, _y, Zn)
|
||||||
|
End Sub
|
||||||
|
Public Sub RotateZ(angle As Single) Implements IRotatable.RotateZ
|
||||||
|
Dim rad As Single = angle * Math.PI / 180
|
||||||
|
Dim cosa As Single = Math.Cos(rad)
|
||||||
|
Dim sina As Single = Math.Sin(rad)
|
||||||
|
Dim Xn As Single = _x * cosa - _y * sina
|
||||||
|
Dim Yn As Single = _x * sina + _y * cosa
|
||||||
|
_x = Xn
|
||||||
|
_y = Yn
|
||||||
|
'Return New Point3D(Xn, Yn, _z)
|
||||||
|
End Sub
|
||||||
|
Public Sub Scale(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) Implements ICoordinate3D.scalePoint
|
||||||
|
Dim factor As Single = fov / (viewDistance + _z)
|
||||||
|
Dim Xn As Single = _x * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = _y * factor + viewHeight / 2
|
||||||
|
_x = Xn
|
||||||
|
_y = Yn
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function returnPoint() As Point3D Implements ICoordinate3D.returnPoint
|
||||||
|
Return Me
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function returnScaledPoint(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) As Point3D Implements ICoordinate3D.returnScaledPoint
|
||||||
|
Dim factor As Single = fov / (viewDistance + _z)
|
||||||
|
Dim Xn As Single = _x * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = _y * factor + viewHeight / 2
|
||||||
|
Return New Point3D(Xn, Yn, _z)
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
|
Public Class Polygon3D
|
||||||
|
Implements ICoordinates3D
|
||||||
|
|
||||||
|
Protected pos As Point3D
|
||||||
|
Protected _points As PointF()
|
||||||
|
Public Sub New(position As Point3D, ParamArray points As PointF())
|
||||||
|
pos = position
|
||||||
|
_points = points
|
||||||
|
End Sub
|
||||||
|
Public Property X() As Single Implements IPositionable.X
|
||||||
|
Get
|
||||||
|
Return pos.X
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
pos.X = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Property Y() As Single Implements IPositionable.Y
|
||||||
|
Get
|
||||||
|
Return pos.Y
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
pos.Y = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Property Z() As Single Implements IPositionable.Z
|
||||||
|
Get
|
||||||
|
Return pos.Z
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
pos.Z = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Sub RotateX(angle As Single) Implements IRotatable.RotateX
|
||||||
|
pos.RotateX(angle)
|
||||||
|
'Return New Polygon3D(pos, _points)
|
||||||
|
End Sub
|
||||||
|
Public Sub RotateY(angle As Single) Implements IRotatable.RotateY
|
||||||
|
pos.RotateY(angle)
|
||||||
|
'Return New Polygon3D(pos, _points)
|
||||||
|
End Sub
|
||||||
|
Public Sub RotateZ(angle As Single) Implements IRotatable.RotateZ
|
||||||
|
pos.RotateZ(angle)
|
||||||
|
Dim ps(_points.Length - 1) As PointF
|
||||||
|
For i As Integer = 0 To _points.Length - 1 Step 1
|
||||||
|
'ps(i) = _points(i)
|
||||||
|
Dim rad As Single = angle * Math.PI / 180
|
||||||
|
Dim cosa As Single = Math.Cos(rad)
|
||||||
|
Dim sina As Single = Math.Sin(rad)
|
||||||
|
Dim Xn As Single = _points(i).X * cosa - _points(i).Y * sina
|
||||||
|
Dim Yn As Single = _points(i).X * sina + _points(i).Y * cosa
|
||||||
|
ps(i) = New PointF(Xn, Yn)
|
||||||
|
Next
|
||||||
|
_points = ps
|
||||||
|
'Return New Polygon3D(pos, ps)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function returnPoint() As Point3D Implements ICoordinate3D.returnPoint
|
||||||
|
Return pos
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function returnPoints() As Point3D() Implements ICoordinates3D.returnPoints
|
||||||
|
Dim pnts(_points.Length - 1) As Point3D
|
||||||
|
For i1 = 0 To _points.Length - 1
|
||||||
|
Dim p As PointF = _points(i1)
|
||||||
|
pnts(i1) = New Point3D(p.X + pos.X, p.Y + pos.Y, 0 + pos.Z)
|
||||||
|
Next
|
||||||
|
Return pnts
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Sub scalePoint(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) Implements ICoordinate3D.scalePoint
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = pos.X * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = pos.Y * factor + viewHeight / 2
|
||||||
|
pos.X = Xn
|
||||||
|
pos.Y = Yn
|
||||||
|
'Return New Point3D(Xn, Yn, 0 + pos.Z)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function returnScaledPoint(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) As Point3D Implements ICoordinate3D.returnScaledPoint
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = pos.X * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = pos.Y * factor + viewHeight / 2
|
||||||
|
Return New Point3D(Xn, Yn, 0 + pos.Z)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Sub scalePoints(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) Implements ICoordinates3D.scalePoints
|
||||||
|
Dim pnts(_points.Length - 1) As PointF
|
||||||
|
For i1 = 0 To _points.Length - 1
|
||||||
|
Dim p As PointF = _points(i1)
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = (p.X + pos.X) * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = (p.Y + pos.Y) * factor + viewHeight / 2
|
||||||
|
pnts(i1) = New PointF(Xn, Yn)
|
||||||
|
Next
|
||||||
|
_points = pnts
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function returnScaledPoints(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) As Point3D() Implements ICoordinates3D.returnScaledPoints
|
||||||
|
Dim pnts(_points.Length - 1) As Point3D
|
||||||
|
For i1 = 0 To _points.Length - 1
|
||||||
|
Dim p As PointF = _points(i1)
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = (p.X + pos.X) * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = (p.Y + pos.Y) * factor + viewHeight / 2
|
||||||
|
pnts(i1) = New Point3D(Xn, Yn, 0 + pos.Z)
|
||||||
|
Next
|
||||||
|
Return pnts
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
|
Public Class Mesh3D
|
||||||
|
Implements ICoordinates3D
|
||||||
|
|
||||||
|
Protected pos As Point3D
|
||||||
|
Protected _points As Point3D()
|
||||||
|
Public Sub New(position As Point3D, ParamArray points As Point3D())
|
||||||
|
pos = position
|
||||||
|
_points = points
|
||||||
|
End Sub
|
||||||
|
Public Sub New(polygon As Polygon3D)
|
||||||
|
pos = polygon.returnPoint()
|
||||||
|
_points = polygon.returnPoints()
|
||||||
|
For i As Integer = 0 To _points.Length - 1
|
||||||
|
Dim p As New Point3D(_points(i).X - pos.X, _points(i).Y - pos.Y, _points(i).Z - pos.Z)
|
||||||
|
_points(i) = p
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
Public Property X() As Single Implements IPositionable.X
|
||||||
|
Get
|
||||||
|
Return pos.X
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
pos.X = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Property Y() As Single Implements IPositionable.Y
|
||||||
|
Get
|
||||||
|
Return pos.Y
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
pos.Y = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Property Z() As Single Implements IPositionable.Z
|
||||||
|
Get
|
||||||
|
Return pos.Z
|
||||||
|
End Get
|
||||||
|
Set(value As Single)
|
||||||
|
pos.Z = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Sub RotateX(angle As Single) Implements IRotatable.RotateX
|
||||||
|
pos.RotateX(angle)
|
||||||
|
For i As Integer = 0 To _points.Length - 1 Step 1
|
||||||
|
_points(i).RotateX(angle)
|
||||||
|
Next
|
||||||
|
'Return New Mesh3D(pos, ps)
|
||||||
|
End Sub
|
||||||
|
Public Sub RotateY(angle As Single) Implements IRotatable.RotateY
|
||||||
|
pos.RotateY(angle)
|
||||||
|
Dim ps(_points.Length - 1) As Point3D
|
||||||
|
For i As Integer = 0 To _points.Length - 1 Step 1
|
||||||
|
_points(i).RotateY(angle)
|
||||||
|
Next
|
||||||
|
'Return New Mesh3D(pos, ps)
|
||||||
|
End Sub
|
||||||
|
Public Sub RotateZ(angle As Single) Implements IRotatable.RotateZ
|
||||||
|
pos.RotateZ(angle)
|
||||||
|
Dim ps(_points.Length - 1) As Point3D
|
||||||
|
For i As Integer = 0 To _points.Length - 1 Step 1
|
||||||
|
_points(i).RotateZ(angle)
|
||||||
|
Next
|
||||||
|
'Return New Mesh3D(pos, ps)
|
||||||
|
End Sub
|
||||||
|
Public Function returnPolygons(facesArray As Integer()()) As Polygon3D()
|
||||||
|
Dim pg As New List(Of Polygon3D)
|
||||||
|
For i As Integer = 0 To facesArray.Length - 1
|
||||||
|
'For Each face As Integer() In facesArray
|
||||||
|
Dim face As Integer() = facesArray(i)
|
||||||
|
Dim pnts As New List(Of PointF)
|
||||||
|
For j As Integer = 0 To face.Length - 1
|
||||||
|
Dim indx As Integer = face(j)
|
||||||
|
pnts.Add(New PointF(_points(indx).X, _points(indx).Y))
|
||||||
|
Next
|
||||||
|
If face.Count > 0 Then _
|
||||||
|
pg.Add(New Polygon3D(pos, pnts.ToArray))
|
||||||
|
Next
|
||||||
|
Return pg.ToArray
|
||||||
|
End Function
|
||||||
|
Public Function returnFlatMeshes(facesArray As Integer()()) As Mesh3D()
|
||||||
|
Dim pg As New List(Of Mesh3D)
|
||||||
|
For i As Integer = 0 To facesArray.Length - 1
|
||||||
|
'For Each face As Integer() In facesArray
|
||||||
|
Dim face As Integer() = facesArray(i)
|
||||||
|
Dim pnts As New List(Of Point3D)
|
||||||
|
For j As Integer = 0 To face.Length - 1
|
||||||
|
Dim indx As Integer = face(j)
|
||||||
|
pnts.Add(_points(indx))
|
||||||
|
Next
|
||||||
|
If face.Count > 0 Then _
|
||||||
|
pg.Add(New Mesh3D(pos, pnts.ToArray))
|
||||||
|
Next
|
||||||
|
Return pg.ToArray
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function returnPoint() As Point3D Implements ICoordinate3D.returnPoint
|
||||||
|
Return pos
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function returnPoints() As Point3D() Implements ICoordinates3D.returnPoints
|
||||||
|
Dim pnts(_points.Length - 1) As Point3D
|
||||||
|
For i1 = 0 To _points.Length - 1
|
||||||
|
Dim p As Point3D = _points(i1)
|
||||||
|
pnts(i1) = New Point3D(p.X + pos.X, p.Y + pos.Y, p.Z + pos.Z)
|
||||||
|
Next
|
||||||
|
Return pnts
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Sub scalePoint(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) Implements ICoordinate3D.scalePoint
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = pos.X * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = pos.Y * factor + viewHeight / 2
|
||||||
|
pos.X = Xn
|
||||||
|
pos.Y = Yn
|
||||||
|
'Return New Point3D(Xn, Yn, 0 + pos.Z)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function returnScaledPoint(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) As Point3D Implements ICoordinate3D.returnScaledPoint
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = pos.X * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = pos.Y * factor + viewHeight / 2
|
||||||
|
Return New Point3D(Xn, Yn, 0 + pos.Z)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Sub scalePoints(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) Implements ICoordinates3D.scalePoints
|
||||||
|
Dim pnts(_points.Length - 1) As Point3D
|
||||||
|
For i1 = 0 To _points.Length - 1
|
||||||
|
Dim p As Point3D = _points(i1)
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = (p.X + pos.X) * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = (p.Y + pos.Y) * factor + viewHeight / 2
|
||||||
|
pnts(i1) = New Point3D(Xn, Yn, p.Z + pos.Z)
|
||||||
|
Next
|
||||||
|
_points = pnts
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function returnScaledPoints(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) As Point3D() Implements ICoordinates3D.returnScaledPoints
|
||||||
|
Dim pnts(_points.Length - 1) As Point3D
|
||||||
|
For i1 = 0 To _points.Length - 1
|
||||||
|
Dim p As Point3D = _points(i1)
|
||||||
|
Dim factor As Single = fov / (viewDistance + pos.Z)
|
||||||
|
Dim Xn As Single = (p.X + pos.X) * factor + viewWidth / 2
|
||||||
|
Dim Yn As Single = (p.Y + pos.Y) * factor + viewHeight / 2
|
||||||
|
pnts(i1) = New Point3D(Xn, Yn, p.Z + pos.Z)
|
||||||
|
Next
|
||||||
|
Return pnts
|
||||||
|
End Function
|
||||||
|
End Class
|
79
3DGDIRender/3DGDIRender.vbproj
Normal file
79
3DGDIRender/3DGDIRender.vbproj
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{57106980-D2A0-4B53-843E-84DBFA89EDA3}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<RootNamespace>captainalm.util.Render3D</RootNamespace>
|
||||||
|
<AssemblyName>3DGDIRender</AssemblyName>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<MyType>Windows</MyType>
|
||||||
|
<TargetFrameworkVersion>v4.0</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>3DGDIRender.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>3DGDIRender.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="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
</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="3D.vb" />
|
||||||
|
<Compile Include="3DInterfaces.vb" />
|
||||||
|
<Compile Include="3DViewports.vb" />
|
||||||
|
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
31
3DGDIRender/3DInterfaces.vb
Normal file
31
3DGDIRender/3DInterfaces.vb
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
'
|
||||||
|
' Created by SharpDevelop.
|
||||||
|
' User: 14manvilleA
|
||||||
|
' Date: 27/09/2019
|
||||||
|
' Time: 10:16
|
||||||
|
'
|
||||||
|
' To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||||
|
'
|
||||||
|
|
||||||
|
Public Interface ICoordinate3D
|
||||||
|
Inherits IRotatable, IPositionable
|
||||||
|
Sub scalePoint(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single)
|
||||||
|
Function returnPoint() As Point3D
|
||||||
|
Function returnScaledPoint(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) As Point3D
|
||||||
|
End Interface
|
||||||
|
Public Interface ICoordinates3D
|
||||||
|
Inherits ICoordinate3D
|
||||||
|
Sub scalePoints(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single)
|
||||||
|
Function returnPoints() As Point3D()
|
||||||
|
Function returnScaledPoints(viewWidth As Single, viewHeight As Single, fov As Single, viewDistance As Single) As Point3D()
|
||||||
|
End Interface
|
||||||
|
Public Interface IPositionable
|
||||||
|
Property X As Single
|
||||||
|
Property Y As Single
|
||||||
|
Property Z As Single
|
||||||
|
End Interface
|
||||||
|
Public Interface IRotatable
|
||||||
|
Sub RotateX(angle As Single)
|
||||||
|
Sub RotateY(angle As Single)
|
||||||
|
Sub RotateZ(angle As Single)
|
||||||
|
End Interface
|
188
3DGDIRender/3DViewports.vb
Normal file
188
3DGDIRender/3DViewports.vb
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
'
|
||||||
|
' Created by SharpDevelop.
|
||||||
|
' User: 14manvilleA
|
||||||
|
' Date: 27/09/2019
|
||||||
|
' Time: 10:18
|
||||||
|
'
|
||||||
|
' To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||||
|
'
|
||||||
|
Imports System.Drawing
|
||||||
|
|
||||||
|
Public Class View3D
|
||||||
|
Protected _objects As New Dictionary(Of String, Pair(Of ICoordinates3D, Color))
|
||||||
|
Protected _bitmapimage As Bitmap = Nothing
|
||||||
|
Protected _operateauto As Boolean = False
|
||||||
|
Protected _width As Integer = 0
|
||||||
|
Protected _height As Integer = 0
|
||||||
|
Protected _backcolor As Color = Color.Black
|
||||||
|
Public Sub New(width As Integer, height As Integer, Optional backcolor As Color = Nothing, Optional refreshafterop As Boolean = False)
|
||||||
|
_width = width
|
||||||
|
_height = height
|
||||||
|
_operateauto = refreshafterop
|
||||||
|
_bitmapimage = New Bitmap(width, height)
|
||||||
|
If backcolor.IsEmpty Then
|
||||||
|
_backcolor = Color.Black
|
||||||
|
Else
|
||||||
|
_backcolor = backcolor
|
||||||
|
End If
|
||||||
|
Using g As Graphics = Graphics.FromImage(_bitmapimage)
|
||||||
|
g.Clear(backcolor)
|
||||||
|
End Using
|
||||||
|
End Sub
|
||||||
|
Public ReadOnly Property getImage() As Bitmap
|
||||||
|
Get
|
||||||
|
Return _bitmapimage.Clone(New Rectangle(0, 0, _bitmapimage.Width, _bitmapimage.Height), _bitmapimage.PixelFormat)
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
Public ReadOnly Property width() As Integer
|
||||||
|
Get
|
||||||
|
Return _width
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
Public ReadOnly Property height() As Integer
|
||||||
|
Get
|
||||||
|
Return _height
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
Public Property refreshAfterOperation() As Boolean
|
||||||
|
Get
|
||||||
|
Return _operateauto
|
||||||
|
End Get
|
||||||
|
Set(value As Boolean)
|
||||||
|
_operateauto = value
|
||||||
|
If _operateauto Then refresh()
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Property backgroundColor() As Color
|
||||||
|
Get
|
||||||
|
Return _backcolor
|
||||||
|
End Get
|
||||||
|
Set(value As Color)
|
||||||
|
_backcolor = value
|
||||||
|
If _operateauto Then refresh()
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Function getObject(Of t As ICoordinates3D)(name As String) As t
|
||||||
|
If _objects.ContainsKey(name) Then
|
||||||
|
Return _objects(name).valueA
|
||||||
|
End If
|
||||||
|
Return Nothing
|
||||||
|
End Function
|
||||||
|
Public Sub setObject(Of t As ICoordinates3D)(name As String, [object] As t)
|
||||||
|
If [object] Is Nothing Then
|
||||||
|
If _objects.ContainsKey(name) Then
|
||||||
|
_objects.Remove(name)
|
||||||
|
Else
|
||||||
|
Throw New InvalidOperationException()
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
If _objects.ContainsKey(name) Then
|
||||||
|
Dim p As Pair(Of ICoordinates3D, Color) = _objects(name)
|
||||||
|
p.valueA = [object]
|
||||||
|
_objects(name) = p
|
||||||
|
Else
|
||||||
|
_objects.Add(name, New Pair(Of ICoordinates3D, Color)([object], _backcolor))
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
If _operateauto Then refresh()
|
||||||
|
End Sub
|
||||||
|
Public Function getObjectColor(name As String) As Color
|
||||||
|
If _objects.ContainsKey(name) Then
|
||||||
|
Return _objects(name).valueB
|
||||||
|
End If
|
||||||
|
Return Nothing
|
||||||
|
End Function
|
||||||
|
Public Sub setObjectColor(name As String, [color] As Color)
|
||||||
|
If color.IsEmpty Then
|
||||||
|
Throw New InvalidOperationException()
|
||||||
|
Else
|
||||||
|
If _objects.ContainsKey(name) Then
|
||||||
|
Dim p As Pair(Of ICoordinates3D, Color) = _objects(name)
|
||||||
|
p.valueB = color
|
||||||
|
_objects(name) = p
|
||||||
|
Else
|
||||||
|
Throw New InvalidOperationException()
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
If _operateauto Then refresh()
|
||||||
|
End Sub
|
||||||
|
Dim slockrf As New Object()
|
||||||
|
Public Sub refresh()
|
||||||
|
SyncLock slockrf
|
||||||
|
render()
|
||||||
|
End SyncLock
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Protected Sub render()
|
||||||
|
Using g As Graphics = Graphics.FromImage(_bitmapimage)
|
||||||
|
g.Clear(_backcolor)
|
||||||
|
Dim objs As New List(Of Pair(Of ICoordinates3D, Color))
|
||||||
|
Dim objsorder As New List(Of Integer)
|
||||||
|
Dim avgz As New List(Of Integer)
|
||||||
|
Dim piv As New List(Of Pair(Of Integer, Single))
|
||||||
|
For q = 0 To _objects.Values.Count - 1
|
||||||
|
Dim obj As Pair(Of ICoordinates3D, Color) = _objects.Values(q)
|
||||||
|
Dim cavgz As Single = 0
|
||||||
|
Dim cnt As Integer = 0
|
||||||
|
Dim array = obj.valueA.returnScaledPoints(_width, _height, 256, 128)
|
||||||
|
For i = 0 To array.Length - 1
|
||||||
|
Dim z As Point3D = array(i)
|
||||||
|
Dim cz As Single = z.Z
|
||||||
|
cavgz += cz
|
||||||
|
cnt += 1
|
||||||
|
Next
|
||||||
|
cavgz /= cnt
|
||||||
|
avgz.Add(cavgz)
|
||||||
|
objs.Add(obj)
|
||||||
|
piv.Add(New Pair(Of Integer, Single)(q, cavgz))
|
||||||
|
Next
|
||||||
|
piv.Sort(New IntegerSinglePairInverseSorter())
|
||||||
|
'#DEBUG#
|
||||||
|
'Console.WriteLine("#START#")
|
||||||
|
Dim array1 = piv.ToArray
|
||||||
|
For i = 0 To array1.Length - 1
|
||||||
|
Dim pr As Pair(Of Integer, Single) = array1(i)
|
||||||
|
objsorder.Add(pr.valueA)
|
||||||
|
'#DEBUG#
|
||||||
|
'Console.WriteLine("#" & pr.valueA & ":" & pr.valueB & "#")
|
||||||
|
Next
|
||||||
|
'#DEBUG#
|
||||||
|
'Console.WriteLine("#FINISH#")
|
||||||
|
For j As Integer = 0 To objsorder.Count - 1
|
||||||
|
Dim index As Integer = objsorder(j)
|
||||||
|
Dim ps3d As Point3D() = objs(index).valueA.returnScaledPoints(_width, _height, 256, 128)
|
||||||
|
Dim pnts As New List(Of PointF)
|
||||||
|
For i = 0 To ps3d.Length - 1
|
||||||
|
Dim p3d As Point3D = ps3d(i)
|
||||||
|
pnts.Add(New PointF(CInt(p3d.X), CInt(p3d.Y)))
|
||||||
|
Next
|
||||||
|
Dim points As PointF() = pnts.ToArray
|
||||||
|
Using b As Brush = New SolidBrush(objs(index).valueB)
|
||||||
|
g.FillPolygon(b, points)
|
||||||
|
End Using
|
||||||
|
Next
|
||||||
|
End Using
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Protected Class IntegerSinglePairInverseSorter
|
||||||
|
Implements IComparer(Of Pair(Of Integer, Single))
|
||||||
|
|
||||||
|
Public Function Compare(x As Pair(Of Integer, Single), y As Pair(Of Integer, Single)) As Integer Implements IComparer(Of Pair(Of Integer, Single)).Compare
|
||||||
|
If x.valueB < y.valueB Then
|
||||||
|
Return -1
|
||||||
|
ElseIf x.valueB > y.valueB Then
|
||||||
|
Return 1
|
||||||
|
End If
|
||||||
|
Return 0
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
|
|
||||||
|
Protected Structure Pair(Of a, b)
|
||||||
|
Public valueA As a
|
||||||
|
Public valueB As b
|
||||||
|
Public Sub New(va As a, vb As b)
|
||||||
|
valueA = va
|
||||||
|
valueB = vb
|
||||||
|
End Sub
|
||||||
|
End Structure
|
||||||
|
End Class
|
35
3DGDIRender/My Project/AssemblyInfo.vb
Normal file
35
3DGDIRender/My Project/AssemblyInfo.vb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
Imports System
|
||||||
|
Imports System.Reflection
|
||||||
|
Imports System.Runtime.InteropServices
|
||||||
|
|
||||||
|
' General Information about an assembly is controlled through the following
|
||||||
|
' set of attributes. Change these attribute values to modify the information
|
||||||
|
' associated with an assembly.
|
||||||
|
|
||||||
|
' Review the values of the assembly attributes
|
||||||
|
|
||||||
|
<Assembly: AssemblyTitle("GDI 3D Renderer")>
|
||||||
|
<Assembly: AssemblyDescription("GDI+ 3D Renderer")>
|
||||||
|
<Assembly: AssemblyCompany("Captain ALM")>
|
||||||
|
<Assembly: AssemblyProduct("GDI+ 3D Renderer")>
|
||||||
|
<Assembly: AssemblyCopyright("Copyright © Captain ALM 2019")>
|
||||||
|
<Assembly: AssemblyTrademark("")>
|
||||||
|
|
||||||
|
<Assembly: ComVisible(False)>
|
||||||
|
|
||||||
|
'The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
<Assembly: Guid("5c8fecf9-154c-4ee0-9a1f-73fce1ceff58")>
|
||||||
|
|
||||||
|
' Version information for an assembly consists of the following four values:
|
||||||
|
'
|
||||||
|
' Major Version
|
||||||
|
' Minor Version
|
||||||
|
' Build Number
|
||||||
|
' Revision
|
||||||
|
'
|
||||||
|
' You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
' by using the '*' as shown below:
|
||||||
|
' <Assembly: AssemblyVersion("1.0.*")>
|
||||||
|
|
||||||
|
<Assembly: AssemblyVersion("0.0.*")>
|
||||||
|
<Assembly: AssemblyFileVersion("0.0.*")>
|
18
3DGDIRenderer.sln
Normal file
18
3DGDIRenderer.sln
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||||
|
# Visual Studio 2005
|
||||||
|
# SharpDevelop 4.4
|
||||||
|
Project("") = "3DGDIRender", "3DGDIRender\3DGDIRender.vbproj", "6F70EF7B-C63A-4338-99CB-027B0C6DE0C1"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
6F70EF7B-C63A-4338-99CB-027B0C6DE0C1.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
6F70EF7B-C63A-4338-99CB-027B0C6DE0C1.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
6F70EF7B-C63A-4338-99CB-027B0C6DE0C1.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
6F70EF7B-C63A-4338-99CB-027B0C6DE0C1.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
Loading…
Reference in New Issue
Block a user