home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Direct3D / BarGraph / BarGraph.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  41.5 KB  |  1,106 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form GraphForm 
  4.    Caption         =   "Data Analysis Bar Graph"
  5.    ClientHeight    =   6420
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7875
  9.    BeginProperty Font 
  10.       Name            =   "MS Sans Serif"
  11.       Size            =   13.5
  12.       Charset         =   0
  13.       Weight          =   700
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    Icon            =   "BarGraph.frx":0000
  19.    LinkTopic       =   "Form1"
  20.    ScaleHeight     =   428
  21.    ScaleMode       =   3  'Pixel
  22.    ScaleWidth      =   525
  23.    StartUpPosition =   3  'Windows Default
  24.    Begin VB.CommandButton Command1 
  25.       Caption         =   "Command1"
  26.       BeginProperty Font 
  27.          Name            =   "MS Sans Serif"
  28.          Size            =   18
  29.          Charset         =   0
  30.          Weight          =   700
  31.          Underline       =   0   'False
  32.          Italic          =   0   'False
  33.          Strikethrough   =   0   'False
  34.       EndProperty
  35.       Height          =   435
  36.       Left            =   1920
  37.       TabIndex        =   0
  38.       Top             =   5820
  39.       Visible         =   0   'False
  40.       Width           =   495
  41.    End
  42.    Begin MSComDlg.CommonDialog CommonDialog1 
  43.       Left            =   1080
  44.       Top             =   5760
  45.       _ExtentX        =   847
  46.       _ExtentY        =   847
  47.       _Version        =   393216
  48.    End
  49.    Begin VB.Timer Timer1 
  50.       Enabled         =   0   'False
  51.       Interval        =   10
  52.       Left            =   240
  53.       Top             =   5760
  54.    End
  55.    Begin VB.Menu MENU_POPUP 
  56.       Caption         =   "POPUPMENU"
  57.       Visible         =   0   'False
  58.       Begin VB.Menu MENU_EXITMENU 
  59.          Caption         =   "Exit Menu!"
  60.       End
  61.       Begin VB.Menu MENU_LOAD 
  62.          Caption         =   "Load Data From File!"
  63.       End
  64.       Begin VB.Menu MENU_RESET 
  65.          Caption         =   "Reset Orientation!"
  66.       End
  67.       Begin VB.Menu MENU_BASE 
  68.          Caption         =   "Show base plane"
  69.          Checked         =   -1  'True
  70.       End
  71.       Begin VB.Menu MENU_ROTATE 
  72.          Caption         =   "Auto Rotate"
  73.          Checked         =   -1  'True
  74.       End
  75.    End
  76. Attribute VB_Name = "GraphForm"
  77. Attribute VB_GlobalNameSpace = False
  78. Attribute VB_Creatable = False
  79. Attribute VB_PredeclaredId = True
  80. Attribute VB_Exposed = False
  81. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  82. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  83. '  File:       BarGraph.frm
  84. '  Content:    Implementation of a 3D BarGraph
  85. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  86. Option Explicit
  87. Dim m_maxX As Double
  88. Dim m_minX As Double
  89. Dim m_maxY As Double
  90. Dim m_minY As Double
  91. Dim m_maxZ As Double
  92. Dim m_minZ As Double
  93. Dim m_maxsize As Double
  94. Dim m_minSize As Double
  95. Dim m_extX As Double
  96. Dim m_extY As Double
  97. Dim m_extZ As Double
  98. Dim m_extSize As Double
  99. Dim m_scalex As Single
  100. Dim m_scaley As Single
  101. Dim m_scalez As Single
  102. Dim m_scalesize As Single
  103. Dim m_binit As Boolean
  104. Dim m_bGraphInit As Boolean
  105. Dim m_bMinimized As Boolean
  106. Dim m_graphroot As CD3DFrame
  107. Dim m_quad1 As CD3DFrame
  108. Dim m_quad2 As CD3DFrame
  109. Dim m_XZPlaneFrame As CD3DFrame
  110. Dim m_bRot As Boolean
  111. Dim m_bShowBase As Boolean
  112. Dim m_drawtext As String
  113. Dim m_drawtextpos As RECT
  114. Dim m_drawtextEnable As Boolean
  115. Dim m_data As Collection
  116. Dim m_hwnd As Long
  117. Dim m_vbfont As IFont
  118. Dim m_vbfont2 As IFont
  119. Dim m_font2height  As Long
  120. Dim m_lastX As Single
  121. Dim m_lasty As Single
  122. Dim m_bMouseDown As Boolean
  123. Dim m_Tex As Direct3DTexture8
  124. Dim m_meshobj As D3DXMesh
  125. Dim m_meshplane As D3DXMesh
  126. Dim m_font As D3DXFont
  127. Dim m_font2 As D3DXFont
  128. Dim m_mediadir As String
  129. Dim m_fElapsedTime As Single
  130. Dim m_vVelocity  As D3DVECTOR
  131. Dim m_fYawVelocity As Single
  132. Dim m_fPitchVelocity As Single
  133. Dim m_fYaw As Single
  134. Dim m_fPitch As Single
  135. Dim m_vPosition As D3DVECTOR
  136. Dim m_bKey(256) As Boolean
  137. Dim m_matView As D3DMATRIX
  138. Dim m_matOrientation As D3DMATRIX
  139. Const kdx = 256&
  140. Const kdy = 256&
  141. Const kScale = 8
  142. Dim m_GraphTitle As String
  143. Dim m_RowLabels As Collection
  144. Dim m_ColLabels As Collection
  145. Dim m_cols As Long
  146. Dim m_rows As Long
  147. Dim m_barmesh() As D3DXMesh
  148. Dim m_labelmesh() As D3DXMesh
  149. Dim m_LabelTex() As Direct3DTexture8
  150. Dim m_sizex As Single
  151. Dim m_sizez As Single
  152. Dim m_ColTextures() As String
  153. Dim m_RowTextures() As String
  154. Const D3DFVF_VERTEX = D3DFVF_XYZ Or D3DFVF_NORMAL Or D3DFVF_TEX1
  155. Implements DirectXEvent8
  156. Sub DestroyDeviceObjects()
  157.     Set m_graphroot = Nothing
  158.     Set m_quad1 = Nothing
  159.     Set m_quad2 = Nothing
  160.     Set m_XZPlaneFrame = Nothing
  161.     ReDim m_LabelTex(0)
  162.     ReDim m_barmesh(0)
  163.     ReDim m_labelmesh(0)
  164. End Sub
  165. Friend Sub Init(hwnd As Long, font As IFontDisp, font2 As IFontDisp)
  166.     Dim i As Long
  167.     'Save hwnd
  168.     m_hwnd = hwnd
  169.     'convert IFontDisp to Ifont
  170.     Set m_vbfont = font
  171.     Set m_vbfont2 = font2
  172.     'initialized d3d
  173.     m_binit = D3DUtil_Init(hwnd, True, 0, 0, D3DDEVTYPE_HAL, Nothing)
  174.         
  175.     'exit if initialization failed
  176.     If m_binit = False Then End
  177.     m_bRot = True
  178.     D3DXMatrixTranslation m_matOrientation, 0, 0, 0
  179.     m_vPosition = vec3(0, 0, -20)
  180.     m_sizex = 1
  181.     m_sizez = 1
  182.     Set m_RowLabels = New Collection
  183.     Set m_ColLabels = New Collection
  184.     m_RowLabels.Add "XXX"
  185.     m_ColLabels.Add "ZZZ"
  186.     m_bShowBase = True
  187.     DeleteDeviceObjects
  188.     InitDeviceObjects
  189.     LoadFileAsBarGraph (m_mediadir + "bargraphdata.csv")
  190.     ComputeDataExtents
  191.     RestoreDeviceObjects
  192.     BuildGraph
  193.     DoEvents
  194.     'Initialze camera matrices
  195.     g_dev.GetTransform D3DTS_VIEW, m_matView
  196. End Sub
  197. Sub RestoreDeviceObjects()
  198.     g_lWindowWidth = Me.ScaleWidth
  199.     g_lWindowHeight = Me.ScaleHeight
  200.     D3DUtil_SetupDefaultScene
  201.     D3DUtil_SetupCamera vec3(0, 5, -20), vec3(0, 0, 0), vec3(0, 1, 0)
  202.     'allow the application to show both sides of all surfaces
  203.     g_dev.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
  204.     'turn on min filtering since our text is often smaller
  205.     'than original size
  206.     g_dev.SetTextureStageState 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR
  207.     Set m_font = g_d3dx.CreateFont(g_dev, m_vbfont.hFont)
  208.     Set m_font2 = g_d3dx.CreateFont(g_dev, m_vbfont2.hFont)
  209. End Sub
  210. Sub DeleteDeviceObjects()
  211.     Set m_font = Nothing
  212.     Set m_font2 = Nothing
  213. End Sub
  214. Private Sub ComputeDataExtents()
  215.     Dim mind As Single
  216.     Dim maxd As Single
  217.     Dim entry As DataEntry
  218.     mind = -9E+20
  219.     maxd = 9E+20
  220.     m_maxX = mind:    m_maxY = mind:    m_maxZ = mind:    m_maxsize = mind
  221.     m_minX = maxd:    m_minY = maxd:    m_minZ = maxd:    m_minSize = maxd
  222.     'Dim entry As DataEntry
  223.     For Each entry In m_data
  224.                         
  225.         If entry.datax > m_maxX Then m_maxX = entry.datax
  226.         If entry.datay > m_maxY Then m_maxY = entry.datay
  227.         If entry.dataz > m_maxZ Then m_maxZ = entry.dataz
  228.         If entry.dataSize > m_maxsize Then m_maxsize = entry.dataSize
  229.         
  230.         If entry.datax < m_minX Then m_minX = entry.datax
  231.         If entry.datay < m_minY Then m_minY = entry.datay
  232.         If entry.dataz < m_minZ Then m_minZ = entry.dataz
  233.         If entry.dataSize < m_minSize Then m_minSize = entry.dataSize
  234.                 
  235.     Next
  236.     m_extX = m_maxX - m_minX
  237.     m_extY = m_maxY - m_minY
  238.     m_extZ = m_maxZ - m_minZ
  239.     m_extSize = m_maxsize - m_minSize
  240.     m_scalex = 1
  241.     m_scaley = 1
  242.     m_scalez = 1
  243.     m_scalesize = 1
  244.     If m_maxX > Abs(m_minX) Then
  245.         If m_maxX <> 0 Then m_scalex = kScale / m_maxX
  246.     Else
  247.         If m_minX <> 0 Then m_scalex = kScale / Abs(m_minX)
  248.     End If
  249.     If m_maxY > Abs(m_minY) Then
  250.         If m_maxY <> 0 Then m_scaley = kScale / m_maxY
  251.     Else
  252.         If m_minY <> 0 Then m_scaley = kScale / Abs(m_minY)
  253.     End If
  254.     If m_maxZ > Abs(m_minZ) Then
  255.         If m_maxZ <> 0 Then m_scalez = kScale / m_maxZ
  256.     Else
  257.         If m_minZ <> 0 Then m_scalez = kScale / Abs(m_minZ)
  258.     End If
  259.     If m_maxsize = 0 Then m_maxsize = 1
  260.     m_scalesize = 1 * (kScale) / m_maxsize
  261.         
  262.     'scale graph data to fit
  263.     For Each entry In m_data
  264.                      
  265.         entry.x = (entry.datax - m_maxX / 2) * m_scalex
  266.         entry.y = (entry.datay) * m_scaley / 2
  267.         entry.z = (entry.dataz - m_maxZ / 2) * m_scalez
  268.         entry.size = entry.dataSize * m_scalesize
  269.     Next
  270. End Sub
  271. Public Sub AddEntry(sName As String, x As Double, y As Double, z As Double, size As Double, color As Long, data As Variant)
  272.     On Local Error GoTo errOut
  273.     Dim entry As New DataEntry
  274.     entry.dataname = sName
  275.     entry.datax = x
  276.     entry.datay = y
  277.     entry.dataz = z
  278.     entry.dataSize = size
  279.     entry.color = color
  280.     entry.data = data
  281.     m_data.Add entry
  282.     Exit Sub
  283. errOut:
  284.     MsgBox "unable to add entry"
  285. End Sub
  286. Public Sub DrawGraph()
  287.     Dim entry As DataEntry
  288.     Dim hr As Long
  289.         
  290.     If m_binit = False Then Exit Sub
  291.     'See what state the device is in.
  292.     hr = g_dev.TestCooperativeLevel
  293.     If hr = D3DERR_DEVICENOTRESET Then
  294.         g_dev.Reset g_d3dpp
  295.         RestoreDeviceObjects
  296.     ElseIf hr <> 0 Then
  297.         Exit Sub
  298.     End If
  299.     m_graphroot.UpdateFrames
  300.              
  301.     'Clear the previous render with the backgroud color
  302.     'We clear to grey but notice that we are using a hexidecimal
  303.     'number to represent Alpha Red Green and blue
  304.     D3DUtil_ClearAll &HFF808080
  305.     'set the ambient lighting level
  306.     g_dev.SetRenderState D3DRS_AMBIENT, &HFFC0C0C0
  307.     g_dev.BeginScene
  308.         
  309.         
  310.     'only render objects underneath the xzplane
  311.     m_quad1.Enabled = False
  312.     m_quad2.Enabled = True
  313.     m_XZPlaneFrame.Enabled = False
  314.     m_graphroot.Render g_dev
  315.     'render the objects in front of xz plane
  316.     m_quad1.Enabled = True
  317.     m_quad2.Enabled = False
  318.     m_XZPlaneFrame.Enabled = False
  319.     m_graphroot.Render g_dev
  320.     'DrawLines 0
  321.     'draw pop up text
  322.     If m_drawtextEnable Then
  323.         m_font.Begin
  324.         g_d3dx.DrawText m_font, &HFF000000, m_drawtext, m_drawtextpos, 0
  325.         m_font.End
  326.     End If
  327.     'render the xzplane with transparency
  328.     If m_bShowBase Then
  329.         m_quad1.Enabled = False
  330.         m_quad2.Enabled = False
  331.         m_XZPlaneFrame.Enabled = True
  332.         m_graphroot.Render g_dev
  333.     End If
  334.     g_dev.EndScene
  335.     D3DUtil_PresentAll m_hwnd
  336. End Sub
  337. Public Sub BuildGraph()
  338.     If Not m_binit Then Exit Sub
  339.     Dim entry As DataEntry
  340.     Dim material As D3DMATERIAL8
  341.     Dim newFrame As CD3DFrame
  342.     Dim mesh As D3DXMesh
  343.     Dim frameMesh As CD3DMesh
  344.     Dim i As Long, j As Long
  345.     Dim w As Single, h As Single
  346.     Dim sv As Single, ev As Single
  347.     Dim su As Single, eu As Single
  348.     Dim d3ddm As D3DDISPLAYMODE
  349.     If m_binit = False Then Exit Sub
  350.     Set m_graphroot = Nothing
  351.     Set m_quad1 = Nothing
  352.     Set m_quad2 = Nothing
  353.     'Create rotatable root object
  354.     Set m_graphroot = D3DUtil_CreateFrame(Nothing)
  355.                 
  356.     'Create XZ plane for reference
  357.     material.diffuse = LONGtoD3DCOLORVALUE(&H6FC0C0C0)
  358.     material.Ambient = material.diffuse
  359.     Set m_XZPlaneFrame = D3DUtil_CreateFrame(m_graphroot)
  360.     m_XZPlaneFrame.AddD3DXMesh(m_meshplane).SetMaterialOverride material
  361.     m_XZPlaneFrame.SetOrientation D3DUtil_RotationAxis(1, 0, 0, 90)
  362.     Set m_quad1 = D3DUtil_CreateFrame(m_graphroot)
  363.     Set m_quad2 = D3DUtil_CreateFrame(m_graphroot)
  364.     Dim rc As RECT
  365.     Dim surf As Direct3DSurface8
  366.     Dim rts As D3DXRenderToSurface
  367.     Dim rtsviewport As D3DVIEWPORT8
  368.     Call g_dev.GetDisplayMode(d3ddm)
  369.     Set rts = g_d3dx.CreateRenderToSurface(g_dev, kdx, kdy, d3ddm.format, 1, D3DFMT_D16)
  370.     rtsviewport.height = kdx
  371.     rtsviewport.width = kdy
  372.     rtsviewport.MaxZ = 1
  373.     Set surf = m_Tex.GetSurfaceLevel(0)
  374.           
  375.     rts.BeginScene surf, rtsviewport
  376.     g_dev.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &HFFC0C0C0, 1, 0
  377.     g_d3dx.DrawText m_font2, &HFF000000, "XXX", rc, DT_CALCRECT
  378.     m_font2height = rc.bottom
  379.     i = 0
  380.     Dim item As Variant
  381.     For Each item In m_RowLabels
  382.         If m_font2height * i >= kdy Then Exit For
  383.         rc.Top = m_font2height * i: rc.Left = 10: rc.bottom = 0: rc.Right = 0
  384.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, DT_CALCRECT
  385.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, 0
  386.         i = i + 1
  387.     Next
  388.     For Each item In m_ColLabels
  389.         If m_font2height * i >= kdy Then Exit For
  390.         rc.Top = m_font2height * i: rc.Left = 10: rc.bottom = 0: rc.Right = 0
  391.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, DT_CALCRECT
  392.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, 0
  393.         i = i + 1
  394.     Next
  395.     rts.EndScene
  396.     i = 0
  397.     Dim quadframe As CD3DFrame
  398.     ReDim m_barmesh(0)
  399.     For Each entry In m_data
  400.         If entry.y >= 0 Then Set quadframe = m_quad1
  401.         If entry.y < 0 Then Set quadframe = m_quad2
  402.                 
  403.         'Set material of objects
  404.         material.diffuse = LONGtoD3DCOLORVALUE(entry.color)
  405.         material.Ambient = material.diffuse
  406.                 
  407.         'Create individual objects
  408.         Set newFrame = D3DUtil_CreateFrame(quadframe)
  409.         newFrame.SetScale 1
  410.         newFrame.SetPosition vec3(entry.x, entry.y / 2, entry.z)
  411.         
  412.         ReDim Preserve m_barmesh(i)
  413.         Set m_barmesh(i) = g_d3dx.CreateBox(g_dev, m_sizex, Abs(entry.y), m_sizez, Nothing)
  414.         newFrame.AddD3DXMesh(m_barmesh(i)).SetMaterialOverride material
  415.         
  416.         
  417.         
  418.         i = i + 1
  419.         newFrame.ObjectName = Str(i)
  420.     Next
  421.         
  422.     Dim strLabel As Variant
  423.         
  424.     w = m_sizex * 3:  h = 0.5
  425.     i = 0
  426.     If Not (m_cols = 0 Or m_rows = 0) Then
  427.         ReDim m_labelmesh(m_rows + m_cols)
  428.         ReDim m_LabelTex(m_rows + m_cols)
  429.         
  430.         For Each strLabel In m_ColLabels
  431.         
  432.         i = i + 1
  433.         
  434.         su = 0: eu = 0.5:
  435.         sv = (m_font2height * (i - 1) / kdy)
  436.         ev = (m_font2height * (i) / kdy)
  437.                                     
  438.         Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  439.         newFrame.ObjectName = strLabel
  440.         newFrame.SetPosition vec3(5.5, -h / 2, (i - m_maxZ / 2 - 1) * m_scalez)
  441.         newFrame.AddRotation COMBINE_BEFORE, 0, 1, 0, g_pi / 2
  442.         m_graphroot.AddChild newFrame
  443.         
  444.         Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  445.         newFrame.ObjectName = strLabel
  446.         newFrame.SetPosition vec3(-5.5, 5 - h / 2, (i - m_maxZ / 2 - 1) * m_scalez)
  447.         newFrame.AddRotation COMBINE_BEFORE, 0, 1, 0, g_pi / 2
  448.         m_graphroot.AddChild newFrame
  449.         
  450.         su = 0: eu = 1: sv = 0: ev = 1
  451.         
  452.         LoadTexture i, m_RowTextures(i)    'note row and col texture are swapped
  453.         
  454.         If Not m_LabelTex(i) Is Nothing Then
  455.                 Set newFrame = CreateSheetWithTextureCoords(w, w, su, eu, sv, ev, m_LabelTex(i))
  456.                 newFrame.ObjectName = strLabel + " picture"
  457.                 newFrame.SetPosition vec3(5.5, -h - w / 2, (i - m_maxZ / 2 - 1) * m_scalez)
  458.                 newFrame.AddRotation COMBINE_BEFORE, 0, 1, 0, g_pi / 2
  459.                 m_graphroot.AddChild newFrame
  460.             End If
  461.              
  462.         Next
  463.         
  464.         j = 0
  465.         For Each strLabel In m_RowLabels
  466.              Set newFrame = D3DUtil_CreateFrame(m_graphroot)
  467.              i = i + 1: j = j + 1
  468.              
  469.              
  470.              su = 0: eu = 0.5:
  471.              sv = (m_font2height * (i - 1) / kdy)
  472.              ev = (m_font2height * (i) / kdy)
  473.                                              
  474.              Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  475.              newFrame.ObjectName = strLabel
  476.              newFrame.SetPosition vec3((j - m_maxX / 2 - 1) * m_scalex, -h / 2, -5.5)
  477.              m_graphroot.AddChild newFrame
  478.              
  479.              Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  480.              newFrame.ObjectName = strLabel
  481.              newFrame.SetPosition vec3((j - m_maxX / 2 - 1) * m_scalex, 5 - h / 2, 5.5)
  482.              m_graphroot.AddChild newFrame
  483.              
  484.              su = 0: eu = 1: sv = 0: ev = 1
  485.              
  486.              LoadTexture i, m_ColTextures(j)    'note row and col texture are swapped
  487.              
  488.              If Not m_LabelTex(i) Is Nothing Then
  489.                 Set newFrame = CreateSheetWithTextureCoords(w, w, su, eu, sv, ev, m_LabelTex(i))
  490.                 newFrame.ObjectName = strLabel + " picture"
  491.                 newFrame.SetPosition vec3((j - m_maxX / 2 - 1) * m_scalex, -h - w / 2, -5.5)
  492.                 m_graphroot.AddChild newFrame
  493.             End If
  494.         Next
  495.     End If
  496.         
  497.     m_bGraphInit = True
  498. End Sub
  499. Public Sub InitDeviceObjects()
  500.     Dim d3ddm As D3DDISPLAYMODE
  501.     If m_binit = False Then Exit Sub
  502.     Dim rc As RECT
  503.     Set m_meshobj = g_d3dx.CreateBox(g_dev, 0.1, 0.1, 0.1, Nothing)
  504.     Set m_meshplane = g_d3dx.CreateBox(g_dev, 10, 10, 0.1, Nothing)
  505.     Call g_dev.GetDisplayMode(d3ddm)
  506.     Set m_Tex = g_d3dx.CreateTexture(g_dev, kdx, kdx, 0, 0, d3ddm.format, D3DPOOL_MANAGED)
  507.     Set m_font = g_d3dx.CreateFont(g_dev, m_vbfont.hFont)
  508.     Set m_font2 = g_d3dx.CreateFont(g_dev, m_vbfont2.hFont)
  509.        
  510.        
  511. End Sub
  512. Private Sub DrawLines(quad As Long)
  513.     g_dev.SetTransform D3DTS_WORLD, m_graphroot.GetMatrix
  514.     DrawLine vec3(-5, 0.1, 0), vec3(5, 0.1, 0), &HFF0&
  515.     DrawLine vec3(0, 0.1, -5), vec3(0, 0.1, 5), &HFF0&
  516. End Sub
  517. Private Sub DrawLine(v1 As D3DVECTOR, v2 As D3DVECTOR, color As Long)
  518.     Dim mat As D3DMATERIAL8
  519.     mat.diffuse = LONGtoD3DCOLORVALUE(color)
  520.     mat.Ambient = mat.diffuse
  521.     g_dev.SetMaterial mat
  522.     Dim dataOut(2) As D3DVERTEX
  523.     LSet dataOut(0) = v1
  524.     LSet dataOut(1) = v2
  525.     g_dev.SetVertexShader D3DFVF_VERTEX
  526.     g_dev.DrawPrimitiveUP D3DPT_LINELIST, 1, dataOut(0), Len(dataOut(0))
  527. End Sub
  528. Public Sub MouseOver(Button As Integer, Shift As Integer, x As Single, y As Single)
  529.     If m_binit = False Then Exit Sub
  530.         
  531.     Dim pick As New CD3DPick
  532.     Dim frame As CD3DFrame
  533.     Dim nid As Long
  534.     Dim entry As DataEntry
  535.     'remove the XZ plane from consideration for pick
  536.     m_XZPlaneFrame.Enabled = False
  537.     m_quad1.Enabled = True
  538.     m_quad2.Enabled = True
  539.     pick.ViewportPick m_graphroot, x, y
  540.     nid = pick.FindNearest()
  541.     If nid < 0 Then
  542.         m_drawtextEnable = False
  543.         Exit Sub
  544.     End If
  545.         
  546.     Set frame = pick.GetFrame(nid)
  547.     'have matrices pre computed for scene graph
  548.     m_graphroot.UpdateFrames
  549.     'due some math to get position of item in screen space
  550.     Dim viewport As D3DVIEWPORT8
  551.     Dim projmatrix As D3DMATRIX
  552.     Dim viewmatrix As D3DMATRIX
  553.     Dim vOut As D3DVECTOR
  554.     g_dev.GetViewport viewport
  555.     g_dev.GetTransform D3DTS_PROJECTION, projmatrix
  556.     g_dev.GetTransform D3DTS_VIEW, viewmatrix
  557.     D3DXVec3Project vOut, vec3(0, 0, 0), viewport, projmatrix, viewmatrix, frame.GetUpdatedMatrix
  558.             
  559.     Debug.Print vOut.x, vOut.y, frame.ObjectName
  560.     Dim destRect As RECT
  561.     m_drawtextpos.Left = x - 20
  562.     m_drawtextpos.Top = y - 70
  563.     If m_drawtextpos.Left < 0 Then m_drawtextpos.Left = 1
  564.     If m_drawtextpos.Top < 0 Then m_drawtextpos.Top = 1
  565.     Dim iOver As Long
  566.     If IsNumeric(frame.ObjectName) Then
  567.         iOver = val(frame.ObjectName)
  568.         Set entry = m_data.item(iOver)
  569.         With entry
  570.             m_drawtext = .dataname + Chr(13)
  571.         End With
  572.         m_drawtextEnable = True
  573.     End If
  574. End Sub
  575. Sub FrameMove()
  576.     'for camera movement
  577.     m_fElapsedTime = DXUtil_Timer(TIMER_GETELLAPSEDTIME) * 1.3
  578.     If m_fElapsedTime < 0 Then Exit Sub
  579.         
  580.         
  581.     If m_bRot And m_bMouseDown = False Then
  582.         m_graphroot.AddRotation COMBINE_BEFORE, 0, 1, 0, (g_pi / 40) * m_fElapsedTime
  583.     End If
  584.         
  585.         
  586.     ' Slow things down for the REF device
  587.     If (g_devType = D3DDEVTYPE_REF) Then m_fElapsedTime = 0.05
  588.     Dim fSpeed As Single
  589.     Dim fAngularSpeed
  590.     fSpeed = 5 * m_fElapsedTime
  591.     fAngularSpeed = 1 * m_fElapsedTime
  592.     ' Slowdown the camera movement
  593.     D3DXVec3Scale m_vVelocity, m_vVelocity, 0.9
  594.     m_fYawVelocity = m_fYawVelocity * 0.9
  595.     m_fPitchVelocity = m_fPitchVelocity * 0.9
  596.     ' Process keyboard input
  597.     If (m_bKey(vbKeyRight)) Then m_vVelocity.x = m_vVelocity.x + fSpeed        '  Slide Right
  598.     If (m_bKey(vbKeyLeft)) Then m_vVelocity.x = m_vVelocity.x - fSpeed         '  Slide Left
  599.     If (m_bKey(vbKeyUp)) Then m_vVelocity.y = m_vVelocity.y + fSpeed           '  Move up
  600.     If (m_bKey(vbKeyDown)) Then m_vVelocity.y = m_vVelocity.y - fSpeed         '  Move down
  601.     If (m_bKey(vbKeyW)) Then m_vVelocity.z = m_vVelocity.z + fSpeed            '  Move Forward
  602.     If (m_bKey(vbKeyS)) Then m_vVelocity.z = m_vVelocity.z - fSpeed            '  Move Backward
  603.     If (m_bKey(vbKeyE)) Then m_fYawVelocity = m_fYawVelocity + fSpeed          '  Yaw right
  604.     If (m_bKey(vbKeyQ)) Then m_fYawVelocity = m_fYawVelocity - fSpeed          '  Yaw left
  605.     If (m_bKey(vbKeyZ)) Then m_fPitchVelocity = m_fPitchVelocity + fSpeed      '  turn down
  606.     If (m_bKey(vbKeyA)) Then m_fPitchVelocity = m_fPitchVelocity - fSpeed      '  turn up
  607.     ' Update the position vector
  608.     Dim vT As D3DVECTOR, vTemp As D3DVECTOR
  609.     D3DXVec3Scale vTemp, m_vVelocity, fSpeed
  610.     D3DXVec3Add vT, vT, vTemp
  611.     D3DXVec3TransformNormal vT, vT, m_matOrientation
  612.     D3DXVec3Add m_vPosition, m_vPosition, vT
  613.     If (m_vPosition.y < 1) Then m_vPosition.y = 1
  614.     ' Update the yaw-pitch-rotation vector
  615.     m_fYaw = m_fYaw + fAngularSpeed * m_fYawVelocity
  616.     m_fPitch = m_fPitch + fAngularSpeed * m_fPitchVelocity
  617.     If (m_fPitch < 0) Then m_fPitch = 0
  618.     If (m_fPitch > g_pi / 2) Then m_fPitch = g_pi / 2
  619.     Dim qR As D3DQUATERNION, det As Single
  620.     D3DXQuaternionRotationYawPitchRoll qR, m_fYaw, m_fPitch, 0
  621.     D3DXMatrixAffineTransformation m_matOrientation, 1.25, vec3(0, 0, 0), qR, m_vPosition
  622.     D3DXMatrixInverse m_matView, det, m_matOrientation
  623.         'set new view matrix
  624.     g_dev.SetTransform D3DTS_VIEW, m_matView
  625. End Sub
  626. Private Sub DirectXEvent8_DXCallback(ByVal i As Long)
  627.     Dim w As Single
  628.     Dim h As Single
  629.     Dim w1 As Single, w2 As Single
  630.     Dim h1 As Single, h2 As Single
  631.     Dim sv As Single, ev As Single
  632.     Dim su As Single, eu As Single
  633.     Dim mat As D3DMATERIAL8
  634.                   
  635.     w = m_sizex * 1.4:  h = 0.4
  636.         
  637.     mat.Ambient = ColorValue4(1, 1, 1, 1)
  638.     mat.diffuse = ColorValue4(1, 1, 1, 1)
  639.         
  640.     sv = (m_font2height * (i) / kdy)
  641.     ev = (m_font2height * (i + 1) / kdy)
  642.     'g_dev.SetTexture 0, m_Tex
  643.     'g_dev.SetMaterial mat
  644.     DrawLine vec3(1, 1, 1), vec3(0, 0, 0), &HFF00FF00
  645.     w = m_sizex * 1.4:  h = 0.4
  646.     'DrawSheet -w, w, -2 * h, 0, 0, 0.5, sv, ev
  647.     'g_dev.SetTexture 0, m_LabelTex(i + 1)
  648.     'DrawSheet -w, w, -2 * h - 2 * w, -2 * h, 0, 1, 0, 1
  649. End Sub
  650. Function CreateSheetWithTextureCoords(width As Single, height As Single, su As Single, eu As Single, sv As Single, ev As Single, texture As Direct3DTexture8) As CD3DFrame
  651.     Dim frame As CD3DFrame
  652.     Dim mesh As CD3DMesh
  653.     Dim retd3dxMesh As D3DXMesh
  654.     Dim vertexbuffer As Direct3DVertexBuffer8
  655.     Dim verts(8) As D3DVERTEX
  656.     Dim indices(12) As Integer
  657.     Dim w As Single, d As Single, h1 As Single, h2 As Single
  658.     w = width / 2
  659.     h2 = height / 2
  660.     h1 = -height / 2
  661.     d = 0.01
  662.     Dim whitematerial As D3DMATERIAL8
  663.     whitematerial.diffuse = ColorValue4(1, 1, 1, 1)
  664.     whitematerial.Ambient = whitematerial.diffuse
  665.         
  666.     'Create an empty d3dxmesh with room for 12 vertices and 12
  667.     Set retd3dxMesh = g_d3dx.CreateMeshFVF(8, 12, D3DXMESH_MANAGED, D3DFVF_VERTEX, g_dev)
  668.     'front face
  669.     'add vertices
  670.     With verts(0): .x = -w: .y = h2: .z = -d: .nz = 1: .tu = su: .tv = sv: End With
  671.     With verts(1): .x = w: .y = h2: .z = -d: .nz = 1: .tu = eu: .tv = sv: End With
  672.     With verts(2): .x = w: .y = h1: .z = -d: .nz = 1: .tu = eu: .tv = ev: End With
  673.     With verts(3): .x = -w: .y = h1: .z = -d: .nz = 1: .tu = su: .tv = ev: End With
  674.     'connect verices to make 2 triangles per face
  675.     indices(0) = 0: indices(1) = 1: indices(2) = 2
  676.     indices(3) = 0: indices(4) = 2: indices(5) = 3
  677.     'back face
  678.     With verts(4): .x = -w: .y = h1: .z = d: .nz = -1: .tu = eu: .tv = ev: End With
  679.     With verts(5): .x = w: .y = h1: .z = d: .nz = -1: .tu = su: .tv = ev: End With
  680.     With verts(6): .x = w: .y = h2: .z = d: .nz = -1: .tu = su: .tv = sv: End With
  681.     With verts(7): .x = -w: .y = h2: .z = d: .nz = -1: .tu = eu: .tv = sv: End With
  682.     indices(6) = 4: indices(7) = 5: indices(8) = 6
  683.     indices(9) = 4: indices(10) = 6: indices(11) = 7
  684.         
  685.     D3DXMeshVertexBuffer8SetData retd3dxMesh, 0, Len(verts(0)) * 8, 0, verts(0)
  686.     D3DXMeshIndexBuffer8SetData retd3dxMesh, 0, Len(indices(0)) * 12, 0, indices(0)
  687.         
  688.     Set frame = New CD3DFrame
  689.     Set mesh = frame.AddD3DXMesh(retd3dxMesh)
  690.     mesh.bUseMaterials = True
  691.     mesh.SetMaterialCount 1
  692.     mesh.SetMaterial 0, whitematerial
  693.     mesh.SetMaterialTexture 0, texture
  694.     Set CreateSheetWithTextureCoords = frame
  695. End Function
  696. Sub DrawSheet(w1 As Single, w2 As Single, h1 As Single, h2 As Single, su As Single, eu As Single, sv As Single, ev As Single)
  697.     Dim verts(4) As D3DVERTEX
  698.     g_dev.SetTexture 0, Nothing
  699.     With verts(0): .x = w1: .y = h1: .tu = su: .tv = ev: .nz = -1: End With
  700.     With verts(1): .x = w2: .y = h1: .tu = eu: .tv = ev: .nz = -1: End With
  701.     With verts(2): .x = w2: .y = h2: .tu = eu: .tv = sv: .nz = -1: End With
  702.     With verts(3): .x = w1: .y = h2: .tu = su: .tv = sv: .nz = -1: End With
  703.     'g_dev.SetVertexShader D3DFVF_VERTEX
  704.     'g_dev.DrawPrimitiveUP D3DPT_TRIANGLEFAN, 2, verts(0), Len(verts(0))
  705.     With verts(0): .z = 0.01: .x = w2: .y = h1: .tu = su: .tv = ev: .nz = 1: End With
  706.     With verts(1): .z = 0.01: .x = w1: .y = h1: .tu = eu: .tv = ev: .nz = 1: End With
  707.     With verts(2): .z = 0.01: .x = w1: .y = h2: .tu = eu: .tv = sv: .nz = 1: End With
  708.     With verts(3): .z = 0.01: .x = w2: .y = h2: .tu = su: .tv = sv: .nz = 1: End With
  709.     'g_dev.SetVertexShader D3DFVF_VERTEX
  710.     'g_dev.DrawPrimitiveUP D3DPT_TRIANGLEFAN, 2, verts(0), Len(verts(0))
  711. End Sub
  712. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  713.     m_bKey(KeyCode) = True
  714. End Sub
  715. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  716.     m_bKey(KeyCode) = False
  717. End Sub
  718. Private Sub Form_Load()
  719.     Me.Show
  720.     DoEvents
  721.     m_mediadir = FindMediaDir("bargraphdata.csv")
  722.     D3DUtil_SetMediaPath m_mediadir
  723.     Init Me.hwnd, Me.font, Command1.font
  724.     'Start the timers and callbacks
  725.     Call DXUtil_Timer(TIMER_start)
  726.     Timer1.Enabled = True
  727. End Sub
  728. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  729.     If Button = 2 Then
  730.         Me.PopupMenu MENU_POPUP
  731.     Else
  732.         '- save our current position
  733.         m_bMouseDown = True
  734.         m_lastX = x
  735.         m_lasty = y
  736.         
  737.     End If
  738. End Sub
  739. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  740.         
  741.     If m_binit = False Then Exit Sub
  742.     If Button = 2 Then Exit Sub
  743.     If m_bMouseDown = False Then
  744.         Call MouseOver(Button, Shift, x, y)
  745.     Else
  746.         '- Rotate the object
  747.         RotateTrackBall CInt(x), CInt(y)
  748.     End If
  749.     FrameMove
  750.     DrawGraph
  751. End Sub
  752. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  753.     m_bMouseDown = False
  754. End Sub
  755. '-----------------------------------------------------------------------------
  756. ' Name: Form_Resize()
  757. ' Desc: hadle resizing of the D3D backbuffer
  758. '-----------------------------------------------------------------------------
  759. Private Sub Form_Resize()
  760.     Timer1.Enabled = False
  761.     ' If D3D is not initialized then exit
  762.     If Not m_binit Then Exit Sub
  763.     ' If we are in a minimized state stop the timer and exit
  764.     If Me.WindowState = vbMinimized Then
  765.         DXUtil_Timer TIMER_STOP
  766.         m_bMinimized = True
  767.         Exit Sub
  768.         
  769.     ' If we just went from a minimized state to maximized
  770.     ' restart the timer
  771.     Else
  772.         If m_bMinimized = True Then
  773.             DXUtil_Timer TIMER_start
  774.             m_bMinimized = False
  775.         End If
  776.     End If
  777.         
  778.      ' Dont let the window get too small
  779.     If Me.ScaleWidth < 10 Then
  780.         Me.width = Screen.TwipsPerPixelX * 10
  781.         Exit Sub
  782.     End If
  783.     If Me.ScaleHeight < 10 Then
  784.         Me.height = Screen.TwipsPerPixelY * 10
  785.         Exit Sub
  786.     End If
  787.     'remove references to FONTs
  788.     DeleteDeviceObjects
  789.     'reset and resize our D3D backbuffer to the size of the window
  790.     D3DUtil_ResizeWindowed Me.hwnd
  791.     'All state get losts after a reset so we need to reinitialze it here
  792.     RestoreDeviceObjects
  793.     Timer1.Enabled = True
  794. End Sub
  795. '- Rotate Track ball
  796. '  given a point on the screen the mouse was moved to
  797. '  simulate a track ball
  798. Private Sub RotateTrackBall(x As Integer, y As Integer)
  799.     Dim delta_x As Single, delta_y As Single
  800.     Dim delta_r As Single, radius As Single, denom As Single, angle As Single
  801.     ' rotation axis in camcoords, worldcoords, sframecoords
  802.     Dim axisC As D3DVECTOR
  803.     Dim wc As D3DVECTOR
  804.     Dim axisS As D3DVECTOR
  805.     Dim base As D3DVECTOR
  806.     Dim origin As D3DVECTOR
  807.     delta_x = x - m_lastX
  808.     delta_y = y - m_lasty
  809.     m_lastX = x
  810.     m_lasty = y
  811.             
  812.      delta_r = Sqr(delta_x * delta_x + delta_y * delta_y)
  813.      radius = 50
  814.      denom = Sqr(radius * radius + delta_r * delta_r)
  815.     If (delta_r = 0 Or denom = 0) Then Exit Sub
  816.     angle = (delta_r / denom)
  817.     axisC.x = (-delta_y / delta_r)
  818.     axisC.y = (-delta_x / delta_r)
  819.     axisC.z = 0
  820.     'transform camera space vector to world space
  821.     'm_largewindow.m_cameraFrame.Transform wc, axisC
  822.     g_dev.GetTransform D3DTS_VIEW, g_viewMatrix
  823.     D3DXVec3TransformCoord wc, axisC, g_viewMatrix
  824.     'transform world space vector into Model space
  825.     m_graphroot.UpdateFrames
  826.     axisS = m_graphroot.InverseTransformCoord(wc)
  827.         
  828.     'transform origen camera space to world coordinates
  829.     'm_largewindow.m_cameraFrame.Transform  wc, origin
  830.     D3DXVec3TransformCoord wc, origin, g_viewMatrix
  831.     'transfer cam space origen to model space
  832.     base = m_graphroot.InverseTransformCoord(wc)
  833.     axisS.x = axisS.x - base.x
  834.     axisS.y = axisS.y - base.y
  835.     axisS.z = axisS.z - base.z
  836.     m_graphroot.AddRotation COMBINE_BEFORE, axisS.x, axisS.y, axisS.z, angle
  837. End Sub
  838. Private Sub Form_Paint()
  839.     If Not m_binit Then Exit Sub
  840.     If Not m_bGraphInit Then Exit Sub
  841.     DrawGraph
  842. End Sub
  843. Private Sub Form_Unload(Cancel As Integer)
  844.     End
  845. End Sub
  846. Private Sub MENU_BASE_Click()
  847.     m_bShowBase = Not m_bShowBase
  848.     MENU_BASE.Checked = m_bShowBase
  849. End Sub
  850. Private Sub MENU_LOAD_Click()
  851.     Dim sFile As String
  852.     'Stop the timers and callbacks
  853.     Timer1.Enabled = False
  854.     CommonDialog1.FileName = ""
  855.     CommonDialog1.DefaultExt = "csv"
  856.     CommonDialog1.filter = "csv|*.csv"
  857.     CommonDialog1.InitDir = m_mediadir
  858.     'On Local Error Resume Next
  859.     CommonDialog1.ShowOpen
  860.     sFile = CommonDialog1.FileName
  861.     If sFile = "" Then Exit Sub
  862.     LoadFileAsBarGraph sFile
  863.     D3DUtil_Destory
  864.     DestroyDeviceObjects
  865.             
  866.     D3DUtil_Init Me.hwnd, True, 0, 0, D3DDEVTYPE_HAL, Nothing
  867.     InitDeviceObjects
  868.     ComputeDataExtents
  869.     BuildGraph
  870.     RestoreDeviceObjects
  871.     'restart the callbacks
  872.     DXUtil_Timer (TIMER_RESET)
  873.     DXUtil_Timer (TIMER_start)
  874.     Timer1.Enabled = True
  875. End Sub
  876. Private Sub MENU_RESET_Click()
  877.     m_graphroot.SetMatrix g_identityMatrix
  878.     m_vPosition = vec3(0, 0, -20)
  879.     m_fYaw = 0
  880.     m_fPitch = 0
  881.     Call D3DXMatrixTranslation(m_matOrientation, 0, 0, 0)
  882.     D3DUtil_SetupDefaultScene
  883.     g_dev.GetTransform D3DTS_VIEW, m_matView
  884. End Sub
  885. Private Sub MENU_ROTATE_Click()
  886.     m_bRot = Not m_bRot
  887.     MENU_ROTATE.Checked = m_bRot
  888. End Sub
  889. Private Sub Timer1_Timer()
  890.     If Not m_binit Then Exit Sub
  891.     FrameMove
  892.     DrawGraph
  893. End Sub
  894. Sub LoadFileAsBarGraph(sFile As String)
  895.     If Dir$(sFile) = "" Then
  896.         MsgBox "Unable to find " & sFile
  897.         Exit Sub
  898.     End If
  899.     Dim fl As Long
  900.     Dim strIn As String
  901.     Dim strTrim As String
  902.     Dim strFirstChar As String
  903.     Dim splitArray
  904.     Dim cols As Long
  905.     Dim bFoundData As Boolean
  906.     Dim bFoundHeader As Boolean
  907.     Dim sName As String
  908.     Dim x As Double
  909.     Dim y As Double
  910.     Dim z As Double
  911.     Dim i As Long
  912.     Dim olddata As Collection
  913.     Dim oldcolLabels As Collection
  914.     Dim oldRowLabels As Collection
  915.     Dim oldCols As Long
  916.     Dim oldRows As Long
  917.     Dim strRowLabel As String
  918.     Dim strColLabel As String
  919.     Dim valout As Variant
  920.     Dim strName As String
  921.     Dim sizeout As Single
  922.     Dim colorout As Long
  923.     fl = FreeFile
  924.         
  925.     'On Local Error GoTo errOut
  926.     Set olddata = m_data
  927.     Set oldcolLabels = m_ColLabels
  928.     Set oldRowLabels = m_RowLabels
  929.     oldCols = m_cols
  930.     oldRows = m_rows
  931.     Set m_data = Nothing
  932.     Set m_data = New Collection
  933.     m_cols = 0
  934.     m_rows = 0
  935.     Set m_ColLabels = New Collection
  936.     Set m_RowLabels = New Collection
  937.     Open sFile For Input As fl
  938.         
  939.     Do While Not EOF(fl)
  940.         Line Input #fl, strIn
  941.         strTrim = Trim(strIn)
  942.         
  943.         'skip comment lines
  944.         strFirstChar = Mid$(strTrim, 1, 1)
  945.         If strFirstChar = "#" Or strFirstChar = ";" Then GoTo nextLine
  946.         If strTrim = "" Then GoTo nextLine
  947.         
  948.         splitArray = Split(strTrim, ",")
  949.         
  950.         cols = UBound(splitArray) + 1
  951.         If cols < 2 Then
  952.             MsgBox "Comma delimited file must have at least a header row, header column, and data"
  953.             GoTo closeOut
  954.         End If
  955.                 
  956.         Dim strData As String
  957.         Dim q As Long
  958.         
  959.         'If we have not found numbers see if we found a header row
  960.         If Not bFoundData Then
  961.             If IsNumeric(splitArray(1)) = False Then
  962.                 
  963.                 'assume data is a header row
  964.                 m_cols = cols
  965.                 
  966.                 m_GraphTitle = CStr(splitArray(0))
  967.                                 
  968.                 ReDim m_ColTextures(UBound(splitArray))
  969.                 
  970.                 For i = 1 To m_cols - 1
  971.                     strData = Trim(CStr(splitArray(i)))
  972.                     strColLabel = strData
  973.                     q = InStr(UCase(strData), "TEXTURE:")
  974.                     If q <> 0 Then
  975.                         m_ColTextures(i) = Mid$(strData, q + 8)
  976.                         If q > 1 Then strColLabel = Mid$(strData, 1, q - 1)
  977.                     End If
  978.                     m_ColLabels.Add strColLabel
  979.                 Next
  980.                 bFoundHeader = True
  981.                 GoTo nextLine
  982.             Else
  983.                 bFoundData = True
  984.                 If bFoundHeader = False Then
  985.                     MsgBox "Comma delimited file must have first for be header row to label columns"
  986.                     GoTo closeOut
  987.                 End If
  988.             End If
  989.         End If
  990.         
  991.         m_rows = m_rows + 1
  992.         strData = Trim(splitArray(0))
  993.         strRowLabel = strData
  994.         q = InStr(UCase(strData), "TEXTURE:")
  995.         ReDim Preserve m_RowTextures(m_rows)
  996.         If q <> 0 Then
  997.             m_RowTextures(m_rows) = Mid$(strData, q + 8)
  998.             If q > 1 Then strRowLabel = Mid$(strData, 1, q - 1)
  999.         End If
  1000.         
  1001.         m_RowLabels.Add strRowLabel
  1002.         
  1003.         sizeout = 1
  1004.         
  1005.         
  1006.         For i = 1 To m_cols - 1
  1007.             colorout = D3DCOLORVALUEtoLONG(ColorValue4(1, 1 - (2 + m_rows Mod 4) / 10, 0.2, 1 - ((i Mod 8)) / 10))
  1008.             strColLabel = m_ColLabels.item(i)
  1009.             valout = splitArray(i)
  1010.             strName = "(" & strRowLabel & "," & strColLabel & ") = " & CStr(valout)
  1011.             AddEntry strName, CDbl(i - 1), val(valout), CDbl(m_rows - 1), CDbl(sizeout), colorout, ""
  1012.         Next
  1013.         
  1014.         
  1015. nextLine:
  1016.     Loop
  1017.     Set olddata = Nothing
  1018.     Close fl
  1019.     m_sizex = (kScale / m_cols) * 0.5
  1020.     m_sizez = (kScale / m_rows) * 0.5
  1021.     Exit Sub
  1022. errOut:
  1023.     MsgBox "there was an error loading " & sFile
  1024. closeOut:
  1025.     'restore state
  1026.     Set m_data = olddata
  1027.     Set m_ColLabels = oldcolLabels
  1028.     Set m_RowLabels = oldRowLabels
  1029.     m_rows = oldRows
  1030.     m_cols = oldCols
  1031.     Close fl
  1032. End Sub
  1033. Function CreateBoxWithTextureCoords(width As Single, height As Single, depth As Single) As D3DXMesh
  1034.     Dim mesh As CD3DMesh
  1035.     Dim retd3dxMesh As D3DXMesh
  1036.     Dim vertexbuffer As Direct3DVertexBuffer8
  1037.     Dim verts(28) As D3DVERTEX
  1038.     Dim indices(36) As Integer
  1039.     Dim w As Single, d As Single, h1 As Single, h2 As Single
  1040.     w = width / 2
  1041.     h2 = height / 2
  1042.     h1 = -height / 2
  1043.     d = depth / 2
  1044.     'Create an empty d3dxmesh with room for 12 vertices and 12
  1045.     Set retd3dxMesh = g_d3dx.CreateMeshFVF(4 * 6, 6 * 6, D3DXMESH_MANAGED, D3DFVF_VERTEX, g_dev)
  1046.     'front face
  1047.     'add vertices
  1048.     With verts(0): .x = -w: .y = h2: .z = -d: .nz = 1: .tu = 0: .tv = 0: End With
  1049.     With verts(1): .x = w: .y = h2: .z = -d: .nz = 1: .tu = 1: .tv = 0: End With
  1050.     With verts(2): .x = w: .y = h1: .z = -d: .nz = 1: .tu = 1: .tv = 1: End With
  1051.     With verts(3): .x = -w: .y = h1: .z = -d: .nz = 1: .tu = 0: .tv = 1: End With
  1052.     'connect verices to make 2 triangles per face
  1053.     indices(0) = 0: indices(1) = 1: indices(2) = 2
  1054.     indices(3) = 0: indices(4) = 2: indices(5) = 3
  1055.     'back face
  1056.     With verts(4): .x = -w: .y = h1: .z = d: .nz = -1: .tu = 0: .tv = 1: End With
  1057.     With verts(5): .x = w: .y = h1: .z = d: .nz = -1: .tu = 1: .tv = 1: End With
  1058.     With verts(6): .x = w: .y = h2: .z = d: .nz = -1: .tu = 1: .tv = 0: End With
  1059.     With verts(7): .x = -w: .y = h2: .z = d: .nz = -1: .tu = 0: .tv = 0: End With
  1060.     indices(6) = 4: indices(7) = 5: indices(8) = 6
  1061.     indices(9) = 4: indices(10) = 6: indices(11) = 7
  1062.     'right face
  1063.     With verts(8): .x = w: .y = h1: .z = -d: .nx = -1: .tu = 0: .tv = 0: End With
  1064.     With verts(9): .x = w: .y = h1: .z = d: .nx = -1: .tu = 1: .tv = 0: End With
  1065.     With verts(10): .x = w: .y = h2: .z = d: .nx = -1: .tu = 1: .tv = 1: End With
  1066.     With verts(11): .x = w: .y = h2: .z = -d: .nx = -1: .tu = 0: .tv = 1: End With
  1067.     indices(12) = 8: indices(13) = 9: indices(14) = 10
  1068.     indices(15) = 8: indices(16) = 10: indices(17) = 11
  1069.     'left face
  1070.     With verts(16): .x = -w: .y = h2: .z = -d: .nx = 1: .tu = 0: .tv = 1: End With
  1071.     With verts(17): .x = -w: .y = h2: .z = d: .nx = 1: .tu = 1: .tv = 1: End With
  1072.     With verts(18): .x = -w: .y = h1: .z = d: .nx = 1: .tu = 1: .tv = 0: End With
  1073.     With verts(19): .x = -w: .y = h1: .z = -d: .nx = 1: .tu = 0: .tv = 0: End With
  1074.     indices(18) = 16: indices(19) = 17: indices(20) = 18
  1075.     indices(21) = 16: indices(22) = 18: indices(23) = 19
  1076.     'top face
  1077.     With verts(20): .x = -w: .y = h2: .z = -d: .ny = -1: .tu = 0: .tv = 0: End With
  1078.     With verts(21): .x = -w: .y = h2: .z = d: .ny = -1: .tu = 1: .tv = 0: End With
  1079.     With verts(22): .x = w: .y = h2: .z = d: .ny = -1: .tu = 1: .tv = 1: End With
  1080.     With verts(23): .x = w: .y = h2: .z = -d: .ny = -1: .tu = 0: .tv = 1: End With
  1081.     indices(24) = 20: indices(25) = 21: indices(26) = 22
  1082.     indices(27) = 20: indices(28) = 22: indices(29) = 23
  1083.         
  1084.     'bottom  face
  1085.     With verts(24): .x = w: .y = h1: .z = -d: .ny = 1: .tu = 0: .tv = 1: End With
  1086.     With verts(25): .x = w: .y = h1: .z = d: .ny = 1: .tu = 1: .tv = 1: End With
  1087.     With verts(26): .x = -w: .y = h1: .z = d: .ny = 1: .tu = 1: .tv = 0: End With
  1088.     With verts(27): .x = -w: .y = h1: .z = -d: .ny = 1: .tu = 0: .tv = 0: End With
  1089.     indices(30) = 24: indices(31) = 25: indices(32) = 26
  1090.     indices(33) = 24: indices(34) = 26: indices(35) = 27
  1091.         
  1092.     D3DXMeshVertexBuffer8SetData retd3dxMesh, 0, Len(verts(0)) * 28, 0, verts(0)
  1093.     D3DXMeshIndexBuffer8SetData retd3dxMesh, 0, Len(indices(0)) * 36, 0, indices(0)
  1094.         
  1095.         
  1096.     Set CreateBoxWithTextureCoords = retd3dxMesh
  1097. End Function
  1098. Sub LoadTexture(i As Long, strFile As String)
  1099.         
  1100.     If strFile = "" Then Exit Sub
  1101.     Set m_LabelTex(i) = D3DUtil.D3DUtil_CreateTextureInPool(g_dev, strFile, D3DFMT_R5G6B5)
  1102.     If m_LabelTex(i) Is Nothing Then
  1103.         MsgBox "Unable to find " & strFile
  1104.     End If
  1105. End Sub
  1106.