Transformの例とViewpointの例

Transform(座標変換)

 Transformノードは、立体をグループ化し、そのグループのローカル座標を座標変換するノードです。次にTransformノードの例を示します。

ローカル座標の原点の移動と回転

 次の図は、赤い円柱がローカル座標の中心にあり、それを、右の方向に移動したもの(赤い円柱)、移動して回転したもの(緑の円柱)、移動して回転の中心を指定して回転したもの(青い円柱)を描いたものです。

 この図を描いたVRMLファイルを次に示します。移動はtranslationフィールドで、回転はrotationフィールドで指定します。回転の中心はcenterフィールドで移動後のローカル座標で与えます。


#VRML V2.0 utf8
#円柱   filename=transform_cylinder.wrl
#円柱の移動と回転
#center

DEF Red Shape {                                #red 
   appearance Appearance {
       material Material{ diffuseColor 1 0 0 }
   }
   geometry Cylinder {
           radius 0.2  height 3 }
}

Transform{                #red  translation
  translation  3 0 0
  children [ USE Red ]
}

DEF Green Transform{           #green  rotation
  translation 3 0 0 
  rotation  0 0 -1 0.5
  children [
   Shape {
   appearance Appearance {
       material Material{ diffuseColor 0 1 0 }
   }
   geometry Cylinder {
           radius 0.2  height 3 }
}
]}
DEF Blue Transform{                 #blue  center  rotation
  translation 3 0 0 
  center 0 -1.5 0
  rotation  0 0 -1 -0.5
  children [
   Shape {
   appearance Appearance {
       material Material{ diffuseColor 0 0 1 }
   }
   geometry Cylinder {
           radius 0.2  height 3 }
}
]}
原点の移動と回転 (クリックすると上の例がVRMLブラウザに表示されます)


ローカル座標のスケールとスケールの方向

 次の図には、赤い円柱がローカル座標の中心にあり、それを、右の方向に移動して回転したもの(緑の円柱)があります。また、緑の円柱をローカル座標系も含めてスケーリングしたもの、スケーリングの方向を指定してからスケーリングしたものも描いています。

 この図を描いたVRMLファイルを次に示します。移動はtranslationフィールドで、回転はrotationフィールドで指定します。スケーリングはscaleフィールドで3方向のファクターを与えます。scaleOrientationフィールドを設定すると、その方向にローカル座標を回転させてからスケーリングします。座標変換の詳細はTransformノードの説明を参照してください。


#VRML V2.0 utf8
#円柱   filename=transform_cylinder2.wrl
#円柱の回転
#scale と scaleOrientation

DEF Red Shape {                                #red 
   appearance Appearance {
       material Material{ diffuseColor 1 0 0 }
   }
   geometry Cylinder {
           radius 0.2  height 3 }
}

DEF Green Transform{           #green  rotation
  translation 2 0 0 
  rotation  0 0 -1 0.5
  children [
   Shape {
   appearance Appearance {
       material Material{ diffuseColor 0 1 0 }
   }
   geometry Cylinder {
           radius 0.2  height 3 }
}
]}

Transform{                #Green scale
  scale 1.5 0.5 1.5
  children [ USE Green ]
}

Transform{                #Green scale
  scaleOrientation 0 0 -1 0.5
#  rotation 0 0 -1 0.5
  scale 1.5 0.5 1.5
  children [ USE Green  ]
}
スケールとスケールの方向 (クリックすると上の例がVRMLブラウザに表示されます)


Viewpoint(視点と視線)

 次の例はいろいろなビューポイントを指定したものです。ビューポイントにはそれぞれdescriptionフィールドで名前を付けています。VRMLのブラウザに表示したときにブラウザのViewpoint Listボタンを使用して、ビューポイントを変えて表示してみてください。


#VRML V2.0 utf8
# Viewpoint  viewpoint.wrl
Background { skyColor 0.8 0.8 1 }
Viewpoint { description "Default"
}
Viewpoint { position 2.0 1.0 20.0 
            description "Position"
}
Viewpoint { position 2.0 1.0 15.0 
            orientation 0.0 0.0 -1.0 0.26
            description "Orientationz"
}
Viewpoint { position 2.0 1.0 15.0 
            orientation -1.0 0.0 0.0 0.26
            description "Orientationx"
}
Viewpoint { position 2.0 1.0 15.0 
            orientation 0.0 -1.0 0.0 0.26
            description "Orientationy"
}
Viewpoint { position -3.0 0.0 6.0 
            description "Position2"
}
Viewpoint { position 3.0 0.0 6.0 
            description "Position3"
}

 Transform { 
   translation -3 0 0
   children [
     Shape {
       appearance Appearance {
         material Material{ diffuseColor 0.2 0.8 0.6 }
      }
      geometry Box { size 3  4  2 }
     }
 ]}
 Transform { 
   translation 3 0 0
   children [
     Shape {
       appearance Appearance {
         material Material{ diffuseColor 0.2 0.6 0.8 }
      }
      geometry Box { size 4  4  2}
     }
 ]}
ビューポイントの指定 (クリックすると上の例がVRMLブラウザに表示されます)