Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8621818
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类:

2006-11-26 19:46:14

' ________________________________________________________________________
' TRUEVISION8 (web: http://www.truevision3d.com)
' ????????????????????????????????????
' Tutorial 5 : A small room.
' ?????
' Description : In this 5th tutorial, we will create a room by using
' ?????? the TVMesh feature "add wall" and we will also add
' the code to place the camera in the center of this room.

' Force explicit declarations
Option Explicit

' We declare TrueVision8.
Private TV8 As TVEngine

' We have to delare the room that we will use for this tutorial.
Private Room As TVMesh

' We the clare the scene
Private Scene As TVScene

' We declare the input engine.
Private InputEngine As TVInputEngine

' We declare the texture factory in order to load textures.
Private TextureFactory As TVTextureFactory


' The loop.
Private DoLoop As Boolean

' We need some variables to hold the vector (position) of the camera.
' A camera has two vectors. The first one holds the position of the
' camera (where we are standing). The second one holds the position
' where we are looking at.
Private sngPositionX As Single
Private sngPositionY As Single
Private sngPositionZ As Single
Private sngLookAtX As Single
Private sngLookAtY As Single
Private sngLookAtZ As Single

Private Sub cmdQuit_Click()

    ' We have clicked on the "Quit" button, so we change the DoLoop.
    DoLoop = False

End Sub

Private Sub Form_Load()

    ' We have to create the TV8 object before anything else.
    Set TV8 = New TVEngine

    ' Set the search directory of the objects, textures, ...
    TV8.SetSearchDirectory App.Path
    
    ' We initialize TV8 in the picture box of the form.
    TV8.Init3DWindowedMode Picture1.hWnd

    ' We want to see the FPS.
    TV8.DisplayFPS = True

    ' We create the input object.
    Set InputEngine = New TVInputEngine

    ' We create the scene (the world).
    Set Scene = New TVScene
    
    ' And the texture factory oject
    '设定材质工厂
    Set TextureFactory = New TVTextureFactory
    
    ' Change the background color (default color is black)
    '设定场景背景颜色
    Scene.SetSceneBackGround 0.3, 0.4, 0.8

 

    ' We load the floor texture and wall texture into the texture factory.
    '加载材质
    TextureFactory.LoadTexture "..\..\..\Media\fieldstone.tga", "FloorTexture"
    TextureFactory.LoadTexture "..\..\..\Media\roof1.bmp", "WallTexture"
    

    ' We tell the scene... Note that the mesh object
    ' is directly created by the CreateMeshBuilder function
    ' so you don't need to do Set Mesh = New TVMesh
    '设置room在场景中建立模型
    Set Room = Scene.CreateMeshBuilder
    
    ' Here is something new : we add walls to our room object. It's not
    ' really complicated : you just have to understand some basic
    ' principles. The first one is : that a wall is a rectangle. The
    ' second one is : the rectangle that defines the wall is created
    ' by using 2 vectors. The third one is : the 1st vector needs to
    ' define the nearest part of the wall and the 2nd vector needs to
    ' define the farest part of the wall. The fourth one is : the wall
    ' coordinates are seen from a top down view.
    '给房子加墙
    Room.AddWall GetTex("WallTexture"), 500, -500, -500, -500, 100, 0, 3, 1
    Room.AddWall GetTex("WallTexture"), -500, -500, -500, 500, 100, 0, 3, 1
    Room.AddWall GetTex("WallTexture"), -500, 500, 500, 500, 100, 0, 3, 1
    Room.AddWall GetTex("WallTexture"), 500, 500, 500, -500, 100, 0, 3, 1
    
    ' Like the "add wall" method, we will add a floor to this room.
    '给房子加地板
    Room.AddFloor GetTex("FloorTexture"), -500, -500, 500, 500, 0, 10, 10
    
    ' Something else new : we set the camera vectors which are the
    ' position of the camera (the point of view) and where we are
    ' looking at. We start by centering the camera position at the
    ' vector 0,40,0 and the look at the vector 50,20,50
    sngPositionX = 0
    sngPositionY = 40
    sngPositionZ = 0
    sngLookAtX = 50
    sngLookAtY = 20
    sngLookAtZ = 50
    '给场景设定摄像视角
    Scene.SetCamera sngPositionX, sngPositionY, sngPositionZ, sngLookAtX, sngLookAtY, sngLookAtZ
    
    ' We pop the form over everything else.
    Form1.Show
        
    ' We start the main loop.
    DoLoop = True
    Main_Loop

End Sub

Private Sub Form_Unload(Cancel As Integer)

    ' The user asked to quit but clicked on the 'X' button at up right.
    DoLoop = False
    
    ' And ask to quit.
    Main_Quit

End Sub

Private Sub Main_Loop()

    ' The main loop
    Do
        ' Let us the capacity to use buttons of the form.
        DoEvents
        
        ' Clear the the last frame.
        TV8.Clear
        
        ' We render all the 3D objects contained in the scene.
        Scene.RenderAllMeshes
        
        ' We display everything that we have rendered
        TV8.RenderToScreen
    
    'We loop all of this until the DoLoop isn't True.
    Loop Until DoLoop = False
    
    ' We ask to quit.
    Main_Quit

End Sub

Private Sub Main_Quit()
        
    ' We want to quit the project, so we destroy the room object.
    Set Room = Nothing
    
    ' Don't forget to destroy the inputengine object...
    Set InputEngine = Nothing
    
    ' Then, we destroy the scene object.
    Set Scene = Nothing
    
    ' We finish the frenetic destroy with the TV8 object.
    Set TV8 = Nothing
    
    ' We end the application.
    End

End Sub

阅读(3320) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~