From bd762e9659c5e5a5b260f5268a1702565e89b964 Mon Sep 17 00:00:00 2001 From: Alfred Manville <14ManvilleA@ccgrammarschool.co.uk> Date: Fri, 27 Sep 2019 10:46:19 +0100 Subject: [PATCH] Inital Commit. --- .gitattributes | 2 + .gitignore | 189 ++++++++++++++ 3DGDIRender/3D.vb | 343 +++++++++++++++++++++++++ 3DGDIRender/3DGDIRender.vbproj | 79 ++++++ 3DGDIRender/3DInterfaces.vb | 31 +++ 3DGDIRender/3DViewports.vb | 188 ++++++++++++++ 3DGDIRender/My Project/AssemblyInfo.vb | 35 +++ 3DGDIRenderer.sln | 18 ++ 8 files changed, 885 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 3DGDIRender/3D.vb create mode 100644 3DGDIRender/3DGDIRender.vbproj create mode 100644 3DGDIRender/3DInterfaces.vb create mode 100644 3DGDIRender/3DViewports.vb create mode 100644 3DGDIRender/My Project/AssemblyInfo.vb create mode 100644 3DGDIRenderer.sln diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7964536 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/3DGDIRender/3D.vb b/3DGDIRender/3D.vb new file mode 100644 index 0000000..c72422e --- /dev/null +++ b/3DGDIRender/3D.vb @@ -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 \ No newline at end of file diff --git a/3DGDIRender/3DGDIRender.vbproj b/3DGDIRender/3DGDIRender.vbproj new file mode 100644 index 0000000..3131219 --- /dev/null +++ b/3DGDIRender/3DGDIRender.vbproj @@ -0,0 +1,79 @@ + + + + + Debug + AnyCPU + {57106980-D2A0-4B53-843E-84DBFA89EDA3} + Library + captainalm.util.Render3D + 3DGDIRender + 512 + Windows + v4.0 + + + true + full + true + true + bin\Debug\ + 3DGDIRender.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + pdbonly + false + true + true + bin\Release\ + 3DGDIRender.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3DGDIRender/3DInterfaces.vb b/3DGDIRender/3DInterfaces.vb new file mode 100644 index 0000000..84d1834 --- /dev/null +++ b/3DGDIRender/3DInterfaces.vb @@ -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 \ No newline at end of file diff --git a/3DGDIRender/3DViewports.vb b/3DGDIRender/3DViewports.vb new file mode 100644 index 0000000..be7c166 --- /dev/null +++ b/3DGDIRender/3DViewports.vb @@ -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 \ No newline at end of file diff --git a/3DGDIRender/My Project/AssemblyInfo.vb b/3DGDIRender/My Project/AssemblyInfo.vb new file mode 100644 index 0000000..3aeaf4c --- /dev/null +++ b/3DGDIRender/My Project/AssemblyInfo.vb @@ -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 + + + + + + + + + + +'The following GUID is for the ID of the typelib if this project is exposed to COM + + +' 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: +' + + + diff --git a/3DGDIRenderer.sln b/3DGDIRenderer.sln new file mode 100644 index 0000000..3eb3c6d --- /dev/null +++ b/3DGDIRenderer.sln @@ -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