home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / ACTIVEX / VIS3SPAC / DATA.9 / examples / vb / 12_4TimerSensor / 12_4TimerSensor.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-11-13  |  5.0 KB  |  146 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "12_4 Timer Sensor"
  4.    ClientHeight    =   6345
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1425
  7.    ClientWidth     =   6390
  8.    Height          =   6720
  9.    Left            =   1080
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   6345
  12.    ScaleWidth      =   6390
  13.    Top             =   1110
  14.    Width           =   6510
  15.    Begin VB.Label Label1 
  16.       Caption         =   $"12_4TimerSensor.frx":0000
  17.       BeginProperty Font 
  18.          name            =   "MS Sans Serif"
  19.          charset         =   0
  20.          weight          =   400
  21.          size            =   12
  22.          underline       =   0   'False
  23.          italic          =   0   'False
  24.          strikethrough   =   0   'False
  25.       EndProperty
  26.       Height          =   975
  27.       Left            =   120
  28.       TabIndex        =   1
  29.       Top             =   0
  30.       Width           =   6135
  31.    End
  32.    Begin TgsVisual3SpaceLibCtl.V3Space V3Space1 
  33.       Height          =   5295
  34.       Left            =   0
  35.       TabIndex        =   0
  36.       Top             =   1080
  37.       Width           =   6375
  38.       _Version        =   131072
  39.       _ExtentX        =   11245
  40.       _ExtentY        =   9340
  41.       _StockProps     =   0
  42.       decorationOn    =   0   'False
  43.       viewingOn       =   0   'False
  44.    End
  45. Attribute VB_Name = "Form1"
  46. Attribute VB_Creatable = False
  47. Attribute VB_Exposed = False
  48.     Dim myRotation As SoRotation
  49.     Dim schedulingSensor As SoTimerSensor
  50.     Dim rotatingSensor As SoTimerSensor
  51. Private Sub Form_Initialize()
  52.     Dim root As SoSeparator
  53.     Set root = New SoSeparator
  54.     Dim myMaterial As SoMaterial
  55.     Set myMaterial = New SoMaterial
  56.     Call myMaterial.diffuseColor.setValue(0#, 0#, 1#)
  57.     Call root.addChild(myMaterial)
  58.     Set myRotation = New SoRotation
  59.     Call root.addChild(myRotation)
  60.     Dim idisp As Object
  61.     Set idisp = V3Space1.GetIDispatch
  62.     Dim myInput As SoInput
  63.     Set myInput = New SoInput
  64.     Dim result As Object
  65.     Set result = myInput.readAllUrl(V3Space1.getRegistryDataPath() + "\examples\data\star.iv", V3Space1.GetIDispatch())
  66.     Call root.addChild(result)
  67.     Call V3Space1.setSceneRoot(root)
  68.     Dim cam As Object
  69.     Set cam = V3Space1.getCurrentCamera()
  70.     Call cam.position.setValue(0#, -1#, 0#)
  71.     Dim vec3f As SbVec3f
  72.     Set vec3f = New SbVec3f
  73.     Call vec3f.setValue(0, 0, 0)
  74.     Call cam.pointAt(vec3f)
  75.     Set rotatingSensor = New SoTimerSensor
  76.     Static rotatingCB As SoSensorCB
  77.     Set rotatingCB = New SoSensorCB
  78.     rotatingCB.sensorType = 2 'timerSensor
  79.     Set rotatingCB.userDataObject = myRotation
  80.     Dim t As SbTime
  81.     Set t = New SbTime
  82.     Call t.setValue(1)
  83.     Call rotatingSensor.setInterval(t)     'scheduled once per second
  84.      
  85.     Call rotatingSensor.setFunction(idisp, rotatingCB)
  86.     Call rotatingSensor.schedule
  87.     Static schedulingCB As SoSensorCB
  88.     Set schedulingCB = New SoSensorCB
  89.     schedulingCB.sensorType = 2 'timerSensor
  90.     Set schedulingCB.userDataObject = rotatingSensor
  91.     Set schedulingSensor = New SoTimerSensor
  92.     Call t.setValue(5#)
  93.     Call schedulingSensor.setInterval(t)
  94.     Call schedulingSensor.setFunction(idisp, schedulingCB)
  95.     Call schedulingSensor.schedule
  96.     Call V3Space1.viewAll
  97. End Sub
  98. Private Sub Form_Terminate()
  99.     If (schedulingSensor.isScheduled()) Then
  100.         Call schedulingSensor.unschedule
  101.     End If
  102.     If (rotatingSensor.isScheduled()) Then
  103.         Call rotatingSensor.unschedule
  104.     End If
  105.     Set myRotation = Nothing
  106.     Set schedulingSensor = Nothing
  107.     Set rotatingSensor = Nothing
  108. End Sub
  109. Private Sub V3Space1_TimerSensor(ByVal userData As Object, ByVal sensor As Object)
  110.     If userData Is Nothing Then
  111.         GoTo cleanup
  112.     End If
  113.     If userData.userDataObject Is myRotation Then
  114.         Dim currentRotation As SbRotation
  115.         Set currentRotation = New SbRotation
  116.         Dim vec3f As SbVec3f
  117.         Set vec3f = New SbVec3f
  118.         Call vec3f.setValue(0, 0, 1)
  119.         Call currentRotation.setValue(vec3f, (3.1415 / 45#))
  120.         Dim newRotation As SbRotation
  121.         Set newRotation = userData.userDataObject.rotation.getValue()
  122.         Call newRotation.multiply(currentRotation)
  123.         Call userData.userDataObject.rotation.setValue(newRotation)
  124.         
  125.         Set currentRotation = Nothing
  126.         Set vec3f = Nothing
  127.         Set newRotation = Nothing
  128.     Else
  129.         Call userData.userDataObject.unschedule
  130.         Dim t As SbTime
  131.         Set t = userData.userDataObject.getInterval()
  132.         If t.getValue = 1# Then
  133.             Call t.setValue((1# / 10#))
  134.         Else
  135.             Call t.setValue(1#)
  136.         End If
  137.         Call userData.userDataObject.setInterval(t)
  138.         Call userData.userDataObject.schedule
  139.         Set t = Nothing
  140.     End If
  141.         
  142. cleanup:
  143.     Set sensor = Nothing
  144.     Set userData = Nothing
  145. End Sub
  146.