home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / direct3d / bargraph / bargraph.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-10-02  |  41.4 KB  |  1,104 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) 2000 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.     End If
  297.     m_graphroot.UpdateFrames
  298.              
  299.     'Clear the previous render with the backgroud color
  300.     'We clear to grey but notice that we are using a hexidecimal
  301.     'number to represent Alpha Red Green and blue
  302.     D3DUtil_ClearAll &HFF808080
  303.     'set the ambient lighting level
  304.     g_dev.SetRenderState D3DRS_AMBIENT, &HFFC0C0C0
  305.     g_dev.BeginScene
  306.         
  307.         
  308.     'only render objects underneath the xzplane
  309.     m_quad1.Enabled = False
  310.     m_quad2.Enabled = True
  311.     m_XZPlaneFrame.Enabled = False
  312.     m_graphroot.Render g_dev
  313.     'render the objects in front of xz plane
  314.     m_quad1.Enabled = True
  315.     m_quad2.Enabled = False
  316.     m_XZPlaneFrame.Enabled = False
  317.     m_graphroot.Render g_dev
  318.     'DrawLines 0
  319.     'draw pop up text
  320.     If m_drawtextEnable Then
  321.         m_font.Begin
  322.         g_d3dx.DrawText m_font, &HFF000000, m_drawtext, m_drawtextpos, 0
  323.         m_font.End
  324.     End If
  325.     'render the xzplane with transparency
  326.     If m_bShowBase Then
  327.         m_quad1.Enabled = False
  328.         m_quad2.Enabled = False
  329.         m_XZPlaneFrame.Enabled = True
  330.         m_graphroot.Render g_dev
  331.     End If
  332.     g_dev.EndScene
  333.     D3DUtil_PresentAll m_hwnd
  334. End Sub
  335. Public Sub BuildGraph()
  336.     If Not m_binit Then Exit Sub
  337.     Dim entry As DataEntry
  338.     Dim material As D3DMATERIAL8
  339.     Dim newFrame As CD3DFrame
  340.     Dim mesh As D3DXMesh
  341.     Dim frameMesh As CD3DMesh
  342.     Dim i As Long, j As Long
  343.     Dim w As Single, h As Single
  344.     Dim sv As Single, ev As Single
  345.     Dim su As Single, eu As Single
  346.     Dim d3ddm As D3DDISPLAYMODE
  347.     If m_binit = False Then Exit Sub
  348.     Set m_graphroot = Nothing
  349.     Set m_quad1 = Nothing
  350.     Set m_quad2 = Nothing
  351.     'Create rotatable root object
  352.     Set m_graphroot = D3DUtil_CreateFrame(Nothing)
  353.                 
  354.     'Create XZ plane for reference
  355.     material.diffuse = LONGtoD3DCOLORVALUE(&H6FC0C0C0)
  356.     material.Ambient = material.diffuse
  357.     Set m_XZPlaneFrame = D3DUtil_CreateFrame(m_graphroot)
  358.     m_XZPlaneFrame.AddD3DXMesh(m_meshplane).SetMaterialOverride material
  359.     m_XZPlaneFrame.SetOrientation D3DUtil_RotationAxis(1, 0, 0, 90)
  360.     Set m_quad1 = D3DUtil_CreateFrame(m_graphroot)
  361.     Set m_quad2 = D3DUtil_CreateFrame(m_graphroot)
  362.     Dim rc As RECT
  363.     Dim surf As Direct3DSurface8
  364.     Dim rts As D3DXRenderToSurface
  365.     Dim rtsviewport As D3DVIEWPORT8
  366.     Call g_dev.GetDisplayMode(d3ddm)
  367.     Set rts = g_d3dx.CreateRenderToSurface(g_dev, kdx, kdy, d3ddm.format, 1, D3DFMT_D16)
  368.     rtsviewport.height = kdx
  369.     rtsviewport.width = kdy
  370.     rtsviewport.MaxZ = 1
  371.     Set surf = m_Tex.GetSurfaceLevel(0)
  372.           
  373.     rts.BeginScene surf, rtsviewport
  374.     g_dev.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &HFFC0C0C0, 1, 0
  375.     g_d3dx.DrawText m_font2, &HFF000000, "XXX", rc, DT_CALCRECT
  376.     m_font2height = rc.bottom
  377.     i = 0
  378.     Dim item As Variant
  379.     For Each item In m_RowLabels
  380.         If m_font2height * i >= kdy Then Exit For
  381.         rc.Top = m_font2height * i: rc.Left = 10: rc.bottom = 0: rc.Right = 0
  382.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, DT_CALCRECT
  383.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, 0
  384.         i = i + 1
  385.     Next
  386.     For Each item In m_ColLabels
  387.         If m_font2height * i >= kdy Then Exit For
  388.         rc.Top = m_font2height * i: rc.Left = 10: rc.bottom = 0: rc.Right = 0
  389.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, DT_CALCRECT
  390.         g_d3dx.DrawText m_font2, &HFF000000, item, rc, 0
  391.         i = i + 1
  392.     Next
  393.     rts.EndScene
  394.     i = 0
  395.     Dim quadframe As CD3DFrame
  396.     ReDim m_barmesh(0)
  397.     For Each entry In m_data
  398.         If entry.y >= 0 Then Set quadframe = m_quad1
  399.         If entry.y < 0 Then Set quadframe = m_quad2
  400.                 
  401.         'Set material of objects
  402.         material.diffuse = LONGtoD3DCOLORVALUE(entry.color)
  403.         material.Ambient = material.diffuse
  404.                 
  405.         'Create individual objects
  406.         Set newFrame = D3DUtil_CreateFrame(quadframe)
  407.         newFrame.SetScale 1
  408.         newFrame.SetPosition vec3(entry.x, entry.y / 2, entry.z)
  409.         
  410.         ReDim Preserve m_barmesh(i)
  411.         Set m_barmesh(i) = g_d3dx.CreateBox(g_dev, m_sizex, Abs(entry.y), m_sizez, Nothing)
  412.         newFrame.AddD3DXMesh(m_barmesh(i)).SetMaterialOverride material
  413.         
  414.         
  415.         
  416.         i = i + 1
  417.         newFrame.ObjectName = Str(i)
  418.     Next
  419.         
  420.     Dim strLabel As Variant
  421.         
  422.     w = m_sizex * 3:  h = 0.5
  423.     i = 0
  424.     If Not (m_cols = 0 Or m_rows = 0) Then
  425.         ReDim m_labelmesh(m_rows + m_cols)
  426.         ReDim m_LabelTex(m_rows + m_cols)
  427.         
  428.         For Each strLabel In m_ColLabels
  429.         
  430.         i = i + 1
  431.         
  432.         su = 0: eu = 0.5:
  433.         sv = (m_font2height * (i - 1) / kdy)
  434.         ev = (m_font2height * (i) / kdy)
  435.                                     
  436.         Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  437.         newFrame.ObjectName = strLabel
  438.         newFrame.SetPosition vec3(5.5, -h / 2, (i - m_maxZ / 2 - 1) * m_scalez)
  439.         newFrame.AddRotation COMBINE_BEFORE, 0, 1, 0, g_pi / 2
  440.         m_graphroot.AddChild newFrame
  441.         
  442.         Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  443.         newFrame.ObjectName = strLabel
  444.         newFrame.SetPosition vec3(-5.5, 5 - h / 2, (i - m_maxZ / 2 - 1) * m_scalez)
  445.         newFrame.AddRotation COMBINE_BEFORE, 0, 1, 0, g_pi / 2
  446.         m_graphroot.AddChild newFrame
  447.         
  448.         su = 0: eu = 1: sv = 0: ev = 1
  449.         
  450.         LoadTexture i, m_RowTextures(i)    'note row and col texture are swapped
  451.         
  452.         If Not m_LabelTex(i) Is Nothing Then
  453.                 Set newFrame = CreateSheetWithTextureCoords(w, w, su, eu, sv, ev, m_LabelTex(i))
  454.                 newFrame.ObjectName = strLabel + " picture"
  455.                 newFrame.SetPosition vec3(5.5, -h - w / 2, (i - m_maxZ / 2 - 1) * m_scalez)
  456.                 newFrame.AddRotation COMBINE_BEFORE, 0, 1, 0, g_pi / 2
  457.                 m_graphroot.AddChild newFrame
  458.             End If
  459.              
  460.         Next
  461.         
  462.         j = 0
  463.         For Each strLabel In m_RowLabels
  464.              Set newFrame = D3DUtil_CreateFrame(m_graphroot)
  465.              i = i + 1: j = j + 1
  466.              
  467.              
  468.              su = 0: eu = 0.5:
  469.              sv = (m_font2height * (i - 1) / kdy)
  470.              ev = (m_font2height * (i) / kdy)
  471.                                              
  472.              Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  473.              newFrame.ObjectName = strLabel
  474.              newFrame.SetPosition vec3((j - m_maxX / 2 - 1) * m_scalex, -h / 2, -5.5)
  475.              m_graphroot.AddChild newFrame
  476.              
  477.              Set newFrame = CreateSheetWithTextureCoords(w, h, su, eu, sv, ev, m_Tex)
  478.              newFrame.ObjectName = strLabel
  479.              newFrame.SetPosition vec3((j - m_maxX / 2 - 1) * m_scalex, 5 - h / 2, 5.5)
  480.              m_graphroot.AddChild newFrame
  481.              
  482.              su = 0: eu = 1: sv = 0: ev = 1
  483.              
  484.              LoadTexture i, m_ColTextures(j)    'note row and col texture are swapped
  485.              
  486.              If Not m_LabelTex(i) Is Nothing Then
  487.                 Set newFrame = CreateSheetWithTextureCoords(w, w, su, eu, sv, ev, m_LabelTex(i))
  488.                 newFrame.ObjectName = strLabel + " picture"
  489.                 newFrame.SetPosition vec3((j - m_maxX / 2 - 1) * m_scalex, -h - w / 2, -5.5)
  490.                 m_graphroot.AddChild newFrame
  491.             End If
  492.         Next
  493.     End If
  494.         
  495.     m_bGraphInit = True
  496. End Sub
  497. Public Sub InitDeviceObjects()
  498.     Dim d3ddm As D3DDISPLAYMODE
  499.     If m_binit = False Then Exit Sub
  500.     Dim rc As RECT
  501.     Set m_meshobj = g_d3dx.CreateBox(g_dev, 0.1, 0.1, 0.1, Nothing)
  502.     Set m_meshplane = g_d3dx.CreateBox(g_dev, 10, 10, 0.1, Nothing)
  503.     Call g_dev.GetDisplayMode(d3ddm)
  504.     Set m_Tex = g_d3dx.CreateTexture(g_dev, kdx, kdx, 0, 0, d3ddm.format, D3DPOOL_MANAGED)
  505.     Set m_font = g_d3dx.CreateFont(g_dev, m_vbfont.hFont)
  506.     Set m_font2 = g_d3dx.CreateFont(g_dev, m_vbfont2.hFont)
  507.        
  508.        
  509. End Sub
  510. Private Sub DrawLines(quad As Long)
  511.     g_dev.SetTransform D3DTS_WORLD, m_graphroot.GetMatrix
  512.     DrawLine vec3(-5, 0.1, 0), vec3(5, 0.1, 0), &HFF0&
  513.     DrawLine vec3(0, 0.1, -5), vec3(0, 0.1, 5), &HFF0&
  514. End Sub
  515. Private Sub DrawLine(v1 As D3DVECTOR, v2 As D3DVECTOR, color As Long)
  516.     Dim mat As D3DMATERIAL8
  517.     mat.diffuse = LONGtoD3DCOLORVALUE(color)
  518.     mat.Ambient = mat.diffuse
  519.     g_dev.SetMaterial mat
  520.     Dim dataOut(2) As D3DVERTEX
  521.     LSet dataOut(0) = v1
  522.     LSet dataOut(1) = v2
  523.     g_dev.SetVertexShader D3DFVF_VERTEX
  524.     g_dev.DrawPrimitiveUP D3DPT_LINELIST, 1, dataOut(0), Len(dataOut(0))
  525. End Sub
  526. Public Sub MouseOver(Button As Integer, Shift As Integer, x As Single, y As Single)
  527.     If m_binit = False Then Exit Sub
  528.         
  529.     Dim pick As New CD3DPick
  530.     Dim frame As CD3DFrame
  531.     Dim nid As Long
  532.     Dim entry As DataEntry
  533.     'remove the XZ plane from consideration for pick
  534.     m_XZPlaneFrame.Enabled = False
  535.     m_quad1.Enabled = True
  536.     m_quad2.Enabled = True
  537.     pick.ViewportPick m_graphroot, x, y
  538.     nid = pick.FindNearest()
  539.     If nid < 0 Then
  540.         m_drawtextEnable = False
  541.         Exit Sub
  542.     End If
  543.         
  544.     Set frame = pick.GetFrame(nid)
  545.     'have matrices pre computed for scene graph
  546.     m_graphroot.UpdateFrames
  547.     'due some math to get position of item in screen space
  548.     Dim viewport As D3DVIEWPORT8
  549.     Dim projmatrix As D3DMATRIX
  550.     Dim viewmatrix As D3DMATRIX
  551.     Dim vOut As D3DVECTOR
  552.     g_dev.GetViewport viewport
  553.     g_dev.GetTransform D3DTS_PROJECTION, projmatrix
  554.     g_dev.GetTransform D3DTS_VIEW, viewmatrix
  555.     D3DXVec3Project vOut, vec3(0, 0, 0), viewport, projmatrix, viewmatrix, frame.GetUpdatedMatrix
  556.             
  557.     Debug.Print vOut.x, vOut.y, frame.ObjectName
  558.     Dim destRect As RECT
  559.     m_drawtextpos.Left = x - 20
  560.     m_drawtextpos.Top = y - 70
  561.     If m_drawtextpos.Left < 0 Then m_drawtextpos.Left = 1
  562.     If m_drawtextpos.Top < 0 Then m_drawtextpos.Top = 1
  563.     Dim iOver As Long
  564.     If IsNumeric(frame.ObjectName) Then
  565.         iOver = val(frame.ObjectName)
  566.         Set entry = m_data.item(iOver)
  567.         With entry
  568.             m_drawtext = .dataname + Chr(13)
  569.         End With
  570.         m_drawtextEnable = True
  571.     End If
  572. End Sub
  573. Sub FrameMove()
  574.     'for camera movement
  575.     m_fElapsedTime = DXUtil_Timer(TIMER_GETELLAPSEDTIME) * 1.3
  576.     If m_fElapsedTime < 0 Then Exit Sub
  577.         
  578.         
  579.     If m_bRot And m_bMouseDown = False Then
  580.         m_graphroot.AddRotation COMBINE_BEFORE, 0, 1, 0, (g_pi / 40) * m_fElapsedTime
  581.     End If
  582.         
  583.         
  584.     ' Slow things down for the REF device
  585.     If (g_devType = D3DDEVTYPE_REF) Then m_fElapsedTime = 0.05
  586.     Dim fSpeed As Single
  587.     Dim fAngularSpeed
  588.     fSpeed = 5 * m_fElapsedTime
  589.     fAngularSpeed = 1 * m_fElapsedTime
  590.     ' Slowdown the camera movement
  591.     D3DXVec3Scale m_vVelocity, m_vVelocity, 0.9
  592.     m_fYawVelocity = m_fYawVelocity * 0.9
  593.     m_fPitchVelocity = m_fPitchVelocity * 0.9
  594.     ' Process keyboard input
  595.     If (m_bKey(vbKeyRight)) Then m_vVelocity.x = m_vVelocity.x + fSpeed        '  Slide Right
  596.     If (m_bKey(vbKeyLeft)) Then m_vVelocity.x = m_vVelocity.x - fSpeed         '  Slide Left
  597.     If (m_bKey(vbKeyUp)) Then m_vVelocity.y = m_vVelocity.y + fSpeed           '  Move up
  598.     If (m_bKey(vbKeyDown)) Then m_vVelocity.y = m_vVelocity.y - fSpeed         '  Move down
  599.     If (m_bKey(vbKeyW)) Then m_vVelocity.z = m_vVelocity.z + fSpeed            '  Move Forward
  600.     If (m_bKey(vbKeyS)) Then m_vVelocity.z = m_vVelocity.z - fSpeed            '  Move Backward
  601.     If (m_bKey(vbKeyE)) Then m_fYawVelocity = m_fYawVelocity + fSpeed          '  Yaw right
  602.     If (m_bKey(vbKeyQ)) Then m_fYawVelocity = m_fYawVelocity - fSpeed          '  Yaw left
  603.     If (m_bKey(vbKeyZ)) Then m_fPitchVelocity = m_fPitchVelocity + fSpeed      '  turn down
  604.     If (m_bKey(vbKeyA)) Then m_fPitchVelocity = m_fPitchVelocity - fSpeed      '  turn up
  605.     ' Update the position vector
  606.     Dim vT As D3DVECTOR, vTemp As D3DVECTOR
  607.     D3DXVec3Scale vTemp, m_vVelocity, fSpeed
  608.     D3DXVec3Add vT, vT, vTemp
  609.     D3DXVec3TransformNormal vT, vT, m_matOrientation
  610.     D3DXVec3Add m_vPosition, m_vPosition, vT
  611.     If (m_vPosition.y < 1) Then m_vPosition.y = 1
  612.     ' Update the yaw-pitch-rotation vector
  613.     m_fYaw = m_fYaw + fAngularSpeed * m_fYawVelocity
  614.     m_fPitch = m_fPitch + fAngularSpeed * m_fPitchVelocity
  615.     If (m_fPitch < 0) Then m_fPitch = 0
  616.     If (m_fPitch > g_pi / 2) Then m_fPitch = g_pi / 2
  617.     Dim qR As D3DQUATERNION, det As Single
  618.     D3DXQuaternionRotationYawPitchRoll qR, m_fYaw, m_fPitch, 0
  619.     D3DXMatrixAffineTransformation m_matOrientation, 1.25, vec3(0, 0, 0), qR, m_vPosition
  620.     D3DXMatrixInverse m_matView, det, m_matOrientation
  621.         'set new view matrix
  622.     g_dev.SetTransform D3DTS_VIEW, m_matView
  623. End Sub
  624. Private Sub DirectXEvent8_DXCallback(ByVal i As Long)
  625.     Dim w As Single
  626.     Dim h As Single
  627.     Dim w1 As Single, w2 As Single
  628.     Dim h1 As Single, h2 As Single
  629.     Dim sv As Single, ev As Single
  630.     Dim su As Single, eu As Single
  631.     Dim mat As D3DMATERIAL8
  632.                   
  633.     w = m_sizex * 1.4:  h = 0.4
  634.         
  635.     mat.Ambient = ColorValue4(1, 1, 1, 1)
  636.     mat.diffuse = ColorValue4(1, 1, 1, 1)
  637.         
  638.     sv = (m_font2height * (i) / kdy)
  639.     ev = (m_font2height * (i + 1) / kdy)
  640.     'g_dev.SetTexture 0, m_Tex
  641.     'g_dev.SetMaterial mat
  642.     DrawLine vec3(1, 1, 1), vec3(0, 0, 0), &HFF00FF00
  643.     w = m_sizex * 1.4:  h = 0.4
  644.     'DrawSheet -w, w, -2 * h, 0, 0, 0.5, sv, ev
  645.     'g_dev.SetTexture 0, m_LabelTex(i + 1)
  646.     'DrawSheet -w, w, -2 * h - 2 * w, -2 * h, 0, 1, 0, 1
  647. End Sub
  648. 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
  649.     Dim frame As CD3DFrame
  650.     Dim mesh As CD3DMesh
  651.     Dim retd3dxMesh As D3DXMesh
  652.     Dim vertexbuffer As Direct3DVertexBuffer8
  653.     Dim verts(8) As D3DVERTEX
  654.     Dim indices(12) As Integer
  655.     Dim w As Single, d As Single, h1 As Single, h2 As Single
  656.     w = width / 2
  657.     h2 = height / 2
  658.     h1 = -height / 2
  659.     d = 0.01
  660.     Dim whitematerial As D3DMATERIAL8
  661.     whitematerial.diffuse = ColorValue4(1, 1, 1, 1)
  662.     whitematerial.Ambient = whitematerial.diffuse
  663.         
  664.     'Create an empty d3dxmesh with room for 12 vertices and 12
  665.     Set retd3dxMesh = g_d3dx.CreateMeshFVF(8, 12, D3DXMESH_MANAGED, D3DFVF_VERTEX, g_dev)
  666.     'front face
  667.     'add vertices
  668.     With verts(0): .x = -w: .y = h2: .z = -d: .nz = 1: .tu = su: .tv = sv: End With
  669.     With verts(1): .x = w: .y = h2: .z = -d: .nz = 1: .tu = eu: .tv = sv: End With
  670.     With verts(2): .x = w: .y = h1: .z = -d: .nz = 1: .tu = eu: .tv = ev: End With
  671.     With verts(3): .x = -w: .y = h1: .z = -d: .nz = 1: .tu = su: .tv = ev: End With
  672.     'connect verices to make 2 triangles per face
  673.     indices(0) = 0: indices(1) = 1: indices(2) = 2
  674.     indices(3) = 0: indices(4) = 2: indices(5) = 3
  675.     'back face
  676.     With verts(4): .x = -w: .y = h1: .z = d: .nz = -1: .tu = eu: .tv = ev: End With
  677.     With verts(5): .x = w: .y = h1: .z = d: .nz = -1: .tu = su: .tv = ev: End With
  678.     With verts(6): .x = w: .y = h2: .z = d: .nz = -1: .tu = su: .tv = sv: End With
  679.     With verts(7): .x = -w: .y = h2: .z = d: .nz = -1: .tu = eu: .tv = sv: End With
  680.     indices(6) = 4: indices(7) = 5: indices(8) = 6
  681.     indices(9) = 4: indices(10) = 6: indices(11) = 7
  682.         
  683.     D3DXMeshVertexBuffer8SetData retd3dxMesh, 0, Len(verts(0)) * 8, 0, verts(0)
  684.     D3DXMeshIndexBuffer8SetData retd3dxMesh, 0, Len(indices(0)) * 12, 0, indices(0)
  685.         
  686.     Set frame = New CD3DFrame
  687.     Set mesh = frame.AddD3DXMesh(retd3dxMesh)
  688.     mesh.bUseMaterials = True
  689.     mesh.SetMaterialCount 1
  690.     mesh.SetMaterial 0, whitematerial
  691.     mesh.SetMaterialTexture 0, texture
  692.     Set CreateSheetWithTextureCoords = frame
  693. End Function
  694. 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)
  695.     Dim verts(4) As D3DVERTEX
  696.     g_dev.SetTexture 0, Nothing
  697.     With verts(0): .x = w1: .y = h1: .tu = su: .tv = ev: .nz = -1: End With
  698.     With verts(1): .x = w2: .y = h1: .tu = eu: .tv = ev: .nz = -1: End With
  699.     With verts(2): .x = w2: .y = h2: .tu = eu: .tv = sv: .nz = -1: End With
  700.     With verts(3): .x = w1: .y = h2: .tu = su: .tv = sv: .nz = -1: End With
  701.     'g_dev.SetVertexShader D3DFVF_VERTEX
  702.     'g_dev.DrawPrimitiveUP D3DPT_TRIANGLEFAN, 2, verts(0), Len(verts(0))
  703.     With verts(0): .z = 0.01: .x = w2: .y = h1: .tu = su: .tv = ev: .nz = 1: End With
  704.     With verts(1): .z = 0.01: .x = w1: .y = h1: .tu = eu: .tv = ev: .nz = 1: End With
  705.     With verts(2): .z = 0.01: .x = w1: .y = h2: .tu = eu: .tv = sv: .nz = 1: End With
  706.     With verts(3): .z = 0.01: .x = w2: .y = h2: .tu = su: .tv = sv: .nz = 1: End With
  707.     'g_dev.SetVertexShader D3DFVF_VERTEX
  708.     'g_dev.DrawPrimitiveUP D3DPT_TRIANGLEFAN, 2, verts(0), Len(verts(0))
  709. End Sub
  710. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  711.     m_bKey(KeyCode) = True
  712. End Sub
  713. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  714.     m_bKey(KeyCode) = False
  715. End Sub
  716. Private Sub Form_Load()
  717.     Me.Show
  718.     DoEvents
  719.     m_mediadir = FindMediaDir("bargraphdata.csv")
  720.     D3DUtil_SetMediaPath m_mediadir
  721.     Init Me.hwnd, Me.font, Command1.font
  722.     'Start the timers and callbacks
  723.     Call DXUtil_Timer(TIMER_start)
  724.     Timer1.Enabled = True
  725. End Sub
  726. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  727.     If Button = 2 Then
  728.         Me.PopupMenu MENU_POPUP
  729.     Else
  730.         '- save our current position
  731.         m_bMouseDown = True
  732.         m_lastX = x
  733.         m_lasty = y
  734.         
  735.     End If
  736. End Sub
  737. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  738.         
  739.     If m_binit = False Then Exit Sub
  740.     If Button = 2 Then Exit Sub
  741.     If m_bMouseDown = False Then
  742.         Call MouseOver(Button, Shift, x, y)
  743.     Else
  744.         '- Rotate the object
  745.         RotateTrackBall CInt(x), CInt(y)
  746.     End If
  747.     FrameMove
  748.     DrawGraph
  749. End Sub
  750. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  751.     m_bMouseDown = False
  752. End Sub
  753. '-----------------------------------------------------------------------------
  754. ' Name: Form_Resize()
  755. ' Desc: hadle resizing of the D3D backbuffer
  756. '-----------------------------------------------------------------------------
  757. Private Sub Form_Resize()
  758.     Timer1.Enabled = False
  759.     ' If D3D is not initialized then exit
  760.     If Not m_binit Then Exit Sub
  761.     ' If we are in a minimized state stop the timer and exit
  762.     If Me.WindowState = vbMinimized Then
  763.         DXUtil_Timer TIMER_STOP
  764.         m_bMinimized = True
  765.         Exit Sub
  766.         
  767.     ' If we just went from a minimized state to maximized
  768.     ' restart the timer
  769.     Else
  770.         If m_bMinimized = True Then
  771.             DXUtil_Timer TIMER_start
  772.             m_bMinimized = False
  773.         End If
  774.     End If
  775.         
  776.      ' Dont let the window get too small
  777.     If Me.ScaleWidth < 10 Then
  778.         Me.width = Screen.TwipsPerPixelX * 10
  779.         Exit Sub
  780.     End If
  781.     If Me.ScaleHeight < 10 Then
  782.         Me.height = Screen.TwipsPerPixelY * 10
  783.         Exit Sub
  784.     End If
  785.     'remove references to FONTs
  786.     DeleteDeviceObjects
  787.     'reset and resize our D3D backbuffer to the size of the window
  788.     D3DUtil_ResizeWindowed Me.hwnd
  789.     'All state get losts after a reset so we need to reinitialze it here
  790.     RestoreDeviceObjects
  791.     Timer1.Enabled = True
  792. End Sub
  793. '- Rotate Track ball
  794. '  given a point on the screen the mouse was moved to
  795. '  simulate a track ball
  796. Private Sub RotateTrackBall(x As Integer, y As Integer)
  797.     Dim delta_x As Single, delta_y As Single
  798.     Dim delta_r As Single, radius As Single, denom As Single, angle As Single
  799.     ' rotation axis in camcoords, worldcoords, sframecoords
  800.     Dim axisC As D3DVECTOR
  801.     Dim wc As D3DVECTOR
  802.     Dim axisS As D3DVECTOR
  803.     Dim base As D3DVECTOR
  804.     Dim origin As D3DVECTOR
  805.     delta_x = x - m_lastX
  806.     delta_y = y - m_lasty
  807.     m_lastX = x
  808.     m_lasty = y
  809.             
  810.      delta_r = Sqr(delta_x * delta_x + delta_y * delta_y)
  811.      radius = 50
  812.      denom = Sqr(radius * radius + delta_r * delta_r)
  813.     If (delta_r = 0 Or denom = 0) Then Exit Sub
  814.     angle = (delta_r / denom)
  815.     axisC.x = (-delta_y / delta_r)
  816.     axisC.y = (-delta_x / delta_r)
  817.     axisC.z = 0
  818.     'transform camera space vector to world space
  819.     'm_largewindow.m_cameraFrame.Transform wc, axisC
  820.     g_dev.GetTransform D3DTS_VIEW, g_viewMatrix
  821.     D3DXVec3TransformCoord wc, axisC, g_viewMatrix
  822.     'transform world space vector into Model space
  823.     m_graphroot.UpdateFrames
  824.     axisS = m_graphroot.InverseTransformCoord(wc)
  825.         
  826.     'transform origen camera space to world coordinates
  827.     'm_largewindow.m_cameraFrame.Transform  wc, origin
  828.     D3DXVec3TransformCoord wc, origin, g_viewMatrix
  829.     'transfer cam space origen to model space
  830.     base = m_graphroot.InverseTransformCoord(wc)
  831.     axisS.x = axisS.x - base.x
  832.     axisS.y = axisS.y - base.y
  833.     axisS.z = axisS.z - base.z
  834.     m_graphroot.AddRotation COMBINE_BEFORE, axisS.x, axisS.y, axisS.z, angle
  835. End Sub
  836. Private Sub Form_Paint()
  837.     If Not m_binit Then Exit Sub
  838.     If Not m_bGraphInit Then Exit Sub
  839.     DrawGraph
  840. End Sub
  841. Private Sub Form_Unload(Cancel As Integer)
  842.     End
  843. End Sub
  844. Private Sub MENU_BASE_Click()
  845.     m_bShowBase = Not m_bShowBase
  846.     MENU_BASE.Checked = m_bShowBase
  847. End Sub
  848. Private Sub MENU_LOAD_Click()
  849.     Dim sFile As String
  850.     'Stop the timers and callbacks
  851.     Timer1.Enabled = False
  852.     CommonDialog1.FileName = ""
  853.     CommonDialog1.DefaultExt = "csv"
  854.     CommonDialog1.filter = "csv|*.csv"
  855.     CommonDialog1.InitDir = m_mediadir
  856.     'On Local Error Resume Next
  857.     CommonDialog1.ShowOpen
  858.     sFile = CommonDialog1.FileName
  859.     If sFile = "" Then Exit Sub
  860.     LoadFileAsBarGraph sFile
  861.     D3DUtil_Destory
  862.     DestroyDeviceObjects
  863.             
  864.     D3DUtil_Init Me.hwnd, True, 0, 0, D3DDEVTYPE_HAL, Nothing
  865.     InitDeviceObjects
  866.     ComputeDataExtents
  867.     BuildGraph
  868.     RestoreDeviceObjects
  869.     'restart the callbacks
  870.     DXUtil_Timer (TIMER_RESET)
  871.     DXUtil_Timer (TIMER_start)
  872.     Timer1.Enabled = True
  873. End Sub
  874. Private Sub MENU_RESET_Click()
  875.     m_graphroot.SetMatrix g_identityMatrix
  876.     m_vPosition = vec3(0, 0, -20)
  877.     m_fYaw = 0
  878.     m_fPitch = 0
  879.     Call D3DXMatrixTranslation(m_matOrientation, 0, 0, 0)
  880.     D3DUtil_SetupDefaultScene
  881.     g_dev.GetTransform D3DTS_VIEW, m_matView
  882. End Sub
  883. Private Sub MENU_ROTATE_Click()
  884.     m_bRot = Not m_bRot
  885.     MENU_ROTATE.Checked = m_bRot
  886. End Sub
  887. Private Sub Timer1_Timer()
  888.     If Not m_binit Then Exit Sub
  889.     FrameMove
  890.     DrawGraph
  891. End Sub
  892. Sub LoadFileAsBarGraph(sFile As String)
  893.     If Dir$(sFile) = "" Then
  894.         MsgBox "Unable to find " + sFile
  895.         Exit Sub
  896.     End If
  897.     Dim fl As Long
  898.     Dim strIn As String
  899.     Dim strTrim As String
  900.     Dim strFirstChar As String
  901.     Dim splitArray
  902.     Dim cols As Long
  903.     Dim bFoundData As Boolean
  904.     Dim bFoundHeader As Boolean
  905.     Dim sName As String
  906.     Dim x As Double
  907.     Dim y As Double
  908.     Dim z As Double
  909.     Dim i As Long
  910.     Dim olddata As Collection
  911.     Dim oldcolLabels As Collection
  912.     Dim oldRowLabels As Collection
  913.     Dim oldCols As Long
  914.     Dim oldRows As Long
  915.     Dim strRowLabel As String
  916.     Dim strColLabel As String
  917.     Dim valout As Variant
  918.     Dim strName As String
  919.     Dim sizeout As Single
  920.     Dim colorout As Long
  921.     fl = FreeFile
  922.         
  923.     'On Local Error GoTo errOut
  924.     Set olddata = m_data
  925.     Set oldcolLabels = m_ColLabels
  926.     Set oldRowLabels = m_RowLabels
  927.     oldCols = m_cols
  928.     oldRows = m_rows
  929.     Set m_data = Nothing
  930.     Set m_data = New Collection
  931.     m_cols = 0
  932.     m_rows = 0
  933.     Set m_ColLabels = New Collection
  934.     Set m_RowLabels = New Collection
  935.     Open sFile For Input As fl
  936.         
  937.     Do While Not EOF(fl)
  938.         Line Input #fl, strIn
  939.         strTrim = Trim(strIn)
  940.         
  941.         'skip comment lines
  942.         strFirstChar = Mid$(strTrim, 1, 1)
  943.         If strFirstChar = "#" Or strFirstChar = ";" Then GoTo nextLine
  944.         If strTrim = "" Then GoTo nextLine
  945.         
  946.         splitArray = Split(strTrim, ",")
  947.         
  948.         cols = UBound(splitArray) + 1
  949.         If cols < 2 Then
  950.             MsgBox "Comma delimited file must have at least a header row, header column, and data"
  951.             GoTo closeOut
  952.         End If
  953.                 
  954.         Dim strData As String
  955.         Dim q As Long
  956.         
  957.         'If we have not found numbers see if we found a header row
  958.         If Not bFoundData Then
  959.             If IsNumeric(splitArray(1)) = False Then
  960.                 
  961.                 'assume data is a header row
  962.                 m_cols = cols
  963.                 
  964.                 m_GraphTitle = CStr(splitArray(0))
  965.                                 
  966.                 ReDim m_ColTextures(UBound(splitArray))
  967.                 
  968.                 For i = 1 To m_cols - 1
  969.                     strData = Trim(CStr(splitArray(i)))
  970.                     strColLabel = strData
  971.                     q = InStr(UCase(strData), "TEXTURE:")
  972.                     If q <> 0 Then
  973.                         m_ColTextures(i) = Mid$(strData, q + 8)
  974.                         If q > 1 Then strColLabel = Mid$(strData, 1, q - 1)
  975.                     End If
  976.                     m_ColLabels.Add strColLabel
  977.                 Next
  978.                 bFoundHeader = True
  979.                 GoTo nextLine
  980.             Else
  981.                 bFoundData = True
  982.                 If bFoundHeader = False Then
  983.                     MsgBox "Comma delimited file must have first for be header row to label columns"
  984.                     GoTo closeOut
  985.                 End If
  986.             End If
  987.         End If
  988.         
  989.         m_rows = m_rows + 1
  990.         strData = Trim(splitArray(0))
  991.         strRowLabel = strData
  992.         q = InStr(UCase(strData), "TEXTURE:")
  993.         ReDim Preserve m_RowTextures(m_rows)
  994.         If q <> 0 Then
  995.             m_RowTextures(m_rows) = Mid$(strData, q + 8)
  996.             If q > 1 Then strRowLabel = Mid$(strData, 1, q - 1)
  997.         End If
  998.         
  999.         m_RowLabels.Add strRowLabel
  1000.         
  1001.         sizeout = 1
  1002.         
  1003.         
  1004.         For i = 1 To m_cols - 1
  1005.             colorout = D3DCOLORVALUEtoLONG(ColorValue4(1, 1 - (2 + m_rows Mod 4) / 10, 0.2, 1 - ((i Mod 8)) / 10))
  1006.             strColLabel = m_ColLabels.item(i)
  1007.             valout = splitArray(i)
  1008.             strName = "(" + strRowLabel + "," + strColLabel + ") = " + CStr(valout)
  1009.             AddEntry strName, CDbl(i - 1), val(valout), CDbl(m_rows - 1), CDbl(sizeout), colorout, ""
  1010.         Next
  1011.         
  1012.         
  1013. nextLine:
  1014.     Loop
  1015.     Set olddata = Nothing
  1016.     Close fl
  1017.     m_sizex = (kScale / m_cols) * 0.5
  1018.     m_sizez = (kScale / m_rows) * 0.5
  1019.     Exit Sub
  1020. errOut:
  1021.     MsgBox "there was an error loading " + sFile
  1022. closeOut:
  1023.     'restore state
  1024.     Set m_data = olddata
  1025.     Set m_ColLabels = oldcolLabels
  1026.     Set m_RowLabels = oldRowLabels
  1027.     m_rows = oldRows
  1028.     m_cols = oldCols
  1029.     Close fl
  1030. End Sub
  1031. Function CreateBoxWithTextureCoords(width As Single, height As Single, depth As Single) As D3DXMesh
  1032.     Dim mesh As CD3DMesh
  1033.     Dim retd3dxMesh As D3DXMesh
  1034.     Dim vertexbuffer As Direct3DVertexBuffer8
  1035.     Dim verts(28) As D3DVERTEX
  1036.     Dim indices(36) As Integer
  1037.     Dim w As Single, d As Single, h1 As Single, h2 As Single
  1038.     w = width / 2
  1039.     h2 = height / 2
  1040.     h1 = -height / 2
  1041.     d = depth / 2
  1042.     'Create an empty d3dxmesh with room for 12 vertices and 12
  1043.     Set retd3dxMesh = g_d3dx.CreateMeshFVF(4 * 6, 6 * 6, D3DXMESH_MANAGED, D3DFVF_VERTEX, g_dev)
  1044.     'front face
  1045.     'add vertices
  1046.     With verts(0): .x = -w: .y = h2: .z = -d: .nz = 1: .tu = 0: .tv = 0: End With
  1047.     With verts(1): .x = w: .y = h2: .z = -d: .nz = 1: .tu = 1: .tv = 0: End With
  1048.     With verts(2): .x = w: .y = h1: .z = -d: .nz = 1: .tu = 1: .tv = 1: End With
  1049.     With verts(3): .x = -w: .y = h1: .z = -d: .nz = 1: .tu = 0: .tv = 1: End With
  1050.     'connect verices to make 2 triangles per face
  1051.     indices(0) = 0: indices(1) = 1: indices(2) = 2
  1052.     indices(3) = 0: indices(4) = 2: indices(5) = 3
  1053.     'back face
  1054.     With verts(4): .x = -w: .y = h1: .z = d: .nz = -1: .tu = 0: .tv = 1: End With
  1055.     With verts(5): .x = w: .y = h1: .z = d: .nz = -1: .tu = 1: .tv = 1: End With
  1056.     With verts(6): .x = w: .y = h2: .z = d: .nz = -1: .tu = 1: .tv = 0: End With
  1057.     With verts(7): .x = -w: .y = h2: .z = d: .nz = -1: .tu = 0: .tv = 0: End With
  1058.     indices(6) = 4: indices(7) = 5: indices(8) = 6
  1059.     indices(9) = 4: indices(10) = 6: indices(11) = 7
  1060.     'right face
  1061.     With verts(8): .x = w: .y = h1: .z = -d: .nx = -1: .tu = 0: .tv = 0: End With
  1062.     With verts(9): .x = w: .y = h1: .z = d: .nx = -1: .tu = 1: .tv = 0: End With
  1063.     With verts(10): .x = w: .y = h2: .z = d: .nx = -1: .tu = 1: .tv = 1: End With
  1064.     With verts(11): .x = w: .y = h2: .z = -d: .nx = -1: .tu = 0: .tv = 1: End With
  1065.     indices(12) = 8: indices(13) = 9: indices(14) = 10
  1066.     indices(15) = 8: indices(16) = 10: indices(17) = 11
  1067.     'left face
  1068.     With verts(16): .x = -w: .y = h2: .z = -d: .nx = 1: .tu = 0: .tv = 1: End With
  1069.     With verts(17): .x = -w: .y = h2: .z = d: .nx = 1: .tu = 1: .tv = 1: End With
  1070.     With verts(18): .x = -w: .y = h1: .z = d: .nx = 1: .tu = 1: .tv = 0: End With
  1071.     With verts(19): .x = -w: .y = h1: .z = -d: .nx = 1: .tu = 0: .tv = 0: End With
  1072.     indices(18) = 16: indices(19) = 17: indices(20) = 18
  1073.     indices(21) = 16: indices(22) = 18: indices(23) = 19
  1074.     'top face
  1075.     With verts(20): .x = -w: .y = h2: .z = -d: .ny = -1: .tu = 0: .tv = 0: End With
  1076.     With verts(21): .x = -w: .y = h2: .z = d: .ny = -1: .tu = 1: .tv = 0: End With
  1077.     With verts(22): .x = w: .y = h2: .z = d: .ny = -1: .tu = 1: .tv = 1: End With
  1078.     With verts(23): .x = w: .y = h2: .z = -d: .ny = -1: .tu = 0: .tv = 1: End With
  1079.     indices(24) = 20: indices(25) = 21: indices(26) = 22
  1080.     indices(27) = 20: indices(28) = 22: indices(29) = 23
  1081.         
  1082.     'bottom  face
  1083.     With verts(24): .x = w: .y = h1: .z = -d: .ny = 1: .tu = 0: .tv = 1: End With
  1084.     With verts(25): .x = w: .y = h1: .z = d: .ny = 1: .tu = 1: .tv = 1: End With
  1085.     With verts(26): .x = -w: .y = h1: .z = d: .ny = 1: .tu = 1: .tv = 0: End With
  1086.     With verts(27): .x = -w: .y = h1: .z = -d: .ny = 1: .tu = 0: .tv = 0: End With
  1087.     indices(30) = 24: indices(31) = 25: indices(32) = 26
  1088.     indices(33) = 24: indices(34) = 26: indices(35) = 27
  1089.         
  1090.     D3DXMeshVertexBuffer8SetData retd3dxMesh, 0, Len(verts(0)) * 28, 0, verts(0)
  1091.     D3DXMeshIndexBuffer8SetData retd3dxMesh, 0, Len(indices(0)) * 36, 0, indices(0)
  1092.         
  1093.         
  1094.     Set CreateBoxWithTextureCoords = retd3dxMesh
  1095. End Function
  1096. Sub LoadTexture(i As Long, strFile As String)
  1097.         
  1098.     If strFile = "" Then Exit Sub
  1099.     Set m_LabelTex(i) = D3DUtil.D3DUtil_CreateTextureInPool(g_dev, strFile, D3DFMT_R5G6B5)
  1100.     If m_LabelTex(i) Is Nothing Then
  1101.         MsgBox "Unable to find " + strFile
  1102.     End If
  1103. End Sub
  1104.