home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Form1
- BorderStyle = 1 'Fixed Single
- Caption = "LightSource Vector Example"
- ClientHeight = 6735
- ClientLeft = 1170
- ClientTop = 1515
- ClientWidth = 9435
- Height = 7200
- Icon = "sun32.frx":0000
- Left = 1080
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 6735
- ScaleWidth = 9435
- Top = 1140
- Width = 9615
- Begin VB.Frame Frame2
- Caption = " Set Vector By Time "
- Height = 1935
- Left = 7440
- TabIndex = 6
- Top = 3420
- Width = 1815
- Begin VB.CommandButton cmdSetTime
- Caption = "Set Time"
- Height = 315
- Left = 360
- TabIndex = 9
- Top = 1440
- Width = 1155
- End
- Begin VB.TextBox txtTime
- Height = 285
- Left = 360
- TabIndex = 7
- Text = "Time"
- Top = 960
- Width = 1155
- End
- Begin VB.Label Label1
- Caption = "0 = Midnight 0.5 = Noon"
- BeginProperty Font
- name = "Arial"
- charset = 0
- weight = 400
- size = 9
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 420
- TabIndex = 8
- Top = 360
- Width = 1155
- End
- End
- Begin VB.Frame Frame1
- Caption = " Light Vector "
- Height = 2115
- Left = 7440
- TabIndex = 2
- Top = 1020
- Width = 1815
- Begin VB.CommandButton cmdSetVector
- Caption = "Set Vector"
- Height = 315
- Left = 360
- TabIndex = 10
- Top = 1620
- Width = 1155
- End
- Begin VB.TextBox txtX
- Height = 285
- Left = 420
- TabIndex = 5
- Text = "X"
- Top = 420
- Width = 1215
- End
- Begin VB.TextBox txtZ
- Height = 285
- Left = 420
- TabIndex = 4
- Text = "Z"
- Top = 1140
- Width = 1215
- End
- Begin VB.TextBox txtY
- Height = 285
- Left = 420
- TabIndex = 3
- Text = "Y"
- Top = 780
- Width = 1215
- End
- Begin VB.Label Label2
- Caption = "Z:"
- Height = 255
- Index = 2
- Left = 180
- TabIndex = 13
- Top = 1200
- Width = 195
- End
- Begin VB.Label Label2
- Caption = "Y:"
- Height = 255
- Index = 1
- Left = 180
- TabIndex = 12
- Top = 840
- Width = 195
- End
- Begin VB.Label Label2
- Caption = "X:"
- Height = 255
- Index = 0
- Left = 180
- TabIndex = 11
- Top = 480
- Width = 195
- End
- End
- Begin VB.CommandButton cmdAnimate
- Caption = "Animate"
- Height = 435
- Left = 7800
- TabIndex = 1
- Top = 5760
- Width = 1155
- End
- Begin VCIFiLib.VtChart VtChart1
- Height = 6615
- Left = 60
- TabIndex = 0
- Top = 60
- Width = 7215
- _version = 65536
- _extentx = 12726
- _extenty = 11668
- _stockprops = 96
- borderstyle = 1
- filename = "sun32.frx":030A
- End
- Attribute VB_Name = "Form1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Sub LoadSufaceData(filename$)
- Dim rows%, cols%, i%, j%, junk$, value#
- On Error GoTo LoadSufaceDataError
- Open filename For Input As #1
- Input #1, junk, rows
- Input #1, junk, cols
- With VtChart1
- .RowCount = rows
- .ColumnCount = cols
- With .DataGrid
- For i = 1 To rows
- For j = 1 To cols
- Input #1, value
- .SetData i, j, value, False
- Next j
- Next i
- End With
- End With
- Close #1
-
- Exit Sub
- LoadSufaceDataError:
- MsgBox Error
- End Sub
- Sub FormatSurfaceChart()
- Dim i%, attr As Object
- With VtChart1
- .ChartType = VtChChartType3dSurface
- .Backdrop.Fill.Style = VtFillStyleBrush
- .Backdrop.Fill.Brush.FillColor.Set 64, 192, 192
-
- With .Plot
- .Light.EdgeVisible = False
- .Elevation.Surface.WireframePen.Style = VtPenStyleNull
- .Elevation.Surface.DisplayType = VtChSurfaceDisplayTypeCBands
- .PlotBase.BaseHeight = 0
- .Wall.Pen.Style = VtPenStyleNull
-
- .Axis(VtChAxisIdZ).AxisGrid.MajorPen.Style = VtPenStyleNull
- .Axis(VtChAxisIdZ).AxisScale.Hide = True
-
- .Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleNull
- .Axis(VtChAxisIdY).AxisScale.Hide = True
-
- .Axis(VtChAxisIdY2).AxisGrid.MajorPen.Style = VtPenStyleNull
- .Axis(VtChAxisIdY2).AxisScale.Hide = True
-
- .Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleNull
- .Axis(VtChAxisIdX).AxisScale.Hide = True
-
- .View3d.Set 58, 16
-
- With .Elevation
- '' Set up the contours
- .AutoValues = False
- .ColorType = VtChContourColorTypeManual
-
- With .Attributes
- For i = 1 To .Count - 5
- .Remove (i)
- Next i
-
- '' Set contour values and their color
- .Item(1).value = 0
- .Item(2).value = 0.01
- .Item(3).value = 43
- .Item(4).value = 43.5
- .Item(5).value = 50
-
- .Item(1).Brush.FillColor.Set 0, 0, 202
- .Item(2).Brush.FillColor.Set 0, 0, 202
- .Item(3).Brush.FillColor.Set 10, 128, 10
- .Item(4).Brush.FillColor.Set 210, 210, 210
- .Item(5).Brush.FillColor.Set 255, 255, 255
- End With
-
- For Each attr In .Attributes
- attr.Brush.Style = VtBrushStyleSolid
- Next attr
-
- End With
- End With
- End With
- End Sub
- Sub SetLightForTime(ch As Object, theTime!)
- '' Times are in the spreadsheet serial number format where
- '' 1 = a day so zero = midnight and 0.5 = noon. For trig
- '' functions Pi/2 = midnight and 3Pi/2 = noon. The code
- '' below maps time to light source coordinates. We also throw
- '' in some ambient intensity to simulate the reflected light
- '' during midday. Note that we are setting the direction
- '' of the sun's rays, not its position. See the associated
- '' readme for chart/light coordinate systems.
- Const r = 20
- Const HALFPI = 1.5708
- Dim radians!, x!, y!, z!
- radians = (theTime / 0.25) * HALFPI + HALFPI
- x = r * Cos(radians)
- y = r * Sin(radians)
- z = -0.1 + theTime
- ch.Plot.Light.LightSources.Item(1).Set x, y, z, 1
- ch.Plot.Light.AmbientIntensity = 1.25 * (IIf(theTime > 0.5, 1 - theTime, theTime))
- txtX.Text = Str(x)
- txtY.Text = Str(y)
- txtZ.Text = Str(z)
- End Sub
- Private Sub cmdAnimate_Click()
- Static when!
- For when = 0 To 1 Step 0.05
- SetLightForTime VtChart1, when
- txtTime.Text = Format(when, "hh:mm")
- DoEvents
- Next when
- End Sub
- Private Sub cmdSetTime_Click()
- Dim theTime!
- theTime = Val(txtTime.Text)
- If theTime >= 0 And theTime <= 1 Then
- txtTime.Text = Format(theTime, "hh:mm")
- SetLightForTime VtChart1, theTime
- Else
- MsgBox "Time must be a number between 0 and 1."
- End If
-
- End Sub
- Private Sub cmdSetVector_Click()
- VtChart1.Plot.Light.LightSources.Item(1).Set Val(txtX.Text), Val(txtY.Text), Val(txtZ.Text), 1
- End Sub
- Private Sub Form_Load()
- LoadSufaceData App.Path & "\surfdata.txt"
- FormatSurfaceChart
- End Sub
-