home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Form1
- Caption = "12_4 Timer Sensor"
- ClientHeight = 6345
- ClientLeft = 1140
- ClientTop = 1425
- ClientWidth = 6390
- Height = 6720
- Left = 1080
- LinkTopic = "Form1"
- ScaleHeight = 6345
- ScaleWidth = 6390
- Top = 1110
- Width = 6510
- Begin VB.Label Label1
- Caption = $"12_4TimerSensor.frx":0000
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 12
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 975
- Left = 120
- TabIndex = 1
- Top = 0
- Width = 6135
- End
- Begin TgsVisual3SpaceLibCtl.V3Space V3Space1
- Height = 5295
- Left = 0
- TabIndex = 0
- Top = 1080
- Width = 6375
- _Version = 131072
- _ExtentX = 11245
- _ExtentY = 9340
- _StockProps = 0
- decorationOn = 0 'False
- viewingOn = 0 'False
- End
- Attribute VB_Name = "Form1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Dim myRotation As SoRotation
- Dim schedulingSensor As SoTimerSensor
- Dim rotatingSensor As SoTimerSensor
- Private Sub Form_Initialize()
- Dim root As SoSeparator
- Set root = New SoSeparator
- Dim myMaterial As SoMaterial
- Set myMaterial = New SoMaterial
- Call myMaterial.diffuseColor.setValue(0#, 0#, 1#)
- Call root.addChild(myMaterial)
- Set myRotation = New SoRotation
- Call root.addChild(myRotation)
- Dim idisp As Object
- Set idisp = V3Space1.GetIDispatch
- Dim myInput As SoInput
- Set myInput = New SoInput
- Dim result As Object
- Set result = myInput.readAllUrl(V3Space1.getRegistryDataPath() + "\examples\data\star.iv", V3Space1.GetIDispatch())
- Call root.addChild(result)
- Call V3Space1.setSceneRoot(root)
- Dim cam As Object
- Set cam = V3Space1.getCurrentCamera()
- Call cam.position.setValue(0#, -1#, 0#)
- Dim vec3f As SbVec3f
- Set vec3f = New SbVec3f
- Call vec3f.setValue(0, 0, 0)
- Call cam.pointAt(vec3f)
- Set rotatingSensor = New SoTimerSensor
- Static rotatingCB As SoSensorCB
- Set rotatingCB = New SoSensorCB
- rotatingCB.sensorType = 2 'timerSensor
- Set rotatingCB.userDataObject = myRotation
- Dim t As SbTime
- Set t = New SbTime
- Call t.setValue(1)
- Call rotatingSensor.setInterval(t) 'scheduled once per second
-
- Call rotatingSensor.setFunction(idisp, rotatingCB)
- Call rotatingSensor.schedule
- Static schedulingCB As SoSensorCB
- Set schedulingCB = New SoSensorCB
- schedulingCB.sensorType = 2 'timerSensor
- Set schedulingCB.userDataObject = rotatingSensor
- Set schedulingSensor = New SoTimerSensor
- Call t.setValue(5#)
- Call schedulingSensor.setInterval(t)
- Call schedulingSensor.setFunction(idisp, schedulingCB)
- Call schedulingSensor.schedule
- Call V3Space1.viewAll
- End Sub
- Private Sub Form_Terminate()
- If (schedulingSensor.isScheduled()) Then
- Call schedulingSensor.unschedule
- End If
- If (rotatingSensor.isScheduled()) Then
- Call rotatingSensor.unschedule
- End If
- Set myRotation = Nothing
- Set schedulingSensor = Nothing
- Set rotatingSensor = Nothing
- End Sub
- Private Sub V3Space1_TimerSensor(ByVal userData As Object, ByVal sensor As Object)
- If userData Is Nothing Then
- GoTo cleanup
- End If
- If userData.userDataObject Is myRotation Then
- Dim currentRotation As SbRotation
- Set currentRotation = New SbRotation
- Dim vec3f As SbVec3f
- Set vec3f = New SbVec3f
- Call vec3f.setValue(0, 0, 1)
- Call currentRotation.setValue(vec3f, (3.1415 / 45#))
- Dim newRotation As SbRotation
- Set newRotation = userData.userDataObject.rotation.getValue()
- Call newRotation.multiply(currentRotation)
- Call userData.userDataObject.rotation.setValue(newRotation)
-
- Set currentRotation = Nothing
- Set vec3f = Nothing
- Set newRotation = Nothing
- Else
- Call userData.userDataObject.unschedule
- Dim t As SbTime
- Set t = userData.userDataObject.getInterval()
- If t.getValue = 1# Then
- Call t.setValue((1# / 10#))
- Else
- Call t.setValue(1#)
- End If
- Call userData.userDataObject.setInterval(t)
- Call userData.userDataObject.schedule
- Set t = Nothing
- End If
-
- cleanup:
- Set sensor = Nothing
- Set userData = Nothing
- End Sub
-