我现在需要在vb里面加个三维的模型,但是我没有弄过,请哪位大虾指教.

解决方案 »

  1.   

    Private CenterX As Integer
    Private CenterY As Integer
    Private Const Size = 40
    Private CurX As Integer
    Private CurY As Integer
    Private CurZ As Integer
    Private MoveTo As Integer
    Private Const MOVE_LEFT = 0
    Private Const MOVE_RIGHT = 1
    Private Const MOVE_UP = 2
    Private Const MOVE_DOWN = 3
    Private Const MOVE_FORWARD = 4
    Private Const MOVE_BACKWARD = 5
    Public Sub EraseBlock()
    X = CurX: y = CurY: Z = CurZ
    xs = (CenterX + X * Size) - Z * (Size / 2)
    Ys = (CenterY - y * Size) + Z * (Size / 2)
    Line (xs, Ys)-(xs + Size, Ys - Size), BackColor, BF
    Line (xs - Size / 2, Ys + Size / 2)-(xs + Size / 2, Ys - Size / 2), BackColor, BF
    For i = 0 To Size / 2
    Line (xs - i, Ys + i)-(xs - i, Ys + i - Size - 1), BackColor
    Line (xs - i + Size, Ys + i)-(xs - i + Size, Ys + i - Size), BackColor
    Next
    End Sub
    Public Sub DrawBlock()
    Line (CenterX, CenterY)-(CenterX + Size * 6, CenterY - Size * 6), vbBlue, B
    Line (CenterX, CenterY)-(CenterX - Size * 6 / 2, CenterY + Size * 6 / 2), vbBlue
    Line (CenterX, CenterY - Size * 6)-(CenterX - Size * 6 / 2, CenterY + Size * 6 / 2 - Size * 6), vbBlue
    Line (CenterX + 1, CenterY - 1)-(CenterX + Size * 6 - 1, CenterY - Size * 6 + 1), RGB(0, 60, 0), BF
    For i = 1 To Size * 6 / 2 - 1
    Line (CenterX - i + 1, CenterY + i)-(CenterX - i + Size * 6, CenterY + i), RGB(0, 60 + i * 2, 0)
    NextFor i = 0 To Size * 6 / 2 - 1
    Line (CenterX - i - 1, CenterY + i)-(CenterX - i - 1, CenterY + i - Size * 6 + 1), RGB(0, 60 + i * 2, 0)
    Next
    Label1.Caption = "X : " & CurX & vbCrLf & "Y : " & CurY & vbCrLf & "Z : " & CurZ & vbCrLf
    X = CurX: y = CurY: Z = CurZ
    col = 10 + Z * 20
    xs = (CenterX + X * Size) - Z * (Size / 2)
    Ys = CenterY + Z * (Size / 2)
    For i = 0 To Size / 2
    Line (xs - i, Ys + i)-(xs - i + Size, Ys + i), vbBlack
    Next
    Ys = (CenterY - y * Size) + Z * (Size / 2)
    Line (xs - Size / 2 + 1, Ys + Size / 2 - 1)-(xs + Size / 2 - 1, Ys - Size / 2 + 1), RGB(col + 120, 0, 0), BF
    Line (xs + 1, Ys - 1)-(xs + Size - 1, Ys - Size + 1), RGB(col, 0, 0), BF
    For i = 0 To Size / 2
    Line (xs - i, Ys + i)-(xs - i + Size, Ys + i), RGB(col + i * 8, 0, 0)
    Line (xs - i, Ys + i)-(xs - i, Ys + i - Size), RGB(col + i * 8, 0, 0)
    Line (xs - i + Size, Ys + i)-(xs - i + Size, Ys + i - Size), RGB(col + i * 8, 0, 0)
    Next
    Line (CenterX - Size * 6 / 2, CenterY + Size * 6 / 2)-(CenterX + Size * 6 / 2, CenterY - Size * 6 / 2), vbBlue, B
    Line (CenterX + Size * 6, CenterY)-(CenterX + Size * 6 - Size * 6 / 2, CenterY + Size * 6 / 2), vbBlue
    Line (CenterX + Size * 6, CenterY - Size * 6)-(CenterX + Size * 6 - Size * 6 / 2, CenterY + Size * 6 / 2 - Size * 6), vbBlue
    End Sub
    Private Sub cmdDemo_Click()
    Select Case cmdDemo.Caption
    Case "DEMO ON"
    Timer1.Enabled = True
    cmdDemo.Caption = "DEMO OFF"
    Case Else
    Timer1.Enabled = False
    cmdDemo.Caption = "DEMO ON"
    End Select
    End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyLeft
    If CurX > 0 Then
    EraseBlock
    CurX = CurX - 1
    DrawBlock
    End If
    Case vbKeyRight
    If CurX < 5 Then
    EraseBlock
    CurX = CurX + 1
    DrawBlock
    End If
    Case vbKeyUp
    If Shift = 0 Then
    If CurY < 5 Then
    EraseBlock
    CurY = CurY + 1
    DrawBlock
    End If
    ElseIf Shift = 1 Then
    If CurZ > 0 Then
    EraseBlock
    CurZ = CurZ - 1
    DrawBlock
    End If
    End If
    Case vbKeyDown
    If Shift = 0 Then
    If CurY > 0 Then
    EraseBlock
    CurY = CurY - 1
    DrawBlock
    End If
    ElseIf Shift = 1 Then
    If CurZ < 5 Then
    EraseBlock
    CurZ = CurZ + 1
    DrawBlock
    End If
    End If
    End Select
    End Sub
    Private Sub Form_Load()
    Move 0, 0, Screen.Width, Screen.Height
    Show
    Label1.Move Picture1.ScaleWidth - Label2.Width, 0
    Label2.Move Picture1.ScaleWidth - Label2.Width, Label1.Height * 4
    Picture1.Move ScaleWidth - Picture1.Width, 0
    CenterX = ScaleWidth / 4
    CenterY = ScaleHeight / 1.5
    DrawBlock
    End Sub
    Private Sub Timer1_Timer()
    Randomize
    d = Int(Rnd * 11)
    If d > 5 And MoveTo < 4 Then MoveTo = RandomMove
    EraseBlock
    Select Case MoveTo
    Case MOVE_DOWN
    If CurY > 0 Then CurY = CurY - 1 Else: MoveTo = RandomMove
    Case MOVE_UP
    If CurY < 5 Then CurY = CurY + 1 Else: MoveTo = RandomMove
    Case MOVE_RIGHT
    If CurX < 5 Then CurX = CurX + 1 Else: MoveTo = RandomMove
    Case MOVE_LEFT
    If CurX > 0 Then CurX = CurX - 1 Else: MoveTo = RandomMove
    Case MOVE_BACKWARD
    If CurZ > 0 Then CurZ = CurZ - 1 Else MoveTo = RandomMove
    Case MOVE_FORWARD
    If CurZ < 5 Then CurZ = CurZ + 1 Else: MoveTo = RandomMove
    End Select
    DrawBlock
    End Sub
    Private Function RandomMove() As Integer
    Randomize
    Dim d As Integer
    d = Int(Rnd * 6)
    RandomMove = d
    End Function
    '参考一下.