home *** CD-ROM | disk | FTP | other *** search
/ Microsoft DirectX SDK 7.0 / Dx7.bin / DXF / samples / multimedia / vbsamples / d3drm / src / egg / egg.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-04  |  5.5 KB  |  161 lines

  1. VERSION 5.00
  2. Begin VB.Form EggForm 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Advanced Retained Mode Tutorial 1"
  5.    ClientHeight    =   4710
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5535
  9.    Icon            =   "egg.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4710
  14.    ScaleWidth      =   5535
  15.    ShowInTaskbar   =   1   'True
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin VB.PictureBox Picture1 
  18.       Height          =   4695
  19.       Left            =   0
  20.       ScaleHeight     =   309
  21.       ScaleMode       =   3  'Pixel
  22.       ScaleWidth      =   365
  23.       TabIndex        =   0
  24.       Top             =   0
  25.       Width           =   5535
  26.    End
  27. Attribute VB_Name = "EggForm"
  28. Attribute VB_GlobalNameSpace = False
  29. Attribute VB_Creatable = False
  30. Attribute VB_PredeclaredId = True
  31. Attribute VB_Exposed = False
  32. Option Explicit
  33. Dim g_dx As New DirectX7
  34. Dim m_dd As DirectDraw7
  35. Dim m_ddClipper As DirectDrawClipper
  36. Dim m_rm As Direct3DRM3
  37. Dim m_rmDevice As Direct3DRMDevice3
  38. Dim m_rmViewport As Direct3DRMViewport2
  39. Dim m_rootFrame As Direct3DRMFrame3
  40. Dim m_lightFrame As Direct3DRMFrame3
  41. Dim m_cameraFrame As Direct3DRMFrame3
  42. Dim m_objectFrame As Direct3DRMFrame3
  43. Dim m_uvFrame As Direct3DRMFrame3
  44. Dim m_light As Direct3DRMLight
  45. Dim m_meshBuilder As Direct3DRMMeshBuilder3
  46. Dim m_object As Direct3DRMMeshBuilder3
  47. Dim m_width As Long
  48. Dim m_height As Long
  49. Dim m_running As Boolean
  50. Dim m_finished As Boolean
  51. Private Sub Form_Load()
  52.         Show
  53.         DoEvents
  54.         InitRM
  55.         FindMediaDir "egg.x"
  56.         InitScene "egg.x"
  57.         RenderLoop
  58.         CleanUp
  59.         End
  60. End Sub
  61. Sub CleanUp()
  62.     m_running = False
  63.     Exit Sub
  64.     Set m_light = Nothing
  65.     Set m_meshBuilder = Nothing
  66.     Set m_object = Nothing
  67.     Set m_lightFrame = Nothing
  68.     Set m_cameraFrame = Nothing
  69.     Set m_objectFrame = Nothing
  70.     Set m_rootFrame = Nothing
  71.     Set m_rmDevice = Nothing
  72.     Set m_ddClipper = Nothing
  73.     Set m_rm = Nothing
  74.     Set m_dd = Nothing
  75. End Sub
  76. Sub InitRM()
  77.     'Create Direct Draw From Current Display Mode
  78.     Set m_dd = g_dx.DirectDrawCreate("")
  79.     'Create new clipper object and associate it with a window'
  80.     Set m_ddClipper = m_dd.CreateClipper(0)
  81.     m_ddClipper.SetHWnd Picture1.hWnd
  82.         
  83.     'save the widht and height of the picture in pixels
  84.     m_width = Picture1.ScaleWidth
  85.     m_height = Picture1.ScaleHeight
  86.     'Create the Retained Mode object
  87.     Set m_rm = g_dx.Direct3DRMCreate()
  88.     'Create the Retained Mode device to draw to
  89.     Set m_rmDevice = m_rm.CreateDeviceFromClipper(m_ddClipper, "", m_width, m_height)
  90.     m_rmDevice.SetQuality D3DRMRENDER_GOURAUD
  91. End Sub
  92. Sub InitScene(sMesh As String)
  93.     'Setup a scene graph with a camera light and object
  94.     Set m_rootFrame = m_rm.CreateFrame(Nothing)
  95.     Set m_cameraFrame = m_rm.CreateFrame(m_rootFrame)
  96.     Set m_lightFrame = m_rm.CreateFrame(m_rootFrame)
  97.     Set m_objectFrame = m_rm.CreateFrame(m_rootFrame)
  98.     'position the camera and create the Viewport
  99.     'provide the device thre viewport uses to render, the frame whose orientation and position
  100.     'is used to determine the camera, and a rectangle describing the extents of the viewport
  101.     m_cameraFrame.SetPosition Nothing, 0, 0, -10
  102.     Set m_rmViewport = m_rm.CreateViewport(m_rmDevice, m_cameraFrame, 0, 0, m_width, m_height)
  103.     'create a white light and hang it off the light frame
  104.     Set m_light = m_rm.CreateLight(D3DRMLIGHT_DIRECTIONAL, &HFFFFFFFF)
  105.     m_lightFrame.AddLight m_light
  106.     'For this sample we will load x files with geometry only
  107.     'so create a meshbuilder object
  108.     Set m_meshBuilder = m_rm.CreateMeshBuilder()
  109.     m_meshBuilder.LoadFromFile sMesh, 0, D3DRMLOAD_FROMFILE, Nothing, Nothing
  110.     'add the meshbuilder to the scene graph
  111.     m_objectFrame.AddVisual m_meshBuilder
  112.     'Have the object rotating
  113.     m_objectFrame.SetRotation Nothing, 1, 1, 1, 0.05
  114. End Sub
  115. Sub RenderLoop()
  116.     Dim t1 As Long
  117.     Dim t2 As Long
  118.     Dim delta As Single
  119.     On Local Error Resume Next
  120.     m_running = True
  121.     t1 = g_dx.TickCount()
  122.     Do While m_running = True
  123.         t2 = g_dx.TickCount()
  124.         delta = (t2 - t1) / 10
  125.         t1 = t2
  126.         m_rootFrame.Move delta  'increment velocities
  127.         m_rmViewport.Clear D3DRMCLEAR_ALL    'clear the rendering surface rectangle described by the viewport
  128.         m_rmViewport.Render m_rootFrame 'render to the device
  129.         FixFloat
  130.         m_rmDevice.Update   'blt the image to the screen
  131.         DoEvents    'allows events to be processed even though we are in a tight loop
  132.     Loop
  133. End Sub
  134. Sub FixFloat()
  135.     On Local Error Resume Next
  136.     Dim l As Single
  137.     l = 6
  138.     l = l / 0
  139. End Sub
  140. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  141.     CleanUp
  142.     End
  143. End Sub
  144. Private Sub Picture1_Paint()
  145.     On Local Error Resume Next
  146.     m_rmDevice.HandlePaint Picture1.hDC
  147. End Sub
  148. Sub FindMediaDir(sFile As String)
  149.     On Local Error Resume Next
  150.     If Mid$(App.Path, 2, 1) = ":" Then
  151.         ChDrive Mid$(App.Path, 1, 1)
  152.     End If
  153.     ChDir App.Path
  154.     If Dir$(sFile) = "" Then
  155.         ChDir "..\media"
  156.     End If
  157.     If Dir$(sFile) = "" Then
  158.         ChDir "..\..\media"
  159.     End If
  160. End Sub
  161.