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

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "08_1B-Spline Curve"
  4.    ClientHeight    =   4860
  5.    ClientLeft      =   1155
  6.    ClientTop       =   1650
  7.    ClientWidth     =   6075
  8.    Height          =   5235
  9.    Left            =   1095
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4860
  12.    ScaleWidth      =   6075
  13.    Top             =   1335
  14.    Width           =   6195
  15.    Begin TgsVisual3SpaceLibCtl.V3Space V3Space1 
  16.       Height          =   4815
  17.       Left            =   0
  18.       TabIndex        =   0
  19.       Top             =   0
  20.       Width           =   6015
  21.       _Version        =   131072
  22.       _ExtentX        =   10610
  23.       _ExtentY        =   8493
  24.       _StockProps     =   0
  25.    End
  26. Attribute VB_Name = "Form1"
  27. Attribute VB_Creatable = False
  28. Attribute VB_Exposed = False
  29. Private Sub Form_Initialize()
  30.     'CODE FOR The Inventor Mentor ENDS HERE
  31.     '////////////////////////////////////////////////////////////
  32.     Dim root As SoSeparator
  33.     Set root = New SoSeparator
  34.     'Create the scene graph for the heart
  35.     Dim heart As SoSeparator
  36.     Set heart = New SoSeparator
  37.     Dim curveSep As SoSeparator
  38.     Set curveSep = makeCurve()
  39.     Dim lmodel As SoLightModel
  40.     Set lmodel = New SoLightModel
  41.     Dim clr As SoBaseColor
  42.     Set clr = New SoBaseColor
  43.     Call lmodel.model.setValue(0) '= SoLightModel::BASE_COLOR;
  44.     Call clr.RGB.setValue(1#, 0#, 0#)
  45.     Call heart.addChild(lmodel)
  46.     Call heart.addChild(clr)
  47.     Call heart.addChild(curveSep)
  48.     Call root.addChild(heart)
  49.     'Create the scene graph for the floor
  50.     Dim floor As Object
  51.     Set floor = New SoSeparator
  52.     Dim xlate As SoTranslation
  53.     Set xlate = New SoTranslation
  54.     Dim rot As SoRotation
  55.     Set rot = New SoRotation
  56.     Dim scale1 As SoScale
  57.     Set scale1 = New SoScale
  58.     Dim myInput As SoInput
  59.     Set myInput = New SoInput
  60.     Dim result As SoGroup
  61.     Dim idisp As Object
  62.     Set idisp = V3Space1.GetIDispatch
  63.     Set result = myInput.readAllUrl("file://d:\oiv40\v3space\vbDemos\data\floorData.iv", idisp)
  64.     Call xlate.translation.setValue(-12#, -5#, -5#)
  65.     Call scale1.scaleFactor.setValue(2#, 1#, 2#)
  66.     Dim vec3f As SbVec3f
  67.     Set vec3f = New SbVec3f
  68.     Call vec3f.setValue(0#, 1#, 0#)
  69.     Dim tRot As SbRotation
  70.     Set tRot = New SbRotation
  71.     Call tRot.setValue(vec3f, 3.1415 / 2#)
  72.     Call rot.rotation.setValue(tRot)
  73.     Call floor.addChild(rot)
  74.     Call floor.addChild(xlate)
  75.     Call floor.addChild(scale1)
  76.     Call floor.addChild(result)
  77.     Call root.addChild(floor)
  78.     'Create the scene graph for the heart's shadow
  79.     Dim shadow As SoSeparator
  80.     Set shadow = New SoSeparator
  81.     Dim shmdl As SoLightModel
  82.     Set shmdl = New SoLightModel
  83.     Dim shmtl As SoMaterial
  84.     Set shmtl = New SoMaterial
  85.     Dim shclr As SoBaseColor
  86.     Set shclr = New SoBaseColor
  87.     Dim shxl As SoTranslation
  88.     Set shx1 = New SoTranslation
  89.     Dim shscl As SoScale
  90.     Set shscl = New SoScale
  91.     Call shmdl.model.setValue(0) ' = SoLightModel::BASE_COLOR;
  92.     Call shclr.RGB.setValue(0.21, 0.15, 0.09)
  93.     Call shmtl.transparency.setValue(0.5)
  94.     Call shx1.translation.setValue(0#, -4.9, 0#)
  95.     Call shscl.scaleFactor.setValue(1#, 0#, 1#)
  96.     Call shadow.addChild(shmtl)
  97.     Call shadow.addChild(shmdl)
  98.     Call shadow.addChild(shclr)
  99.     Call shadow.addChild(shx1)
  100.     Call shadow.addChild(shscl)
  101.     Call shadow.addChild(curveSep)
  102.     Call root.addChild(shadow)
  103.     Call V3Space1.setSceneRoot(root)
  104.     Dim cam As Object
  105.     Set cam = V3Space1.getCurrentCamera
  106.     Call cam.position.setValue(-6#, 8#, 20#)
  107.     Call vec3f.setValue(0#, -2#, -4#)
  108.     Call cam.pointAt(vec3f)
  109.     Set root = Nothing
  110.     Set cam = Nothing
  111.     Set heart = Nothing
  112.     Set curveSep = Nothing
  113.     Set lmodel = Nothing
  114.     Set clr = Nothing
  115.     Set floor = Nothing
  116.     Set xlate = Nothing
  117.     Set vec3f = Nothing
  118.     Set rot = Nothing
  119.     Set scale1 = Nothing
  120.     Set myInput = Nothing
  121.     Set idisp = Nothing
  122.     Set result = Nothing
  123.     Set tRot = Nothing
  124.     Set shadow = Nothing
  125.     Set shmdl = Nothing
  126.     Set shclr = Nothing
  127.     Set shxl = Nothing
  128.     Set shscl = Nothing
  129. End Sub
  130. Public Function makeCurve() As SoSeparator
  131.     'Create the nodes needed for the B-Spline curve.
  132.     Dim curveSep As SoSeparator
  133.     Set curveSep = New SoSeparator
  134.     'Set the draw style of the curve.
  135.     Dim drawStyle  As SoDrawStyle
  136.     Set drawStyle = New SoDrawStyle
  137.     Call drawStyle.lineWidth.setValue(4)
  138.     Call curveSep.addChild(drawStyle)
  139.     'Define the NURBS curve including the control points
  140.     'and a complexity.
  141.     Dim complexity As SoComplexity
  142.     Set complexity = New SoComplexity
  143.     Dim controlPts As SoCoordinate3
  144.     Set controlPts = New SoCoordinate3
  145.     Dim curve As SoNurbsCurve
  146.     Set curve = New SoNurbsCurve
  147.     Call complexity.Value.setValue(0.8)
  148.     '0   { 4.0, -6.0,  6.0},
  149.     Call controlPts.Point.set1Value(0, 4#, -6#, 6#)
  150.     '1   {-4.0,  1.0,  0.0},
  151.     Call controlPts.Point.set1Value(1, -4#, 1#, 0#)
  152.     '2   {-1.5,  5.0, -6.0},
  153.     Call controlPts.Point.set1Value(2, -1.5, 5#, -6#)
  154.     '3   { 0.0,  2.0, -2.0},
  155.     Call controlPts.Point.set1Value(3, 0#, 2#, -2#)
  156.     '4   { 1.5,  5.0, -6.0},
  157.     Call controlPts.Point.set1Value(4, 1.5, 5#, -6#)
  158.     '5   { 4.0,  1.0,  0.0},
  159.     Call controlPts.Point.set1Value(5, 4#, 1#, 0#)
  160.     '6   {-4.0, -6.0,  6.0}};
  161.     Call controlPts.Point.set1Value(6, -4#, -6#, 6#)
  162.     Call curve.numControlPoints.setValue(7)
  163.     'The knot vector
  164.     'float knots[10] = {1, 2, 3, 4, 5, 5, 6, 7, 8, 9};
  165.     Call curve.knotVector.set1Value(0, 1)
  166.     Call curve.knotVector.set1Value(1, 1)
  167.     Call curve.knotVector.set1Value(2, 2)
  168.     Call curve.knotVector.set1Value(3, 3)
  169.     Call curve.knotVector.set1Value(4, 4)
  170.     Call curve.knotVector.set1Value(5, 5)
  171.     Call curve.knotVector.set1Value(6, 6)
  172.     Call curve.knotVector.set1Value(7, 7)
  173.     Call curve.knotVector.set1Value(8, 8)
  174.     Call curve.knotVector.set1Value(9, 9)
  175.     Call curveSep.addChild(complexity)
  176.     Call curveSep.addChild(controlPts)
  177.     Call curveSep.addChild(curve)
  178.     Set makeCurve = curveSep
  179.     Set curveSep = Nothing
  180.     Set drawStyle = Nothing
  181.     Set complexity = Nothing
  182.     Set controlPts = Nothing
  183.     Set curve = Nothing
  184. End Function
  185.