Posted on 2005-11-25 15:51
繁星 阅读(1937)
评论(4) 编辑 收藏 引用
刚写了一个模拟地球的程序,我是用经纬地球模型来接近球体的。沿着经线和纬线方向来分割(各分为40份);程序部分代码:
Private Type CUSTOMVERTEX
p As D3DVECTOR
n As D3DVECTOR
tu As Single
tv As Single
End Type
Dim Vertices(3200) As CUSTOMVERTEX
Dim VertexSizeInBytes As Long
VertexSizeInBytes = Len(Vertices(0))
For i = 0 To 39
For j = 0 To 39
With Vertices(m)
.p = Cver(j * g_pi / 40, i * g_pi / 20, 1)
.n = .p
.tv = j / 40
.tu = i / 40
End With
With Vertices(m + 1)
.p = Cver((j + 1) * g_pi / 40, (i + 1) * g_pi / 20, 1)
.n = .p
.tv = (j + 1) / 40
.tu = (i + 1) / 40
End With
m = m + 2
Next
Next
Set g_VB = g_D3DDevice.CreateVertexBuffer(VertexSizeInBytes * 3200, 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT)
D3DVertexBuffer8SetData g_VB, 0, VertexSizeInBytes * 3200, 0, Vertices(0)
Function Cver(a As Single, b As Single, r As Single) As D3DVECTOR
Cver.x = r * Sin(a) * Cos(b)
Cver.y = r * Cos(a)
Cver.z = r * Sin(a) * Sin(b)
End Function
上面代码实现了一个球体并贴上纹理:
原代码下载:http://www.cnitblog.com/Files/seesea/球体.rar