您的位置:首页 > 编程语言 > VB

3DSTATE for Visual basic.Net开发(二)

2009-11-22 09:14 453 查看
3DSTATEfor Visual basic.Net开发注:转载请说明来源处!

准 备:

熟悉环境

在介绍前我们先来了解一下在接下来的学习中,我们首先要做的一些事情。
1、首先添加3DSTATE.vb到项目中,该文件位于C:/VBNet 3D Developer Studio 6.0 (Student Package)/Engine/Include目录下。
2、定义一个三维世界
Dim LoadWorld As Integer = STATE_engine_load_world("hello.morfit", "", "bitmaps", USER_DEFINED_BEHAVIOR)
这个返回值LoadWorld会告诉我们是否建立了三维世界,若没有建立则退出系统。代码如下:
If LoadWorld <> OK Then
MsgBox("Error loading world!")
Application.Exit()
End If
3、下面我们需要定义一个摄像机
Dim Camera As UIntPtr
Camera = STATE_camera_get_default_camera()
4、在程序结束时释放内存
STATE_engine_close()
整个程序代码:添加一个Timer
而且该窗体并不含* .Designer.vb,只包含Form1.resx,如下图所示:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
'
'Timer1
'
Me.Timer1.Interval = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(592, 334)
Me.Name = "Form1"
Me.Text = "Hello, World"
Me.ResumeLayout(False)
End Sub
#End Region
#Region "Fields"
Dim m_AlreadyDone As Boolean = False
#End Region
Protected Overrides Sub OnActivated(ByVal e As System.EventArgs)
If m_AlreadyDone Then
Exit Sub
End If
m_AlreadyDone = True
Dim Path As String = "C:/VBNet 3D Developer Studio 6.0 (Student Package)"
Dim Res As Integer
Res = STATE_engine_load_world("newcubeSTATE.wld", Path & "/Worlds", _
Path & "/Worlds/bitmaps", USER_DEFINED_BEHAVIOR)
If Res <> OK Then
MessageBox.Show("Failed to load world, aborting" & Chr(10) & Chr(13) & "look at error.log to see why.", _
"HelloWorld Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Application.Exit()
Exit Sub
End If
'Initialize 3D card.
STATE_3D_card_use(True)
STATE_engine_hide_log_window()
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
STATE_3D_card_use(False)
'It is important to call this before ending the program
STATE_engine_close()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim obj As UIntPtr = STATE_object_get_object_using_name("the_cube")
STATE_object_rotate_x(obj, 0.1, WORLD_SPACE)
STATE_object_rotate_y(obj, 0.5, WORLD_SPACE)
STATE_object_rotate_z(obj, 0.5, WORLD_SPACE)
'draw image seen from camera onto screen
STATE_engine_render(Handle, STATE_camera_get_default_camera())
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
或者直接更改Form1窗体中的Form1.Designer.vb文件。
基础知识

1、Handles
所有的对象、摄像机、位图、面等都具有Handles值,这个就像他们各自的ID一样,是程序在调用它们时如何区分他们之间的关键字。
Handle定义的类型为Long,但是当它为NULL值(即Value=0)时会出错。

2、3DSTATE APIs概述
3DSTATE APIs是由一系列功能组成的,每组功能用于三维世界中不同的方面。这些重要的功能主要包括:the camera API, the object API, the engine API, the polygon API, and the bitmap API.
所有的3DSTATE功能都是以单词STATE为前缀,例如STATE_camera_get_location, STATE_engine_load_world, and STATE_object_set_direction等。

三峡大学土木水电学院3S实验室肖泽云
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: