home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / ACTIVEX / VIS3SPAC / DATA.9 / examples / vb / 10_01AddEventCB / 10_1AddEventCB.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-11-14  |  8.7 KB  |  253 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "10_01 Keyboard Event Callback"
  4.    ClientHeight    =   5415
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1425
  7.    ClientWidth     =   10530
  8.    Height          =   5790
  9.    Left            =   1080
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5415
  12.    ScaleWidth      =   10530
  13.    Top             =   1110
  14.    Width           =   10650
  15.    Begin VB.Label keyText 
  16.       Alignment       =   2  'Center
  17.       BeginProperty Font 
  18.          name            =   "MS Sans Serif"
  19.          charset         =   0
  20.          weight          =   700
  21.          size            =   13.5
  22.          underline       =   0   'False
  23.          italic          =   0   'False
  24.          strikethrough   =   0   'False
  25.       EndProperty
  26.       Height          =   855
  27.       Left            =   120
  28.       TabIndex        =   3
  29.       Top             =   4320
  30.       Width           =   3855
  31.    End
  32.    Begin VB.Label Label2 
  33.       Caption         =   $"10_1AddEventCB.frx":0000
  34.       BeginProperty Font 
  35.          name            =   "MS Sans Serif"
  36.          charset         =   0
  37.          weight          =   400
  38.          size            =   12
  39.          underline       =   0   'False
  40.          italic          =   0   'False
  41.          strikethrough   =   0   'False
  42.       EndProperty
  43.       Height          =   1815
  44.       Left            =   120
  45.       TabIndex        =   2
  46.       Top             =   2280
  47.       Width           =   3735
  48.    End
  49.    Begin VB.Label Label1 
  50.       Caption         =   $"10_1AddEventCB.frx":0096
  51.       BeginProperty Font 
  52.          name            =   "MS Sans Serif"
  53.          charset         =   0
  54.          weight          =   400
  55.          size            =   12
  56.          underline       =   0   'False
  57.          italic          =   0   'False
  58.          strikethrough   =   0   'False
  59.       EndProperty
  60.       Height          =   1935
  61.       Left            =   120
  62.       TabIndex        =   1
  63.       Top             =   240
  64.       Width           =   3975
  65.    End
  66.    Begin TgsVisual3SpaceLibCtl.V3Space V3Space1 
  67.       Height          =   5415
  68.       Left            =   4200
  69.       TabIndex        =   0
  70.       Top             =   0
  71.       Width           =   6375
  72.       _Version        =   131072
  73.       _ExtentX        =   11245
  74.       _ExtentY        =   9551
  75.       _StockProps     =   0
  76.       decorationOn    =   0   'False
  77.       viewingOn       =   0   'False
  78.       selectionEnable =   -1  'True
  79.    End
  80. Attribute VB_Name = "Form1"
  81. Attribute VB_Creatable = False
  82. Attribute VB_Exposed = False
  83.     Dim cube As SoCube
  84.     Dim sphere As SoSphere
  85.     Dim cone As SoCone
  86.     Dim cylinder As SoCylinder
  87.     Dim cubeTransform As SoTransform
  88.     Dim sphereTransform As SoTransform
  89.     Dim coneTransform As SoTransform
  90.     Dim cylTransform As SoTransform
  91. Private Sub Form_Initialize()
  92.     On Error Resume Next
  93.     Dim selectionRoot As SoSelection
  94.     Set selectionRoot = V3Space1.getSceneRoot
  95.     'Add an event callback to catch mouse button presses.
  96.     'The callback is set up later on.
  97.     Dim myEventCB As SoEventCallback
  98.     Set myEventCB = New SoEventCallback
  99.     Call selectionRoot.addChild(myEventCB)
  100.     'Add some geometry to the scene
  101.     'a red cube
  102.     Dim cubeRoot As SoSeparator
  103.     Set cubeRoot = New SoSeparator
  104.     Dim cubeMaterial As SoMaterial
  105.     Set cubeMaterial = New SoMaterial
  106.     Set cubeTransform = New SoTransform
  107.     Call cubeRoot.addChild(cubeTransform)
  108.     Call cubeRoot.addChild(cubeMaterial)
  109.     Set cube = New SoCube
  110.     Call cubeRoot.addChild(cube)
  111.     Call cubeTransform.translation.setValue(-2, 2, 0)
  112.     Call cubeMaterial.diffuseColor.setValue(0.8, 0, 0)
  113.     Call selectionRoot.addChild(cubeRoot)
  114.     'a blue sphere
  115.     Dim sphereRoot As SoSeparator
  116.     Set sphereRoot = New SoSeparator
  117.     Dim sphereMaterial As SoMaterial
  118.     Set sphereMaterial = New SoMaterial
  119.     Set sphereTransform = New SoTransform
  120.     Call sphereRoot.addChild(sphereTransform)
  121.     Call sphereRoot.addChild(sphereMaterial)
  122.     Set sphere = New SoSphere
  123.     Call sphereRoot.addChild(sphere)
  124.     Call sphereTransform.translation.setValue(2, 2, 0)
  125.     Call sphereMaterial.diffuseColor.setValue(0, 0, 0.8)
  126.     Call selectionRoot.addChild(sphereRoot)
  127.     'a green cone
  128.     Dim coneRoot As SoSeparator
  129.     Set coneRoot = New SoSeparator
  130.     Dim coneMaterial As SoMaterial
  131.     Set coneMaterial = New SoMaterial
  132.     Set coneTransform = New SoTransform
  133.     Call coneRoot.addChild(coneTransform)
  134.     Call coneRoot.addChild(coneMaterial)
  135.     Set cone = New SoCone
  136.     Call coneRoot.addChild(cone)
  137.     Call coneTransform.translation.setValue(2, -2, 0)
  138.     Call coneMaterial.diffuseColor.setValue(0, 0.8, 0)
  139.     Call selectionRoot.addChild(coneRoot)
  140.     'a magenta cylinder
  141.     Dim cylRoot As SoSeparator
  142.     Set cylRoot = New SoSeparator
  143.     Dim cylMaterial As SoMaterial
  144.     Set cylMaterial = New SoMaterial
  145.     Set cylTransform = New SoTransform
  146.     Call cylRoot.addChild(cylTransform)
  147.     Call cylRoot.addChild(cylMaterial)
  148.     Set cylinder = New SoCylinder
  149.     Call cylRoot.addChild(cylinder)
  150.     Call cylTransform.translation.setValue(-2, -2, 0)
  151.     Call cylMaterial.diffuseColor.setValue(0.8, 0, 0.8)
  152.     Call selectionRoot.addChild(cylRoot)
  153.     Call V3Space1.viewAll
  154.     Static eCB As SoEventCallbackCB
  155.     Set eCB = New SoEventCallbackCB
  156.     'keyboard
  157.     eCB.nType = 3
  158.     Set eCB.userDataObject = V3Space1.getSceneRoot
  159.     Dim idisp As Object
  160.     Set idisp = V3Space1.GetIDispatch
  161.     Call myEventCB.addEventCallback(idisp, eCB)
  162.     Call V3Space1.viewAll
  163.     Set idisp = Nothing
  164.     Set selectionRoot = Nothing
  165.     Set cubeRoot = Nothing
  166.     Set coneRoot = Nothing
  167.     Set sphereRoot = Nothing
  168.     Set cylRoot = Nothing
  169.     Set cubeMaterial = Nothing
  170.     Set coneMaterial = Nothing
  171.     Set sphereMaterial = Nothing
  172.     Set cylMaterial = Nothing
  173. End Sub
  174. Private Sub Form_Terminate()
  175.     Set cube = Nothing
  176.     Set cone = Nothing
  177.     Set cylinder = Nothing
  178.     Set cubeTransform = Nothing
  179.     Set sphereTransform = Nothing
  180.     Set coneTransform = Nothing
  181.     Set cylTransform = Nothing
  182. End Sub
  183. Private Sub V3Space1_KeyboardEvent(ByVal eventCallbackCB As Object, ByVal eventCallback As Object)
  184.     On Error Resume Next
  185.     Dim ev As SoKeyboardEvent
  186.     Set ev = eventCallback.getEvent()
  187.     Dim key As Long
  188.     key = ev.getKey()
  189.     keyText.Caption = "Key Pressed: " + ev.getPrintableCharacter()
  190.     If key <> 65362 And key <> 65364 Then
  191.         GoTo cleanup
  192.     End If
  193.     If key = 65362 Then
  194.         Call myScaleSelection(eventCallbackCB.userDataObject, 1.1)
  195.         keyText.Caption = "Key Pressed: shift-up arrow"
  196.     Else
  197.         Call myScaleSelection(eventCallbackCB.userDataObject, 0.9)
  198.         keyText.Caption = "Key Pressed: shift-down arrow"
  199.     End If
  200. cleanup:
  201.     Set ev = Nothing
  202.     Set eventCallbackCB = Nothing
  203.     Set eventCallback = Nothing
  204. End Sub
  205. Public Sub myScaleSelection(selection As SoSelection, sf As Single)
  206.     On Error Resume Next
  207.     Dim selectedPath As SoPath
  208.     Dim xform As SoTransform
  209.     Dim scaleFactor As SbVec3f
  210.     Dim i As Integer
  211.     Dim j As Integer
  212.     'Scale each object in the selection list
  213.     Dim selCnt As Long
  214.     Dim selLen As Long
  215.     selCnt = selection.getNumSelected()
  216.     For i = 0 To selCnt - 1
  217.         Set selectedPath = selection.getPath(i)
  218.         Set xform = Nothing
  219.         'Look for the shape node, starting from the tail of the
  220.         'path.  Once we know the type of shape, we know which
  221.         'transform to modify
  222.         selLen = selectedPath.getLength()
  223.         Dim n As Object
  224.         For j = 0 To selLen - 1
  225.             Set n = selectedPath.getNodeFromTail(j)
  226.             If n.isOfType(cube.getClassTypeId()) Then
  227.                 Set xform = cubeTransform
  228.                 Exit For
  229.             ElseIf n.isOfType(sphere.getClassTypeId()) Then
  230.                 Set xform = sphereTransform
  231.                 Exit For
  232.             ElseIf n.isOfType(cylinder.getClassTypeId()) Then
  233.                 Set xform = cylTransform
  234.                 Exit For
  235.             ElseIf n.isOfType(cone.getClassTypeId()) Then
  236.                 Set xform = coneTransform
  237.                 Exit For
  238.             End If
  239.             Set n = Nothing
  240.         Next j
  241.         Set n = Nothing
  242.         'Apply the scale
  243.         If Not (xform Is Nothing) Then
  244.             Set scaleFactor = xform.scaleFactor.getValueVec()
  245.             Call scaleFactor.multiplyScalar(sf)
  246.             Call xform.scaleFactor.setValueVec3f(scaleFactor)
  247.             Set scaleFactor = Nothing
  248.             Set xform = Nothing
  249.         End If
  250.         Set selectedPath = Nothing
  251.     Next i
  252. End Sub
  253.