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

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "13_5Boolean"
  4.    ClientHeight    =   5700
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1425
  7.    ClientWidth     =   6780
  8.    Height          =   6075
  9.    Left            =   1080
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5700
  12.    ScaleWidth      =   6780
  13.    Top             =   1110
  14.    Width           =   6900
  15.    Begin VB.Label Label1 
  16.       Caption         =   $"13_5Boolean.frx":0000
  17.       BeginProperty Font 
  18.          name            =   "MS Sans Serif"
  19.          charset         =   0
  20.          weight          =   700
  21.          size            =   12
  22.          underline       =   0   'False
  23.          italic          =   0   'False
  24.          strikethrough   =   0   'False
  25.       EndProperty
  26.       Height          =   1575
  27.       Left            =   120
  28.       TabIndex        =   1
  29.       Top             =   120
  30.       Width           =   6615
  31.    End
  32.    Begin TgsVisual3SpaceLibCtl.V3Space V3Space1 
  33.       Height          =   3855
  34.       Left            =   120
  35.       TabIndex        =   0
  36.       Top             =   1800
  37.       Width           =   6615
  38.       _Version        =   131072
  39.       _ExtentX        =   11668
  40.       _ExtentY        =   6800
  41.       _StockProps     =   0
  42.       decorationOn    =   0   'False
  43.       viewingOn       =   0   'False
  44.       selectionEnable =   -1  'True
  45.    End
  46. Attribute VB_Name = "Form1"
  47. Attribute VB_Creatable = False
  48. Attribute VB_Exposed = False
  49. Dim bigDuckGate As SoGate
  50. Dim bigDuckTime As SoElapsedTime
  51. Dim myEventCB As SoEventCallback
  52. Dim myBoolean As SoBoolOperation
  53. Dim smallDuckGate As SoGate
  54. Dim smallDuckTime As SoElapsedTime
  55. Dim smallDuckRotXYZ As SoRotationXYZ
  56. Dim bigDuckRotXYZ As SoRotationXYZ
  57. Private Sub Form_Initialize()
  58.     Dim root As SoSeparator
  59.     Set root = New SoSeparator
  60.     'Add a camera and light
  61.     Dim myCamera As SoPerspectiveCamera
  62.     Set myCamera = V3Space1.getCurrentCamera
  63.     Call myCamera.position.setValue(0#, -4#, 8#)
  64.     Call myCamera.heightAngle.setValue(M_PI / 2.5)
  65.     Call myCamera.nearDistance.setValue(1#)
  66.     Call myCamera.farDistance.setValue(15#)
  67.     Dim myLight As SoDirectionalLight
  68.     Set myLight = New SoDirectionalLight
  69.     Call root.addChild(myLight)
  70.     'Rotate scene slightly to get better view
  71.     Dim globalRotXYZ As SoRotationXYZ
  72.     Set globalRotXYZ = New SoRotationXYZ
  73.     Call globalRotXYZ.axis.setValue(SoRotationXYZ_X)
  74.     Call globalRotXYZ.angle.setValue(M_PI / 9)
  75.     Call root.addChild(globalRotXYZ)
  76.     'Pond group
  77.     Dim pond As SoSeparator
  78.     Set pond = New SoSeparator
  79.     Call root.addChild(pond)
  80.     Dim pondTranslation As SoTranslation
  81.     Set pondTranslation = New SoTranslation
  82.     Call pondTranslation.translation.setValue(0#, -6.725, 0#)
  83.     Call pond.addChild(pondTranslation)
  84.     'water
  85.     Dim waterMaterial As SoMaterial
  86.     Set waterMaterial = New SoMaterial
  87.     Call waterMaterial.diffuseColor.setValue(0#, 0.3, 0.8)
  88.     Call pond.addChild(waterMaterial)
  89.     Dim waterCylinder As SoCylinder
  90.     Set waterCylinder = New SoCylinder
  91.     Call waterCylinder.radius.setValue(4#)
  92.     Call waterCylinder.Height.setValue(0.5)
  93.     Call pond.addChild(waterCylinder)
  94.     'rock
  95.     Dim rockMaterial As SoMaterial
  96.     Set rockMaterial = New SoMaterial
  97.     Call rockMaterial.diffuseColor.setValue(0.8, 0.23, 0.03)
  98.     Call pond.addChild(rockMaterial)
  99.     Dim rockSphere As SoSphere
  100.     Set rockSphere = New SoSphere
  101.     Call rockSphere.radius.setValue(0.9)
  102.     Call pond.addChild(rockSphere)
  103.     'Read the duck object from a file and add to the group
  104.     Dim myInput As SoInput
  105.     Set myInput = New SoInput
  106.     Dim duckObject As Object
  107.     Set duckObject = myInput.readAllUrl(V3Space1.getRegistryDataPath() + "\examples\data\duck.iv", V3Space1.GetIDispatch())
  108.     If duckObject Is Nothing Then
  109.         Exit Sub
  110.     End If
  111.     'CODE FOR The Inventor Mentor STARTS HERE
  112.     'Bigger duck group
  113.     Dim bigDuck As SoSeparator
  114.     Set bigDuck = New SoSeparator
  115.     Call root.addChild(bigDuck)
  116.     Set bigDuckRotXYZ = New SoRotationXYZ
  117.     Call bigDuck.addChild(bigDuckRotXYZ)
  118.     Dim bigInitialTransform As SoTransform
  119.     Set bigInitialTransform = New SoTransform
  120.     Call bigInitialTransform.translation.setValue(0#, 0#, 3.5)
  121.     Call bigInitialTransform.scaleFactor.setValue(6#, 6#, 6#)
  122.     Call bigDuck.addChild(bigInitialTransform)
  123.     Call bigDuck.addChild(duckObject)
  124.     'Smaller duck group
  125.     Dim smallDuck As SoSeparator
  126.     Set smallDuck = New SoSeparator
  127.     Call root.addChild(smallDuck)
  128.     Set smallDuckRotXYZ = New SoRotationXYZ
  129.     Call smallDuck.addChild(smallDuckRotXYZ)
  130.     Dim smallInitialTransform As SoTransform
  131.     Set smallInitialTransform = New SoTransform
  132.         
  133.     Call smallInitialTransform.translation.setValue(0#, -2.24, 1.5)
  134.     Call smallInitialTransform.scaleFactor.setValue(4#, 4#, 4#)
  135.     Call smallDuck.addChild(smallInitialTransform)
  136.     Call smallDuck.addChild(duckObject)
  137.     'Use a gate engine to start/stop the rotation of
  138.     'the bigger duck.
  139.     Set bigDuckGate = New SoGate
  140.     Dim mffloat As SoMFFloat
  141.     Set mffloat = New SoMFFloat
  142.     Call bigDuckGate.setInputType(mffloat.getClassTypeId())
  143.     Set bigDuckTime = New SoElapsedTime
  144.     Call bigDuckGate.inputField.connectFromEngine(bigDuckTime.timeout)
  145.     Call bigDuckRotXYZ.axis.setValue(SoRotationXYZ_Y)
  146.     Call bigDuckRotXYZ.angle.connectFromEngine(bigDuckGate.output)
  147.     'Each mouse button press will enable/disable the gate
  148.     'controlling the bigger duck.
  149.     Set myEventCB = New SoEventCallback
  150.     Static eCB As SoEventCallbackCB
  151.     Set eCB = New SoEventCallbackCB
  152.     'mouse
  153.     eCB.nType = SoEventCallbackCB_MOUSEBUTTON
  154.     Set eCB.userDataObject = bigDuckGate
  155.     Call myEventCB.addEventCallback(V3Space1.GetIDispatch(), eCB)
  156.     Call root.addChild(myEventCB)
  157.     'Use a Boolean engine to make the rotation of the smaller
  158.     'duck depend on the bigger duck.  The smaller duck moves
  159.     'only when the bigger duck is still.
  160.     Set myBoolean = New SoBoolOperation
  161.     Call myBoolean.a.connectFrom(bigDuckGate.enable)
  162.     Call myBoolean.operation.setValue(SoBoolOperation_NOT_A)
  163.     Set smallDuckGate = New SoGate
  164.     Call smallDuckGate.setInputType(mffloat.getClassTypeId())
  165.     Set smallDuckTime = New SoElapsedTime
  166.     Call smallDuckGate.inputField.connectFromEngine(smallDuckTime.timeout)
  167.     Call smallDuckGate.enable.connectFromEngine(myBoolean.output)
  168.     Call smallDuckRotXYZ.axis.setValue(SoRotationXYZ_Y)
  169.     Call smallDuckRotXYZ.angle.connectFromEngine(smallDuckGate.output)
  170.     Call V3Space1.setSceneRoot(root)
  171. End Sub
  172. Private Sub Form_Terminate()
  173.     Call smallDuckRotXYZ.angle.disconnect
  174.     Call bigDuckRotXYZ.angle.disconnect
  175. End Sub
  176. Private Sub V3Space1_MouseButtonEvent(ByVal eventCallbackCB As Object, ByVal eventCallback As Object)
  177.     Dim event As SOEVENT
  178.     Set event = eventCallback.getEvent()
  179.     If Not event.isButtonPressEvent(event, 0) Then
  180.         Exit Sub
  181.     End If
  182.     Dim gate As SoGate
  183.     Set gate = eventCallbackCB.userDataObject
  184.     If (gate.enable.getValue()) Then
  185.         Call gate.enable.setValue(0)
  186.     Else
  187.         Call gate.enable.setValue(True)
  188.     End If
  189.       
  190.     Call eventCallback.setHandled
  191. End Sub
  192.