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

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Trimmed Nurbs Surface"
  4.    ClientHeight    =   5565
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1425
  7.    ClientWidth     =   5535
  8.    Height          =   5940
  9.    Left            =   1080
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5565
  12.    ScaleWidth      =   5535
  13.    Top             =   1110
  14.    Width           =   5655
  15.    Begin TgsVisual3SpaceLibCtl.V3Space V3Space1 
  16.       Height          =   5415
  17.       Left            =   0
  18.       TabIndex        =   0
  19.       Top             =   120
  20.       Width           =   5535
  21.       _Version        =   131072
  22.       _ExtentX        =   9763
  23.       _ExtentY        =   9551
  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.     Dim root As SoSeparator
  31.     Set root = New SoSeparator
  32.     Dim rot   As SoRotation
  33.     Set rot = New SoRotation
  34.     Dim vec3f As SbVec3f
  35.     Set vec3f = New SbVec3f
  36.     Call vec3f.setValue(0#, 1#, 0#)
  37.     Dim tRot As SbRotation
  38.     Set tRot = New SbRotation
  39.     Call tRot.setValue(vec3f, 3.14159265358979 / 2#)
  40.     Call rot.rotation.setValue(tRot)
  41.     Call root.addChild(rot)
  42.     'Create the scene graph for the carpet
  43.     Dim carpet As SoSeparator
  44.     Set carpet = New SoSeparator
  45.     Dim surf As SoSeparator
  46.     Set surf = makeSurface()
  47.     Dim tex As SoTexture2
  48.     Set tex = New SoTexture2
  49.     Call tex.filename.setValue(V3Space1.getRegistryDataPath() + "\examples\/data/diamondRug.rgb")
  50.     Call carpet.addChild(tex)
  51.     Call carpet.addChild(surf)
  52.     Call root.addChild(carpet)
  53.     'Create the scene graph for the floor
  54.     Dim floor As SoSeparator
  55.     Set floor = New SoSeparator
  56.     Dim xlate As SoTranslation
  57.     Set xlate = New SoTranslation
  58.     Dim scale1 As SoScale
  59.     Set scale1 = New SoScale
  60.     Dim myInput As SoInput
  61.     Set myInput = New SoInput
  62.     Dim result As SoNode
  63.     Set idisp = V3Space1.GetIDispatch
  64.     Set result = myInput.readAllUrl("examples\data\floorData.iv", idisp)
  65.     Call xlate.translation.setValue(-12#, -5#, -5#)
  66.     Call scale1.scaleFactor.setValue(2#, 1#, 2#)
  67.     Call floor.addChild(xlate)
  68.     Call floor.addChild(scale1)
  69.     Call floor.addChild(result)
  70.     Call root.addChild(floor)
  71.     'Create the scene graph for the carpet's shadow
  72.     Dim shadow As SoSeparator
  73.     Set shadow = New SoSeparator
  74.     Dim shmdl  As SoLightModel
  75.     Set shmdl = New SoLightModel
  76.     Dim shmtl  As SoMaterial
  77.     Set shmtl = New SoMaterial
  78.     Dim shclr  As SoBaseColor
  79.     Set shclr = New SoBaseColor
  80.     Dim shxl  As SoTranslation
  81.     Set shxl = New SoTranslation
  82.     Dim shscl As SoScale
  83.     Set shscl = New SoScale
  84.     Call shmdl.model.setValue(0)    'SoLightModel:: BASE_COLOR
  85.     Call shclr.RGB.setValue(0.21, 0.15, 0.09)
  86.     Call shmtl.transparency.setValue(0.3)
  87.     Call shxl.translation.setValue(0#, -4.9, 0#)
  88.     Call shscl.scaleFactor.setValue(1#, 0#, 1#)
  89.     Call shadow.addChild(shmtl)
  90.     Call shadow.addChild(shmdl)
  91.     Call shadow.addChild(shclr)
  92.     Call shadow.addChild(shxl)
  93.     Call shadow.addChild(shscl)
  94.     Call shadow.addChild(surf)
  95.     Call root.addChild(shadow)
  96.     Call V3Space1.setSceneRoot(root)
  97.     Dim cam As Object
  98.     Set cam = V3Space1.getCurrentCamera
  99.     Call cam.position.setValue(-8.5, 13#, 23#)
  100.     Call vec3f.setValue(-2#, -2#, -4#)
  101.     Call cam.pointAt(vec3f)
  102.     Set root = Nothing
  103.     Set rot = Nothing
  104.     Set vec3f = Nothing
  105.     Set tRot = Nothing
  106.     Set carpet = Nothing
  107.     Set surf = Nothing
  108.     Set tex = Nothing
  109.     Set floor = Nothing
  110.     Set xlate = Nothing
  111.     Set scale1 = Nothing
  112.     Set myInput = Nothing
  113.     Set result = Nothing
  114.     Set idisp = Nothing
  115.     Set shadow = Nothing
  116.     Set shmdl = Nothing
  117.     Set shmtl = Nothing
  118.     Set shclr = Nothing
  119.     Set shxl = Nothing
  120.     Set shscl = Nothing
  121.     Set cam = Nothing
  122. End Sub
  123. Public Static Function makeSurface()
  124.     Dim surfSep As SoSeparator
  125.     Set surfSep = New SoSeparator
  126.     'Define the Bezier surface including the control
  127.     'points, trim curve, and a complexity.
  128.     Dim complexity As SoComplexity
  129.     Set complexity = New SoComplexity
  130.     Dim controlPts As SoCoordinate3
  131.     Set controlPts = New SoCoordinate3
  132.     Dim surface As SoNurbsSurface
  133.     Set surface = New SoNurbsSurface
  134.     Call complexity.Value.setValue(0.7)
  135.     '0   {-4.5, -2.0,  8.0},
  136.     Call controlPts.Point.set1Value(0, -4.5, -2#, 8#)
  137.     '1  {-2.0,  1.0,  8.0},
  138.     Call controlPts.Point.set1Value(1, -2#, 1#, 8#)
  139.     '2   { 2.0, -3.0,  6.0},
  140.     Call controlPts.Point.set1Value(2, 2#, -3#, 6#)
  141.     '3   { 5.0, -1.0,  8.0},
  142.     Call controlPts.Point.set1Value(3, 5#, -1#, 8#)
  143.     '4   {-3.0,  3.0,  4.0},
  144.     Call controlPts.Point.set1Value(4, -3#, 3#, 4#)
  145.     '5   { 0.0, -1.0,  4.0},
  146.     Call controlPts.Point.set1Value(5, 0#, -1#, 4#)
  147.     '6   { 1.0, -1.0,  4.0},
  148.     Call controlPts.Point.set1Value(6, 1#, -1#, 4#)
  149.     '7   { 3.0,  2.0,  4.0},
  150.     Call controlPts.Point.set1Value(7, 3#, 2#, 4#)
  151.     '8   {-5.0, -2.0, -2.0},
  152.     Call controlPts.Point.set1Value(8, -5#, -2#, -2#)
  153.     '9   {-2.0, -4.0, -2.0},
  154.     Call controlPts.Point.set1Value(9, -2#, -4#, -2#)
  155.     '10   { 2.0, -1.0, -2.0},
  156.     Call controlPts.Point.set1Value(10, 2#, -1#, -2#)
  157.     '11   { 5.0,  0.0, -2.0},
  158.     Call controlPts.Point.set1Value(11, 5#, 0#, -2#)
  159.     '12   {-4.5,  2.0, -6.0},
  160.     Call controlPts.Point.set1Value(12, -4.5, 2#, -6#)
  161.     '13   {-2.0, -4.0, -5.0},
  162.     Call controlPts.Point.set1Value(13, -2#, -4#, -5#)
  163.     '14   { 2.0,  3.0, -5.0},
  164.     Call controlPts.Point.set1Value(14, 2#, 3#, -5#)
  165.     '15   { 4.5, -2.0, -6.0}}
  166.     Call controlPts.Point.set1Value(15, 4.5, -2#, -6#)
  167.     Call surface.numUControlPoints.setValue(4)
  168.     Call surface.numVControlPoints.setValue(4)
  169.     'The Bezier knot vector for the surface.
  170.     ' This knot vector is used in both the U and
  171.     'V directions.
  172.     Call surface.uKnotVector.set1Value(0, 0)
  173.     Call surface.uKnotVector.set1Value(1, 0)
  174.     Call surface.uKnotVector.set1Value(2, 0)
  175.     Call surface.uKnotVector.set1Value(3, 0)
  176.     Call surface.uKnotVector.set1Value(4, 1)
  177.     Call surface.uKnotVector.set1Value(5, 1)
  178.     Call surface.uKnotVector.set1Value(6, 1)
  179.     Call surface.uKnotVector.set1Value(7, 1)
  180.     Call surface.vKnotVector.set1Value(0, 0)
  181.     Call surface.vKnotVector.set1Value(1, 0)
  182.     Call surface.vKnotVector.set1Value(2, 0)
  183.     Call surface.vKnotVector.set1Value(3, 0)
  184.     Call surface.vKnotVector.set1Value(4, 1)
  185.     Call surface.vKnotVector.set1Value(5, 1)
  186.     Call surface.vKnotVector.set1Value(6, 1)
  187.     Call surface.vKnotVector.set1Value(7, 1)
  188.     Call surfSep.addChild(complexity)
  189.     Call surfSep.addChild(controlPts)
  190.     Dim trimPts As SoProfileCoordinate2
  191.     Set trimPts = New SoProfileCoordinate2
  192.     Dim nTrim1 As SoNurbsProfile
  193.     Set nTrim1 = New SoNurbsProfile
  194.     Dim nTrim2 As SoNurbsProfile
  195.     Set nTrim2 = New SoNurbsProfile
  196.     Dim nTrim3 As SoNurbsProfile
  197.     Set nTrim3 = New SoNurbsProfile
  198.     '0   {0.0, 0.0},
  199.     Call trimPts.Point.set1Value(0, 0#, 0#)
  200.     '1   {1.0, 0.0},
  201.     Call trimPts.Point.set1Value(1, 1#, 0#)
  202.     '2   {1.0, 1.0},
  203.     Call trimPts.Point.set1Value(2, 1#, 1#)
  204.     '3   {0.0, 1.0},
  205.     Call trimPts.Point.set1Value(3, 0#, 1#)
  206.     '4   {0.2, 0.2},
  207.     Call trimPts.Point.set1Value(4, 0.2, 0.2)
  208.     '5   {0.2, 0.7},
  209.     Call trimPts.Point.set1Value(5, 0.2, 0.7)
  210.     '6   {0.9, 0.7},
  211.     Call trimPts.Point.set1Value(6, 0.9, 0.7)
  212.     '7   {0.9, 0.2},
  213.     Call trimPts.Point.set1Value(7, 0.9, 0.2)
  214.     '8   {0.7, 0.0},
  215.     Call trimPts.Point.set1Value(8, 0.7, 0#)
  216.     '9   {0.4, 0.8}}
  217.     Call trimPts.Point.set1Value(9, 0.4, 0.8)
  218.     'int32_t trimInds[5]
  219.     Call nTrim1.Index.set1Value(0, 0)
  220.     Call nTrim1.Index.set1Value(1, 1)
  221.     Call nTrim1.Index.set1Value(2, 2)
  222.     Call nTrim1.Index.set1Value(3, 3)
  223.     Call nTrim1.Index.set1Value(4, 0)
  224.     'float tknots1[7] = {0, 0, 1, 2, 3, 4, 4}
  225.     Call nTrim1.knotVector.set1Value(0, 0)
  226.     Call nTrim1.knotVector.set1Value(1, 0)
  227.     Call nTrim1.knotVector.set1Value(2, 1)
  228.     Call nTrim1.knotVector.set1Value(3, 2)
  229.     Call nTrim1.knotVector.set1Value(4, 3)
  230.     Call nTrim1.knotVector.set1Value(5, 4)
  231.     Call nTrim1.knotVector.set1Value(6, 4)
  232.     Call nTrim2.linkage.setValue(1) 'SoProfile::START_NEW
  233.     Call nTrim2.Index.set1Value(0, 4)
  234.     Call nTrim2.Index.set1Value(1, 5)
  235.     Call nTrim2.Index.set1Value(2, 6)
  236.     Call nTrim2.Index.set1Value(3, 7)
  237.     'float tknots2[6] = {0, 0, 1, 2, 3, 3}
  238.     Call nTrim2.knotVector.set1Value(0, 0)
  239.     Call nTrim2.knotVector.set1Value(1, 0)
  240.     Call nTrim2.knotVector.set1Value(2, 1)
  241.     Call nTrim2.knotVector.set1Value(3, 2)
  242.     Call nTrim2.knotVector.set1Value(4, 3)
  243.     Call nTrim2.knotVector.set1Value(5, 3)
  244.     Call nTrim3.linkage.setValue(2) 'SoProfile::ADD_TO_CURRENT)
  245.     Call nTrim3.Index.set1Value(0, 7)
  246.     Call nTrim3.Index.set1Value(1, 8)
  247.     Call nTrim3.Index.set1Value(2, 9)
  248.     Call nTrim3.Index.set1Value(3, 4)
  249.     'float tknots3[8] = {0, 0, 0, 0, 1, 1, 1, 1}
  250.     Call nTrim3.knotVector.set1Value(0, 0)
  251.     Call nTrim3.knotVector.set1Value(1, 0)
  252.     Call nTrim3.knotVector.set1Value(2, 0)
  253.     Call nTrim3.knotVector.set1Value(3, 0)
  254.     Call nTrim3.knotVector.set1Value(4, 1)
  255.     Call nTrim3.knotVector.set1Value(5, 1)
  256.     Call nTrim3.knotVector.set1Value(6, 1)
  257.     Call nTrim3.knotVector.set1Value(7, 1)
  258.     Call surfSep.addChild(trimPts)
  259.     Call surfSep.addChild(nTrim1)
  260.     Call surfSep.addChild(nTrim2)
  261.     Call surfSep.addChild(nTrim3)
  262.     Call surfSep.addChild(surface)
  263.     Set makeSurface = surfSep
  264. End Function
  265.