VRML

1-2 さらに発展したプログラム

 次のプログラムでは、左から四角形、球、円錐を表示してます。


Program 1-3 vrml13.wrl

#VRML V2.0 utf8

#ShapeをBoxのTransformの階層の外に出し、ロゴを少しねじる。



DEF transformCUBE Transform  {

  translation -3.0 0.0 1.0  # 3m左、2m上、1m手前

  rotation -1 1 0.8 0.785

  children    [

    DEF CUBE Shape  {

      appearance Appearance   {

        material Material   {

          diffuseColor 1 0 0

          specularColor 0.9 0.9 0.9

        }

      }

      geometry Box { }

    }

  ]

}



# このBallはCubeの階層の外側にある。



DEF transformBALL Transform  {

  translation 0.0 0.0 1.0

  children    [

    DEF BALL Shape  {

      appearance Appearance   {

        material Material   {

          diffuseColor 0 1 0

          specularColor 0.9 0.9 0.9

        }

      }

      geometry Sphere { }

    }

  ]

}



DEF transformCONE Transform {

  translation 3.0 0.0 1.0

  children    [

    DEF CONE Shape  {

      appearance Appearance   {

        material Material   {

          diffuseColor 0 0 1

          specularColor 0.9 0.9 0.9

        }

      }

      geometry Cone { }

    }

  ]

}


 もう1つのプログラムを見てもらうと、左の3次元もProgram1-3と同じ、左から四角、球、円錐を使用してある。
 何が違うかと言うと、Program1-4を見てもらうと、Transformの中に四角と球が一緒に入ってある。このことにより、球の位置はVRMLの座標からではなく、四角の位置から(0.0 -3.0 1.0)の位置に球が置くようになっている。
ソースプログラムは、下の表に記してある。


Program1-4 vrml14.wrl

#VRML V2.0 utf8



DEF CUBEandBALL Transform {

  translation -3.0 0.0 1.0    # 3m左、2m上、1m後ろ

  rotation -1 1 0.8 0.785

  children    [

    DEF CUBE Shape  {

      appearance Appearance   {

        material Material   {

          diffuseColor 1 0 0

          specularColor 0.9 0.9 0.9

        }

      }

      geometry Box { }

    }

      

    # このBallはCubeの階層の内側にある。

    # これにより、球の位置は四角形からの座標となる。

      

    DEF BALL Transform {

      translation 0.0 -3.0 1.0

      children    [

        DEF BALL Shape  {

          appearance Appearance   {

            material Material   {

              diffuseColor 0 1 0

              specularColor 0.9 0.9 0.9

            }

          }

          geometry Sphere { }

        }

      ]

    }

  ]

}

        

# これは3角錐をあらわす。

DEF transformCONE Transform  {

  children    [

    DEF CONE Shape  {

      appearance Appearance   {

        translation 3.0 0.0 1.0

          diffuseColor 0 0 1

          specularColor 0.9 0.9 0.9

        }

        material Material   {

      }

      geometry Cone { }

    }

  ]

}


図で表現するなら、下の図になる。

vrml13.wrlとvrml14.wrlの違い