可以借助DirectX來編程。免費3D引擎可不好找,一般來說速度比不上硬件加速后的DX,尤其令人頭疼的是一般都沒有針對VB的文檔,LZ有這方面理想的話,自己寫一個吧……
創(chuàng)新互聯(lián)是一家成都網(wǎng)站設(shè)計、做網(wǎng)站,提供網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,網(wǎng)站制作,建網(wǎng)站,按需網(wǎng)站制作,網(wǎng)站開發(fā)公司,于2013年創(chuàng)立是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價值為核心業(yè)務(wù),全程參與項目的網(wǎng)站策劃設(shè)計制作,前端開發(fā),后臺程序制作以及后期項目運營并提出專業(yè)建議和思路。
我不得不承認在VB上寫DirectX的教程相當難找!如果LZ想深入研究三維圖形問題,C++一定要學,就算不能用C++編程,起碼要能把C++程序翻譯成VB程序。
我自己學會DX編程花了兩三個月(很淺)。編這樣一個程序難度是有點大的。
工具:DirectX9和其針對VB的庫(項目-添加引用。.NET庫里DX庫一般都有),VB不知道現(xiàn)在支不支持DX10以上的版本,不過9絕對夠用了。
思路:一切3D圖形都是由三角形拼成的。矩形挖掉一個圓孔可不是一個方便畫的圖形,我估計至少得有24個三角形。你需要記錄這些點的坐標,或者干脆把它們寫在文件里,到時讀出來。
這是我的一個老DX程序的不完全的代碼(顯示一個黑乎乎的平面),不一定能編譯,可以參考一下。
Imports Microsoft.DirectX '一定要~
Public Class FormMain
'Direct3D Startup
Dim d3dpp As New Direct3D.PresentParameters 'DX基本參數(shù),例如全屏還是窗口等
Public MyDevice As Direct3D.Device ‘DX基本設(shè)備,畫圖就靠它。
'Matrices
Dim matWorld, matView, matProj As Matrix '世界位置矩陣,攝像機位置矩陣和透視矩陣,數(shù)學要學好啊。
'mesh
Public MyPlane as Direct3D.Mesh ’我們的物體
Public VBPlane(3) As Direct3D.CustomVertex.PositionNormalTextured '存放頂點位置的數(shù)組
#Region "DX Core"
Public Sub InitDeviceObjects()
With d3dpp ‘以下請照抄。
.Windowed = True ‘不全屏。
.SwapEffect = Direct3D.SwapEffect.Discard ’雙緩沖交換效果。請百度“雙緩沖”
.BackBufferFormat = Direct3D.Format.Unknown
.EnableAutoDepthStencil = True ’讓DX自動管理深度緩沖
.AutoDepthStencilFormat = Direct3D.DepthFormat.D16
End With
MyDevice = New Direct3D.Device(0, Direct3D.DeviceType.Hardware, Me.Handle, Direct3D.CreateFlags.HardwareVertexProcessing, d3dpp) '創(chuàng)建DX設(shè)備啦!以下兩句請照抄。
MyDevice.SetRenderState(Direct3D.RenderStates.ZEnable, True) ‘Z緩沖
MyDevice.SetRenderState(Direct3D.RenderStates.NormalizeNormals, True)'法線歸一化,請看相關(guān)數(shù)學書籍。
End Sub
Public Sub RestoreDeviceObjects()
Dim PlaneIB() As Short = {0, 1, 3, 0, 2, 3} ’頂點索引信息。
Dim AttrTable(1) As Direct3D.AttributeRange ‘頂點分組屬性表
AttrTable(0).AttributeId = 0
AttrTable(0).FaceStart = 0
AttrTable(0).FaceCount = 2 ’有兩個三角形
AttrTable(0).VertexStart = 0
AttrTable(0).VertexCount = 4 ‘四個點
‘頂點坐標信息。
VBPlane(0) = New Direct3D.CustomVertex.PositionNormalTextured(-500, -500, 0, 0, 0, 1, 0, 0)
VBPlane(1) = New Direct3D.CustomVertex.PositionNormalTextured(500, -500, 0, 0, 0, 1, 1, 0)
VBPlane(2) = New Direct3D.CustomVertex.PositionNormalTextured(-500, 500, 0, 0, 0, 1, 0, 1)
VBPlane(3) = New Direct3D.CustomVertex.PositionNormalTextured(500, 500, 0, 0, 0, 1, 1, 1)
MyPlane = New Direct3D.Mesh(2, 4, Direct3D.MeshFlags.Managed, Direct3D.VertexFormats.Position + Direct3D.VertexFormats.Normal + Direct3D.VertexFormats.Texture1, MyDevice) ’創(chuàng)建物體
MyPlane.SetVertexBufferData(VBPlane, Direct3D.LockFlags.None) ‘輸入頂點坐標數(shù)據(jù)
MyPlane.SetIndexBufferData(PlaneIB, Direct3D.LockFlags.None) ‘輸入索引數(shù)據(jù)
MyPlane.SetAttributeTable(AttrTable) ‘輸入頂點分組屬性表
End Sub
Public Sub Render() ‘調(diào)用它畫圖
Dim vlook As New Vector3(1, 0, 0)
Dim vPos As New Vector3(0,0,0)
Dim vUp As New Vector3(0, 0, 1)
MatView = Matrix.LookAtLH(vPos, vlook, vUp) ‘計算攝像機位置矩陣
Device.SetTransform(Direct3D.TransformType.View, MatView) ‘設(shè)置當前攝像機位置矩陣為MatView。
Dim fAspect As Single = Me.Width / Me.Height ’窗口長寬比
matProj = Matrix.PerspectiveFovLH(Math.PI / 4, fAspect, 1.0F, 10001) ‘計算透視矩陣MatProj。
MyDevice.SetTransform(Direct3D.TransformType.Projection, matProj) ‘設(shè)置當前透視矩陣為MatProj。
MyDevice.Clear(Direct3D.ClearFlags.Target + Direct3D.ClearFlags.ZBuffer, Color.Blue, 1.0F, 0) ’先刷藍屏
MyDevice.BeginScene() ‘開始畫
MatWorld = Matrix.Identity ’物體位于原點,不旋轉(zhuǎn)
Device.SetTransform(Direct3D.TransformType.World, MatWorld) ’設(shè)置物體位置
Me.Mesh.DrawSubset(0) ‘畫物體
MyDevice.EndScene() ’結(jié)束
MyDevice.Present() ‘顯示在屏幕上
End Sub
Public Sub DeleteDeviceObjects() ’結(jié)束程序時放掉資源
MyPlane.Dispose()
MyDevice.Dispose()
End Sub
#End Region
Private Sub FormMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
DeleteDeviceObjects()
Windows.Forms.Cursor.Show()
End Sub
Private Sub FormMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
InitDeviceObjects()
RestoreDeviceObjects()
Windows.Forms.Cursor.Hide()
Render()
End Sub
End Class
顯示桌面的本質(zhì)是個系統(tǒng) Shell(IShellDispatch4.ToggleDesktop()),所以只需要調(diào)用這個 Shell 就好了,用不著模擬按鍵。
項目引用 C:\Windows\System32\shell32.dll,參考代碼:
Dim?objShel?As?Shell32.ShellClass?=?New?Shell32.ShellClass()
CType(objShel,?Shell32.IShellDispatch4).ToggleDesktop()
給你看一段我的代碼
Public xlApp As Excel.Application
Public xlBook As Excel.Workbook
Public xlSheet As Excel.Worksheet
xlApp = CreateObject("Excel.Application") '創(chuàng)建EXCEL對象
xlBook = xlApp.Workbooks.Open(OpenFileDialog1.FileName) '打開已經(jīng)存在的EXCEL工件簿文件
xlSheet = xlBook.Worksheets(xlBook.Sheets(1).name) '讀取excel
'****************************讀取excel數(shù)據(jù),顯示在數(shù)據(jù)表上****************************************
DataGridView1.Rows.Clear() '清空記錄
For i = 5 To 19
If xlSheet.Cells(i, 1).value "" Then
DataGridView1.Rows.Add(xlSheet.Cells(2, 9).value, xlSheet.Cells(i, 1).value, xlSheet.Cells(2, 2).value, xlSheet.Cells(2, 7).value, xlSheet.Cells(2, 4).value, CDate(DateTimePicker1.Value), "", xlSheet.Cells(i, 5).value, Combo_CZZ.Text, Combo_MacName.Text, "", xlSheet.Cells(1, 3).value, xlSheet.Cells(1, 6).value, "", Combo_BanCi.Text, "")
End If
Next
這份文件列出了參數(shù)在PowerMILL提供。 表1 列出一般PowerMILL參數(shù), 表2 列出了有效的PowerMILL安裝額外的參數(shù)表。 表1。 PowerMILL參數(shù)。 標識符說明 (AdditionalStock)最大厚度的股票估計要去除刀具路徑。這是用來作為一種輔助手