home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH10 / SRC / BEZIER.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-02  |  20.8 KB  |  693 lines

  1. VERSION 4.00
  2. Begin VB.Form BezierForm 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Bezier"
  6.    ClientHeight    =   5700
  7.    ClientLeft      =   300
  8.    ClientTop       =   840
  9.    ClientWidth     =   9105
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   6390
  21.    KeyPreview      =   -1  'True
  22.    Left            =   240
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   5700
  25.    ScaleWidth      =   9105
  26.    Top             =   210
  27.    Width           =   9225
  28.    Begin VB.OptionButton Choice 
  29.       Caption         =   "Urn"
  30.       Height          =   255
  31.       Index           =   8
  32.       Left            =   7080
  33.       TabIndex        =   18
  34.       Top             =   2880
  35.       Width           =   2055
  36.    End
  37.    Begin VB.OptionButton Choice 
  38.       Caption         =   "Tent"
  39.       Height          =   255
  40.       Index           =   2
  41.       Left            =   7080
  42.       TabIndex        =   17
  43.       Top             =   720
  44.       Width           =   2055
  45.    End
  46.    Begin VB.CheckBox ShowGridCheck 
  47.       Caption         =   "Show Control Grid"
  48.       Height          =   255
  49.       Left            =   7080
  50.       TabIndex        =   16
  51.       Top             =   3840
  52.       Width           =   2055
  53.    End
  54.    Begin VB.OptionButton Choice 
  55.       Caption         =   "Hill"
  56.       Height          =   255
  57.       Index           =   0
  58.       Left            =   7080
  59.       TabIndex        =   15
  60.       Top             =   0
  61.       Value           =   -1  'True
  62.       Width           =   2055
  63.    End
  64.    Begin VB.OptionButton Choice 
  65.       Caption         =   "Wave"
  66.       Height          =   255
  67.       Index           =   1
  68.       Left            =   7080
  69.       TabIndex        =   14
  70.       Top             =   360
  71.       Width           =   2055
  72.    End
  73.    Begin VB.OptionButton Choice 
  74.       Caption         =   "Curl"
  75.       Height          =   255
  76.       Index           =   3
  77.       Left            =   7080
  78.       TabIndex        =   13
  79.       Top             =   1080
  80.       Width           =   2055
  81.    End
  82.    Begin VB.OptionButton Choice 
  83.       Caption         =   "Pipe"
  84.       Height          =   255
  85.       Index           =   4
  86.       Left            =   7080
  87.       TabIndex        =   12
  88.       Top             =   1440
  89.       Width           =   2055
  90.    End
  91.    Begin VB.OptionButton Choice 
  92.       Caption         =   "Cowling"
  93.       Height          =   255
  94.       Index           =   5
  95.       Left            =   7080
  96.       TabIndex        =   11
  97.       Top             =   1800
  98.       Width           =   2055
  99.    End
  100.    Begin VB.OptionButton Choice 
  101.       Caption         =   "Twist"
  102.       Height          =   255
  103.       Index           =   6
  104.       Left            =   7080
  105.       TabIndex        =   10
  106.       Top             =   2160
  107.       Width           =   2055
  108.    End
  109.    Begin VB.OptionButton Choice 
  110.       Caption         =   "Spiral"
  111.       Height          =   255
  112.       Index           =   7
  113.       Left            =   7080
  114.       TabIndex        =   9
  115.       Top             =   2520
  116.       Width           =   2055
  117.    End
  118.    Begin VB.CheckBox ShowControlsCheck 
  119.       Caption         =   "Show Control Points"
  120.       Height          =   255
  121.       Left            =   7080
  122.       TabIndex        =   8
  123.       Top             =   3480
  124.       Width           =   2055
  125.    End
  126.    Begin VB.CheckBox ShowAxesCheck 
  127.       Caption         =   "Show Axes"
  128.       Height          =   255
  129.       Left            =   7080
  130.       TabIndex        =   7
  131.       Top             =   4200
  132.       Width           =   2055
  133.    End
  134.    Begin VB.TextBox PhiText 
  135.       Height          =   285
  136.       Left            =   3600
  137.       TabIndex        =   6
  138.       Text            =   "0.1570"
  139.       Top             =   5400
  140.       Width           =   855
  141.    End
  142.    Begin VB.TextBox ThetaText 
  143.       Height          =   285
  144.       Left            =   2040
  145.       TabIndex        =   4
  146.       Text            =   "0.6283"
  147.       Top             =   5400
  148.       Width           =   855
  149.    End
  150.    Begin VB.TextBox RText 
  151.       Height          =   285
  152.       Left            =   480
  153.       TabIndex        =   2
  154.       Text            =   "10"
  155.       Top             =   5400
  156.       Width           =   855
  157.    End
  158.    Begin VB.PictureBox Pict 
  159.       AutoRedraw      =   -1  'True
  160.       Height          =   5295
  161.       Left            =   0
  162.       ScaleHeight     =   349
  163.       ScaleMode       =   3  'Pixel
  164.       ScaleWidth      =   461
  165.       TabIndex        =   0
  166.       Top             =   0
  167.       Width           =   6975
  168.    End
  169.    Begin MSComDlg.CommonDialog LoadDialog 
  170.       Left            =   7080
  171.       Top             =   4800
  172.       _version        =   65536
  173.       _extentx        =   847
  174.       _extenty        =   847
  175.       _stockprops     =   0
  176.       cancelerror     =   -1  'True
  177.    End
  178.    Begin VB.Label Label1 
  179.       Caption         =   "Phi"
  180.       Height          =   255
  181.       Index           =   2
  182.       Left            =   3240
  183.       TabIndex        =   5
  184.       Top             =   5400
  185.       Width           =   375
  186.    End
  187.    Begin VB.Label Label1 
  188.       Caption         =   "Theta"
  189.       Height          =   255
  190.       Index           =   1
  191.       Left            =   1440
  192.       TabIndex        =   3
  193.       Top             =   5400
  194.       Width           =   495
  195.    End
  196.    Begin VB.Label Label1 
  197.       Caption         =   "R"
  198.       Height          =   255
  199.       Index           =   0
  200.       Left            =   240
  201.       TabIndex        =   1
  202.       Top             =   5400
  203.       Width           =   255
  204.    End
  205.    Begin VB.Menu mnuFile 
  206.       Caption         =   "&File"
  207.       Begin VB.Menu mnuFileLoad 
  208.          Caption         =   "&Load..."
  209.          Shortcut        =   ^L
  210.       End
  211.       Begin VB.Menu mnuFileSaveAs 
  212.          Caption         =   "&Save As..."
  213.          Shortcut        =   ^A
  214.       End
  215.       Begin VB.Menu mnuFileSep 
  216.          Caption         =   "-"
  217.       End
  218.       Begin VB.Menu mnuFileExit 
  219.          Caption         =   "E&xit"
  220.       End
  221.    End
  222. Attribute VB_Name = "BezierForm"
  223. Attribute VB_Creatable = False
  224. Attribute VB_Exposed = False
  225. Option Explicit
  226. ' Location of viewing eye.
  227. Dim EyeR As Single
  228. Dim EyeTheta As Single
  229. Dim EyePhi As Single
  230. Const Dtheta = PI / 20
  231. Const Dphi = PI / 20
  232. Const Dr = 1
  233. ' Location of focus point.
  234. Const FocusX = 0#
  235. Const FocusY = 0#
  236. Const FocusZ = 0#
  237. Dim Projector(1 To 4, 1 To 4) As Single
  238. Dim ThePicture As ObjPicture
  239. Dim TheSurface As ObjBezier
  240. Dim ShowingParameters As Boolean
  241. Dim ChoiceNum As Integer
  242. ' *******************************************************
  243. ' Rotate the points in the cube and draw the cube.
  244. ' *******************************************************
  245. Private Sub DrawData(pic As Object)
  246. Dim s(1 To 4, 1 To 4) As Single
  247. Dim t(1 To 4, 1 To 4) As Single
  248. Dim ST(1 To 4, 1 To 4) As Single
  249. Dim PST(1 To 4, 1 To 4) As Single
  250.     MousePointer = vbHourglass
  251.     Refresh
  252.     ' Prevent overflow errors when drawing lines
  253.     ' too far out of bounds.
  254.     On Error Resume Next
  255.     ' Scale and translate so it looks OK in pixels.
  256.     m3Scale s, 35, -35, 1
  257.     m3Translate t, 230, 175, 0
  258.     m3MatMultiplyFull ST, s, t
  259.     m3MatMultiplyFull PST, Projector, ST
  260.     ' Transform the points.
  261.     ThePicture.ApplyFull PST
  262.     ' Display the data.
  263.     pic.Cls
  264.     ThePicture.Draw pic, EyeR
  265.     pic.Refresh
  266.     ' Display the viewnig parameters.
  267.     ShowViewingParameters
  268.     MousePointer = vbDefault
  269. End Sub
  270. ' ************************************************
  271. ' Set the control points for a urn.
  272. ' ************************************************
  273. Sub MakeUrn()
  274. Dim r(1 To 5) As Single
  275. Dim h(1 To 5) As Single
  276. Dim i As Integer
  277.     TheSurface.SetBounds 5, 6
  278.     r(1) = 1
  279.     r(2) = 1
  280.     r(3) = 5
  281.     r(4) = 1.5
  282.     r(5) = 1.5
  283.     h(1) = 4
  284.     h(2) = 3.5
  285.     h(3) = 2
  286.     h(4) = -1
  287.     h(5) = -3
  288.         
  289.     For i = 1 To 5
  290.         TheSurface.SetControlPoint i, 1, -r(i), h(i), 0
  291.         TheSurface.SetControlPoint i, 2, -r(i), h(i), -1.5 * r(i)
  292.         TheSurface.SetControlPoint i, 3, 2 * r(i), h(i), -1.5 * r(i)
  293.         TheSurface.SetControlPoint i, 4, 2 * r(i), h(i), 1.5 * r(i)
  294.         TheSurface.SetControlPoint i, 5, -r(i), h(i), 1.5 * r(i)
  295.         TheSurface.SetControlPoint i, 6, -r(i), h(i), 0
  296.     Next i
  297. End Sub
  298. ' ************************************************
  299. ' Set the control points for a pipe.
  300. ' ************************************************
  301. Sub MakePipe()
  302. Const s = 3
  303. Dim i As Integer
  304. Dim x As Single
  305.     TheSurface.SetBounds 4, 6
  306.     For i = 1 To 4
  307.         x = 1.5 * (i - 2.5)
  308.         TheSurface.SetControlPoint i, 1, x, _
  309.             -s, 0
  310.         TheSurface.SetControlPoint i, 2, x, _
  311.             -s, -s
  312.         TheSurface.SetControlPoint i, 3, x, _
  313.             s, -s
  314.         TheSurface.SetControlPoint i, 4, x, _
  315.             s, s
  316.         TheSurface.SetControlPoint i, 5, x, _
  317.             -s, s
  318.         TheSurface.SetControlPoint i, 6, x, _
  319.             -s, 0
  320.     Next i
  321. End Sub
  322. ' ************************************************
  323. ' Set the control points for a curl.
  324. ' ************************************************
  325. Sub MakeCurl()
  326. Dim ang As Integer
  327. Dim j As Integer
  328. Dim r As Single
  329. Dim x As Single
  330. Dim y As Single
  331. Dim z As Single
  332.     TheSurface.SetBounds 4, 4
  333.     For j = 1 To 4
  334.         z = 1.5 * (j - 2.5)
  335.         r = 6 - Abs(2 * j - 5)
  336.         For ang = 1 To 4
  337.             x = r * Cos((ang - 1) * PI / 2)
  338.             y = r * Sin((ang - 1) * PI / 2)
  339.             TheSurface.SetControlPoint ang, j, x, y, z
  340.         Next ang
  341.     Next j
  342. End Sub
  343. ' ************************************************
  344. ' Set the control points for a wave.
  345. ' ************************************************
  346. Sub MakeWave()
  347. Dim i As Integer
  348. Dim j As Integer
  349.             
  350.     TheSurface.SetBounds 4, 4
  351.     ' Start flat and modify from there.
  352.     For i = 1 To 4
  353.         For j = 1 To 4
  354.             TheSurface.SetControlPoint i, j, 2 * i - 5, 0, 2 * j - 5
  355.         Next j
  356.     Next i
  357.     ' Make the modifications.
  358.     TheSurface.SetControlPoint 2, 2, -1, -10, -1
  359.     TheSurface.SetControlPoint 2, 3, -1, 10, 1
  360.     TheSurface.SetControlPoint 3, 2, 1, -10, -1
  361.     TheSurface.SetControlPoint 3, 3, 1, 10, 1
  362. End Sub
  363. ' ************************************************
  364. ' Set the control points for a tent.
  365. ' ************************************************
  366. Sub MakeTent()
  367.     TheSurface.SetBounds 3, 3
  368.     TheSurface.SetControlPoint 1, 1, -3, -2, -3
  369.     TheSurface.SetControlPoint 1, 2, -3, 2, 0
  370.     TheSurface.SetControlPoint 1, 3, -3, -2, 3
  371.     TheSurface.SetControlPoint 2, 1, 0, 2, -3
  372.     TheSurface.SetControlPoint 2, 2, 0, 4, 0
  373.     TheSurface.SetControlPoint 2, 3, 0, 2, 3
  374.     TheSurface.SetControlPoint 3, 1, 3, -2, -3
  375.     TheSurface.SetControlPoint 3, 2, 3, 2, 0
  376.     TheSurface.SetControlPoint 3, 3, 3, -2, 3
  377. End Sub
  378. ' ************************************************
  379. ' Set the control points for a spiral.
  380. ' ************************************************
  381. Sub MakeSpiral()
  382.     TheSurface.SetBounds 5, 2
  383.     TheSurface.SetControlPoint 1, 1, -4, 2, 0
  384.     TheSurface.SetControlPoint 1, 2, -4, -2, 0
  385.     TheSurface.SetControlPoint 2, 1, -2, 0, -4
  386.     TheSurface.SetControlPoint 2, 2, -2, 0, 4
  387.     TheSurface.SetControlPoint 3, 1, 0, -6, 0
  388.     TheSurface.SetControlPoint 3, 2, 0, 6, 0
  389.     TheSurface.SetControlPoint 4, 1, 2, 0, 4
  390.     TheSurface.SetControlPoint 4, 2, 2, 0, -4
  391.     TheSurface.SetControlPoint 5, 1, 4, 2, 0
  392.     TheSurface.SetControlPoint 5, 2, 4, -2, 0
  393. End Sub
  394. ' ************************************************
  395. ' Set the control points for a twist.
  396. ' ************************************************
  397. Sub MakeTwist()
  398.     TheSurface.SetBounds 2, 2
  399.     TheSurface.SetControlPoint 1, 1, -2, 3, 3
  400.     TheSurface.SetControlPoint 1, 2, -3, 3, -3
  401.     TheSurface.SetControlPoint 2, 1, 3, 4, -2
  402.     TheSurface.SetControlPoint 2, 2, 2, -3, 0
  403. End Sub
  404. ' ************************************************
  405. ' Set the control points for a cowling.
  406. ' ************************************************
  407. Sub MakeCowl()
  408. Dim i As Integer
  409. Dim s As Single
  410. Dim y As Single
  411.     TheSurface.SetBounds 4, 6
  412.     For i = 1 To 4
  413.         y = 3 - 2 * Abs(i - 2.5)
  414.         
  415.         s = 2 + i / 2
  416.         
  417.         TheSurface.SetControlPoint i, 1, _
  418.             1.25 * s - 1, y, 0
  419.         TheSurface.SetControlPoint i, 2, _
  420.             1.25 * s - 1, y, s
  421.         TheSurface.SetControlPoint i, 3, _
  422.             -s - 1, y, s
  423.         TheSurface.SetControlPoint i, 4, _
  424.             -s - 1, y, -s
  425.         TheSurface.SetControlPoint i, 5, _
  426.             1.25 * s - 1, y, -s
  427.         TheSurface.SetControlPoint i, 6, _
  428.             1.25 * s - 1, y, 0
  429.     Next i
  430. End Sub
  431. ' ************************************************
  432. ' Set the control points for a hill.
  433. ' ************************************************
  434. Sub MakeHill()
  435. Dim i As Integer
  436. Dim j As Integer
  437.             
  438.     TheSurface.SetBounds 4, 4
  439.     ' Start flat and modify from there.
  440.     For i = 1 To 4
  441.         For j = 1 To 4
  442.             TheSurface.SetControlPoint i, j, 2 * i - 5, 0, 2 * j - 5
  443.         Next j
  444.     Next i
  445.     ' Make the modifications.
  446.     TheSurface.SetControlPoint 2, 2, -1, 7, -1
  447.     TheSurface.SetControlPoint 2, 3, -1, 7, 1
  448.     TheSurface.SetControlPoint 3, 2, 1, 7, -1
  449.     TheSurface.SetControlPoint 3, 3, 1, 7, 1
  450. End Sub
  451. Sub ShowViewingParameters()
  452.     ShowingParameters = True
  453.     RText.Text = Format$(EyeR, "0.0000")
  454.     ThetaText.Text = Format$(EyeTheta, "0.0000")
  455.     PhiText.Text = Format$(EyePhi, "0.0000")
  456.     RText.Refresh
  457.     ThetaText.Refresh
  458.     PhiText.Refresh
  459.     ShowingParameters = False
  460. End Sub
  461. Private Sub Choice_Click(Index As Integer)
  462.     ChoiceNum = Index
  463.     CreateData (ShowAxesCheck.value = vbChecked)
  464.     DrawData Pict
  465.     Pict.SetFocus
  466. End Sub
  467. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  468.     Select Case KeyCode
  469.         Case vbKeyLeft
  470.             EyeTheta = EyeTheta - Dtheta
  471.         
  472.         Case vbKeyRight
  473.             EyeTheta = EyeTheta + Dtheta
  474.         
  475.         Case vbKeyUp
  476.             EyePhi = EyePhi - Dphi
  477.         
  478.         Case vbKeyDown
  479.             EyePhi = EyePhi + Dphi
  480.                 
  481.         Case Else
  482.             Exit Sub
  483.     End Select
  484.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  485.     DrawData Pict
  486. End Sub
  487. Private Sub Form_KeyPress(KeyAscii As Integer)
  488.     Select Case KeyAscii
  489.         Case Asc("+")
  490.             EyeR = EyeR + Dr
  491.         
  492.         Case Asc("-")
  493.             EyeR = EyeR - Dr
  494.         
  495.         Case Else
  496.             Exit Sub
  497.     End Select
  498.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  499.     DrawData Pict
  500. End Sub
  501. Private Sub Form_Load()
  502.     ' Initialize the eye position.
  503.     EyeR = 10
  504.     EyeTheta = PI * 0.2
  505.     EyePhi = PI * 0.1
  506.     ' Initialize the projection transformation.
  507.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  508.     ' Create the data.
  509.     CreateData (ShowAxesCheck.value = vbChecked)
  510.     ' Project and draw the data.
  511.     Me.Show
  512.     DrawData Pict
  513. End Sub
  514. ' ************************************************
  515. ' Create the surface.
  516. ' ************************************************
  517. Sub CreateData(show_axes As Boolean)
  518. Const GapU = 0.1
  519. Const GapV = 0.1
  520. Const Du = GapU / 5
  521. Const Dv = GapV / 5
  522. Dim axis As ObjPolyline
  523.     MousePointer = vbHourglass
  524.     Refresh
  525.     Set ThePicture = New ObjPicture
  526.     Set TheSurface = New ObjBezier
  527.     ThePicture.objects.Add TheSurface
  528.     TheSurface.DrawControls = (ShowControlsCheck.value = vbChecked)
  529.     TheSurface.DrawGrid = (ShowGridCheck.value = vbChecked)
  530.     If show_axes Then
  531.         Set axis = New ObjPolyline
  532.         ThePicture.objects.Add axis
  533.         axis.AddSegment 0, 0, 0, 5.5, 0, 0
  534.         axis.AddSegment 0, 0, 0, 0, 3, 0
  535.         axis.AddSegment 0, 0, 0, 0, 0, 5.5
  536.     End If
  537.     ' Set the control points.
  538.     Select Case ChoiceNum
  539.         Case 0  ' Hill.
  540.             MakeHill
  541.         Case 1  ' Wave.
  542.             MakeWave
  543.         Case 2  ' Tent.
  544.             MakeTent
  545.             
  546.         Case 3  ' Curl.
  547.             MakeCurl
  548.             
  549.         Case 4  ' Pipe.
  550.             MakePipe
  551.             
  552.         Case 5  ' Cowling.
  553.             MakeCowl
  554.             
  555.         Case 6  ' Twist.
  556.             MakeTwist
  557.         
  558.         Case 7  ' Spiral.
  559.             MakeSpiral
  560.         
  561.         Case 8  ' Urn.
  562.             MakeUrn
  563.         
  564.         Case Else  ' Something safe.
  565.             MakeHill
  566.     End Select
  567.     ' Create the grid to represent the surface.
  568.     TheSurface.InitializeGrid GapU, GapV, Du, Dv
  569. End Sub
  570. Private Sub mnuFileExit_Click()
  571.     Unload Me
  572. End Sub
  573. Private Sub mnuFileLoad_Click()
  574. Dim fname As String
  575. Dim filenum As Integer
  576. Dim txt As String
  577. Dim Xmin As Single
  578. Dim ymin As Single
  579. Dim Xmax As Single
  580. Dim ymax As Single
  581.     ' Allow the user to pick a file.
  582.     On Error Resume Next
  583.     LoadDialog.filename = "*.APF"
  584.     LoadDialog.ShowOpen
  585.     If Err.Number = cdlCancel Then
  586.         Unload LoadDialog
  587.         Exit Sub
  588.     ElseIf Err.Number <> 0 Then
  589.         Unload LoadDialog
  590.         Beep
  591.         MsgBox "Error selecting file.", , vbExclamation
  592.         Exit Sub
  593.     End If
  594.     On Error GoTo 0
  595.     fname = LoadDialog.filename
  596.     LoadDialog.InitDir = Left$(fname, Len(fname) _
  597.         - Len(LoadDialog.FileTitle) - 1)
  598.     ' Clear the picture.
  599.     Set ThePicture = Nothing
  600.     ' Open the file.
  601.     filenum = FreeFile
  602.     Open fname For Input As #filenum
  603.     ' Make sure it's an Object Picture File.
  604.     Input #filenum, txt
  605.     If txt <> "3D APF PICTURE" Then
  606.         Close filenum
  607.         Beep
  608.         MsgBox "Error reading file """ & fname & """.", , vbExclamation
  609.         Exit Sub
  610.     End If
  611.     ' Read the picture.
  612.     MousePointer = vbHourglass
  613.     DoEvents
  614.     Set ThePicture = New ObjPicture
  615.     ThePicture.FileInput filenum
  616.     If ThePicture.objects(1).ObjectType = "BEZIER" Then
  617.         Set TheSurface = ThePicture.objects(1)
  618.         TheSurface.DrawControls = (ShowControlsCheck.value = vbChecked)
  619.         TheSurface.DrawGrid = (ShowGridCheck.value = vbChecked)
  620.     End If
  621.     ' Close the file.
  622.     Close filenum
  623.     ' Refresh the display.
  624.     DrawData Pict
  625.     ' Deselect all the option buttons.
  626.     For ChoiceNum = 0 To 8
  627.         If Choice(ChoiceNum).value Then _
  628.             Choice(ChoiceNum).value = False
  629.     Next ChoiceNum
  630.     MousePointer = vbDefault
  631. End Sub
  632. Private Sub mnuFileSaveAs_Click()
  633. Dim fname As String
  634. Dim filenum As Integer
  635.     ' Allow the user to pick a file.
  636.     On Error Resume Next
  637.     LoadDialog.filename = "*.APF"
  638.     LoadDialog.ShowOpen
  639.     If Err.Number = cdlCancel Then
  640.         Unload LoadDialog
  641.         Exit Sub
  642.     ElseIf Err.Number <> 0 Then
  643.         Unload LoadDialog
  644.         Beep
  645.         MsgBox "Error selecting file.", , vbExclamation
  646.         Exit Sub
  647.     End If
  648.     On Error GoTo 0
  649.     fname = LoadDialog.filename
  650.     LoadDialog.InitDir = Left$(fname, Len(fname) _
  651.         - Len(LoadDialog.FileTitle) - 1)
  652.     ' Open the file.
  653.     filenum = FreeFile
  654.     Open fname For Output As #filenum
  655.     ' Write the picture.
  656.     ThePicture.FileWrite filenum
  657.     ' Close the file.
  658.     Close filenum
  659. End Sub
  660. Private Sub PhiText_Change()
  661.     If ShowingParameters Then Exit Sub
  662.     EyePhi = CSng(PhiText.Text)
  663.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  664.     DrawData Pict
  665. End Sub
  666. Private Sub RText_Change()
  667.     If ShowingParameters Then Exit Sub
  668.     EyeR = CSng(RText.Text)
  669.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  670.     DrawData Pict
  671. End Sub
  672. Private Sub ShowAxesCheck_Click()
  673.     CreateData (ShowAxesCheck.value = vbChecked)
  674.     DrawData Pict
  675.     Pict.SetFocus
  676. End Sub
  677. Private Sub ShowControlsCheck_Click()
  678.     TheSurface.DrawControls = (ShowControlsCheck.value = vbChecked)
  679.     DrawData Pict
  680.     Pict.SetFocus
  681. End Sub
  682. Private Sub ShowGridCheck_Click()
  683.     TheSurface.DrawGrid = (ShowGridCheck.value = vbChecked)
  684.     DrawData Pict
  685.     Pict.SetFocus
  686. End Sub
  687. Private Sub ThetaText_Change()
  688.     If ShowingParameters Then Exit Sub
  689.     EyeTheta = CSng(ThetaText.Text)
  690.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  691.     DrawData Pict
  692. End Sub
  693.