home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / vbsamples / direct3d / animkeys / animkeys.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-10-09  |  8.0 KB  |  220 lines

  1. VERSION 5.00
  2. Begin VB.Form Form3 
  3.    Caption         =   "Animate Key Frames"
  4.    ClientHeight    =   6015
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   7530
  8.    Icon            =   "AnimKeys.frx":0000
  9.    LinkTopic       =   "Form3"
  10.    ScaleHeight     =   401
  11.    ScaleMode       =   3  'Pixel
  12.    ScaleWidth      =   502
  13.    StartUpPosition =   3  'Windows Default
  14. Attribute VB_Name = "Form3"
  15. Attribute VB_GlobalNameSpace = False
  16. Attribute VB_Creatable = False
  17. Attribute VB_PredeclaredId = True
  18. Attribute VB_Exposed = False
  19. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  20. '  Copyright (C) 2000 Microsoft Corporation.  All Rights Reserved.
  21. '  File:       AnimKeys.frm
  22. '  Content:    Playback of animated geometry
  23. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  24. Option Explicit
  25. Dim Character As CD3DFrame
  26. Dim Animation As CD3DAnimation
  27. Dim MediaDir As String
  28. Dim m_bInit As Boolean
  29. Dim m_bMinimized As Boolean
  30. '-----------------------------------------------------------------------------
  31. ' Name: Form_Load()
  32. ' Desc: Main entry point for the sample
  33. '-----------------------------------------------------------------------------
  34. Private Sub Form_Load()
  35.     Dim hr As Long
  36.     ' Show the form
  37.     Me.Show
  38.     DoEvents
  39.     ' Initialize D3D
  40.     ' Note: D3DUtil_Init will attempt to use D3D Hardware acceleartion.
  41.     ' If it is not available it attempt to use the Software Reference Rasterizer.
  42.     ' If all fail it will display a message box indicating so.
  43.     '
  44.     m_bInit = D3DUtil_Init(Me.hwnd, True, 0, 0, D3DDEVTYPE_HAL, Nothing)
  45.     If Not (m_bInit) Then End
  46.                    
  47.     ' Find a path to our media
  48.     MediaDir = FindMediaDir("skmech.x")
  49.     D3DUtil_SetMediaPath MediaDir
  50.     ' Load Character and Animation Data
  51.     InitDeviceObjects
  52.     ' Position camera and Lights
  53.     RestoreDeviceObjects
  54.     ' Start our timer
  55.     DXUtil_Timer TIMER_start
  56.     ' Loop forever rendering our animation
  57.     Do While True
  58.         'Have our animation pose our character
  59.         Animation.SetTime DXUtil_Timer(TIMER_GETAPPTIME) * 30
  60.         
  61.         'See what state the device is in.
  62.         hr = g_dev.TestCooperativeLevel
  63.         If hr = D3DERR_DEVICENOTRESET Then
  64.             g_dev.Reset g_d3dpp
  65.             RestoreDeviceObjects
  66.         End If
  67.         
  68.         'dont bother rendering if we are not ready yet
  69.         If hr = 0 Then
  70.             
  71.             'Clear the background to ARGB grey
  72.             D3DUtil_ClearAll &HFF909090
  73.         
  74.             'Start the Scene
  75.             g_dev.BeginScene
  76.             
  77.             'Render the character (g_dev defined in D3DUtil)
  78.             Character.Render g_dev
  79.             
  80.             'End the scene
  81.             g_dev.EndScene
  82.             
  83.         End If
  84.         
  85.         'Update the Scene to our window
  86.         D3DUtil_PresentAll Me.hwnd
  87.         'Allow VB events to process
  88.         DoEvents
  89.         
  90.     Loop
  91. End Sub
  92. '-----------------------------------------------------------------------------
  93. ' Name: InitDeviceObjects()
  94. ' Desc: Load Character and Animation Data
  95. '-----------------------------------------------------------------------------
  96. Sub InitDeviceObjects()
  97.     'Create an Animation object to hold any animations
  98.     Set Animation = New CD3DAnimation
  99.     'Create a Frame object from a file
  100.     'the Animation object will parent any animations in the file
  101.     Set Character = D3DUtil_LoadFromFile(MediaDir + "skmech.x", Nothing, Animation)
  102. End Sub
  103. '-----------------------------------------------------------------------------
  104. ' Name: InvalidateDeviceObjects()
  105. ' Desc: place code to release references to non-managed objects here
  106. '-----------------------------------------------------------------------------
  107. Sub InvalidateDeviceObjects()
  108.     'all objects are managed in this sample
  109. End Sub
  110. '-----------------------------------------------------------------------------
  111. ' Name: RestoreDeviceObjects()
  112. ' Desc: setup device state such as camera and light placement
  113. '-----------------------------------------------------------------------------
  114. Sub RestoreDeviceObjects()
  115.     ' Set up some lights and camera
  116.     g_lWindowWidth = Me.ScaleWidth
  117.     g_lWindowHeight = Me.ScaleHeight
  118.     D3DUtil_SetupDefaultScene
  119.     ' position the camera
  120.     D3DUtil_SetupCamera vec3(0, 0, 300), vec3(0, 0, 0), vec3(0, 1, 0)
  121. End Sub
  122. '-----------------------------------------------------------------------------
  123. ' Name: DeleteDeviceObjects()
  124. ' Desc: Called when the app is exitting, or the device is being changed,
  125. '       this function deletes any device dependant objects.
  126. '-----------------------------------------------------------------------------
  127. Public Sub DeleteDeviceObjects()
  128.     Set Character = Nothing
  129.     Set Animation = Nothing
  130.     m_bInit = False
  131. End Sub
  132. '-----------------------------------------------------------------------------
  133. ' Name: Form_KeyDown()
  134. ' Desc: Process key messages for exit and change device
  135. '-----------------------------------------------------------------------------
  136. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  137.      Select Case KeyCode
  138.         
  139.         Case vbKeyEscape
  140.             Unload Me
  141.             
  142.         Case vbKeyF2
  143.                 
  144.             ' Pause the timer
  145.             DXUtil_Timer TIMER_STOP
  146.             
  147.             ' Bring up the device selection dialog
  148.             ' we pass in the form so the selection process
  149.             ' can make calls into InitDeviceObjects
  150.             ' and RestoreDeviceObjects
  151.             frmSelectDevice.SelectDevice Me
  152.             
  153.             ' Restart the timer
  154.             DXUtil_Timer TIMER_start
  155.             
  156.         Case vbKeyReturn
  157.         
  158.             ' Check for Alt-Enter if not pressed exit
  159.             If Shift <> 4 Then Exit Sub
  160.             
  161.             ' If we are windowed go fullscreen
  162.             ' If we are fullscreen returned to windowed
  163.             If g_d3dpp.Windowed Then
  164.                  D3DUtil_ResetFullscreen
  165.             Else
  166.                  D3DUtil_ResetWindowed
  167.             End If
  168.                              
  169.             ' Call Restore after ever mode change
  170.             ' because calling reset looses state that needs to
  171.             ' be reinitialized
  172.             RestoreDeviceObjects
  173.            
  174.     End Select
  175. End Sub
  176. '-----------------------------------------------------------------------------
  177. ' Name: Form_Resize()
  178. ' Desc: hadle resizing of the D3D backbuffer
  179. '-----------------------------------------------------------------------------
  180. Private Sub Form_Resize()
  181.     ' If D3D is not initialized then exit
  182.     If Not m_bInit Then Exit Sub
  183.     ' If we are in a minimized state stop the timer and exit
  184.     If Me.WindowState = vbMinimized Then
  185.         DXUtil_Timer TIMER_STOP
  186.         m_bMinimized = True
  187.         Exit Sub
  188.         
  189.     ' If we just went from a minimized state to maximized
  190.     ' restart the timer
  191.     Else
  192.         If m_bMinimized = True Then
  193.             DXUtil_Timer TIMER_start
  194.             m_bMinimized = False
  195.         End If
  196.     End If
  197.         
  198.     ' Dont let the window get too small
  199.     If Me.ScaleWidth < 10 Then
  200.         Me.width = Screen.TwipsPerPixelX * 10
  201.         Exit Sub
  202.     End If
  203.     If Me.ScaleHeight < 10 Then
  204.         Me.height = Screen.TwipsPerPixelY * 10
  205.         Exit Sub
  206.     End If
  207.     'reset and resize our D3D backbuffer to the size of the window
  208.     D3DUtil_ResizeWindowed Me.hwnd
  209.     'All state get losts after a reset so we need to reinitialze it here
  210.     RestoreDeviceObjects
  211. End Sub
  212. '-----------------------------------------------------------------------------
  213. ' Name: Form_Unload()
  214. ' Desc:
  215. '-----------------------------------------------------------------------------
  216. Private Sub Form_Unload(Cancel As Integer)
  217.     DeleteDeviceObjects
  218.     End
  219. End Sub
  220.