可以借助DirectX來編程。免費3D引擎可不好找,一般來說速度比不上硬件加速后的DX,尤其令人頭疼的是一般都沒有針對VB的文檔,LZ有這方面理想的話,自己寫一個吧……
“只有客戶發(fā)展了,才有我們的生存與發(fā)展!”這是創(chuàng)新互聯(lián)建站的服務(wù)宗旨!把網(wǎng)站當作互聯(lián)網(wǎng)產(chǎn)品,產(chǎn)品思維更注重全局思維、需求分析和迭代思維,在網(wǎng)站建設(shè)中就是為了建設(shè)一個不僅審美在線,而且實用性極高的網(wǎng)站。創(chuàng)新互聯(lián)對成都網(wǎng)站設(shè)計、做網(wǎng)站、網(wǎng)站制作、網(wǎng)站開發(fā)、網(wǎng)頁設(shè)計、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)推廣、探索永無止境。
我不得不承認在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
DataGridView控件,放一個DataGridView1和Button1到窗體,下面是按鈕下代碼
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.DataGridView1.AllowUserToAddRows = False
DataGridView1.RowTemplate.Height = 200
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
For i = 1 To 3
Me.DataGridView1.Columns.Add("列" i.ToString, "列" i.ToString)
Me.DataGridView1.Rows.Add()
Next
Me.DataGridView1.Columns(0).Width = 100
Me.DataGridView1.Columns(1).Width = 500
Me.DataGridView1.Columns(0).Width = 300
End Sub
'自己設(shè)置相關(guān)需要的屬性即可
數(shù)學上不是有斜二測畫法,算好坐標即可畫出
或者用AnyCAD的.Net圖形控件
也可以調(diào)用matlab 實現(xiàn)
首先在項目的VB.NET界面,使用菜單【項目】--【添加引用】--【COM】
選擇 ?Microsoft ADO Ext. 2.x for DDL and Security
然后單擊【確定】,完成引用。
完整代碼如下:
Imports?ADOX
Public?Class?Form1
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
'創(chuàng)建空的access數(shù)據(jù)庫文件--數(shù)據(jù)庫文件.mdb,密碼為123
Dim?Mycat?As?Catalog?=?New?Catalog()
Mycat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Jet?OLEDB:Engine?Type=5;Data?Source=?數(shù)據(jù)庫文件.mdb;Jet?OLEDB:Database?Password=123")
'以下代碼創(chuàng)建一個名為“實驗數(shù)據(jù)表”
Dim?MyTable?As?ADOX.Table?=?New?ADOX.Table?????????'定義新表
MyTable.Name?=?"實驗數(shù)據(jù)表"????'表命名
'給表“實驗數(shù)據(jù)表”?創(chuàng)建一個字符串字段,字段名“姓名”
MyTable.Columns.Append("姓名",?,?ADOX.DataTypeEnum.adWChar)
'給表“實驗數(shù)據(jù)表”?創(chuàng)建一個整數(shù)字段,字段名“學號”
MyTable.Columns.Append("學號",?ADOX.DataTypeEnum.adInteger)????'追加一個數(shù)字型字段
'給字段“學號”創(chuàng)建一個主鍵“PimaryKey_Field”????????
MyTable.Keys.Append("學號",?ADOX.KeyTypeEnum.adKeyPrimary,?"學號")
Mycat.Tables.Append(MyTable)?'把所有的新字段追加到表
MyTable?=?Nothing
Mycat?=?Nothing
End?Sub
End?Class
Dim a(3, 3, 3)
Dim b(3, 3), c(3, 3), d(3, 3)
Private Sub aaa()
' 對數(shù)組a(3,3,3)賦值
For i = 1 To 3
For j = 1 To 3
b(i, j) = a(1, i, j)
Next
Next
For i = 1 To 3
For j = 1 To 3
c(i, j) = a(2, i, j)
Next
Next
For i = 1 To 3
For j = 1 To 3
d(i, j) = a(3, i, j)
Next
Next
End Sub
網(wǎng)站欄目:vb.net三維表,vb 三維數(shù)組
網(wǎng)頁地址:http://sd-ha.com/article38/hsessp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計公司、微信公眾號、品牌網(wǎng)站設(shè)計、ChatGPT、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)