可以借助DirectX來編程。免費3D引擎可不好找,一般來說速度比不上硬件加速后的DX,尤其令人頭疼的是一般都沒有針對VB的文檔,LZ有這方面理想的話,自己寫一個吧……
創(chuàng)新互聯(lián)專注于企業(yè)成都營銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、政和網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場景定制、商城系統(tǒng)網(wǎng)站開發(fā)、集團公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為政和等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
我不得不承認在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
VB.net與VB不同。
VB.net已經(jīng)有專門繪圖的類。
可以定義筆刷然后用Drawing類中的方法繪制。
Private Sub DrawEllipse()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Private Sub DrawRectangle()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawRectangle(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
VB的作用是方便、快捷、簡單,但是它對數(shù)據(jù)庫編程不夠好,需要用到很復(fù)雜的控件,所以適合用來做小游戲、小軟件。
VB能做幾乎所有類型的軟件。
學校用到的人事管理、師資管理、學生資料、成績統(tǒng)計、考試系統(tǒng)方面的軟件,VB都可以勝任。
繼承(Inherits)控件就可以重寫它的屬性和方法,圖標可以在paint中重繪,用gdi,工具主要在drawing和drawing2d中。
combobox彈出的框增加圖標嗎?個人看法可能需要得到那個句柄,才可以重繪,但那個好像是一體的,不知道能不能弄到句柄。
textbox可以自定義高度。只是以行高度為單位,改變字體大小即可,沒必要重寫吧。
我也自學,感覺基礎(chǔ)容易學,進階資料少。循序漸進也沒序可循,基本是在摸索。
都是想到什么問題,就立下一個目標,然后攻破他,結(jié)果可能是嘗試幾天后,發(fā)現(xiàn)目標超出能力范圍。
晦澀是相對的,實踐出真知,多動手,基礎(chǔ)就好了。
文章題目:vb.net繪圖引擎 畫圖軟件visual怎么使用
分享鏈接:http://muchs.cn/article2/doeohic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、網(wǎng)站營銷、網(wǎng)站收錄、關(guān)鍵詞優(yōu)化、自適應(yīng)網(wǎng)站、App開發(fā)
聲明:本網(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)