VRML | 您所在的位置:网站首页 › transform同时旋转和缩放 › VRML |
Transform{ #children设定受该节点变换影响的所有子节点。 exposedField MFNode children [ ] #translation新旧坐标系的原点之间的距离。 exposedField SFVec3f translation 0.0 0.0 0.0 #rotation新坐标系相对于旧坐标系进行旋转的转动轴和旋转角度。 exposedField SFRotation rotation 0.0 0.0 1.0 0.0 #scale设定新坐标系在X、Y、Z方向的缩放系数 exposedField SFVec3f scale 1.0 1.0 1.0 #scaleOrientation用于设定旋转轴和旋转角度。具体为:先按照旋转后的新坐标系进行缩放操作,然后再坐标系将旋转回原方位。 exposedField SFRotation scaleOrientation 0 0 1 0 #center设定一个点,位于新坐标系的原点,坐标系的旋转和缩放均围绕该中心点进行。 exposedField SFVec3f center 0.0 0.0 0.0 #bboxCenter设定包围该变换所有子节点的区域的中心坐标点。 field SFVec3f bboxCenter 0.0 0.0 0.0 #bboxSize设定包围该变换所有子节点的区域X、Y、Z方向上的尺寸。 field SFVec3f bboxSize -1.0 -1.0 -1.0 #addChildren将指定的子节点增加到子节点列表中。 eventIn MFNode addChildren #removeChildren将指定的子节点从子节点列表中删除。 eventIn MFNode removeChildren }
坐标变换规则: 平移规则:沿坐标轴正向移动时,平移量为正。平移量是原新坐标系原点之间的距离。 旋转规则:以原点到(x,y,z)的方向线为旋转轴,按右手螺旋法则旋转a弧度。旋转轴是原新坐标系原点之间的连线,方向符合 右手定则。 缩放规则:缩放系数大于1放大,小于1缩小。 新坐标系只在节点内有效。children下只有一个成员节点时,中括号可省略。 对造型进行平移、旋转、缩放多项操作时,不论在程序中的排列顺序如何,浏览器的执行顺序为: 先缩放,再旋转,最后平移。 空间坐标的平移 空间坐标的平移是通过Transform节点的translation域的域值设定,建立的新坐标系原点作为children域中所有子节点创建造型的 定位点,从而实现新旧坐标系造型之间的相对位置的移动和变化。 例子: #VRML V2.0 utf8 Shape{ #圆柱体造型 appearance Appearance{ material Material { diffuseColor 0 0 1 } } geometry Cylinder{ radius 1 height 2 } } Transform{ #添加坐标变换节点 translation 0 1.5 0 #圆锥体沿Y轴向上平移1.5 children[ Shape{ #圆锥体造型 appearance Appearance{ material Material{ diffuseColor 0 1 0 } } geometry Cone{ bottomRadius 2 height 1 } } ] } 坐标的旋转 实现坐标系的旋转,需要确定旋转轴、旋转方向和旋转角度。旋转轴是VRML空间中一点到原点的直线,坐标轴围绕该直线旋转,旋转方向符合右手规则,旋转角度是该坐标轴向所预定的旋转方向旋转的角度大小,以弧度为单位。 通过设定Transform节点的rotation域值,可以在VRML空间中创建旋转坐标系,即可使坐标系向所希望的方向旋转。 一些常用角度的弧度值(弧度=角度*π/180)
例子: #VRML V2.0 utf8 Transform { rotation 1 0 0 1.571 children [ Shape { #表壳造型 appearance Appearance { material Material { diffuseColor 0.7 0.2 0.2 } } geometry Cylinder { radius 2.2 height 0.5 } } ] } 坐标的缩放 使用Transform节点的scale、scaleOrientation和center域的域值设定不同方向上的缩放比例,形成一个新的缩放坐标系, 并在新坐标系中创建一个或一组经过缩放的造型。 利用scaleOrientation域实现定向缩放,即在缩放前旋转新的坐标系,缩放后再将其旋转回来,以使坐标系能在任意方向上缩放。由于缩放后再旋转回来,所以物体造型并没有被旋转,即scaleOrientation域只影响缩放的方向。 例子: #VRML V2.0 utf8 Shape{ #白色圆球造型 appearance Appearance{ material Material{ diffuseColor 1 1 1 } } geometry Sphere{ radius 1.5 } } Transform{ #红色椭圆球造型 scale 2 1.1 1.1 #XYZ各个方向缩放系数 children[ Shape{ appearance Appearance { material Material { diffuseColor 1 0 0 transparency 0.4 #半透明设置 } } geometry Sphere{ radius 1.5 } } ] } 造型沿指定中心点缩放 center域的域值是以新的缩放中心点作为参考原点的坐标值,即原始坐标原点在新的坐标系中的坐标值,与通常将原始坐标系作为参照物的习惯相反。 如缩放中心点设定为center 0 -1 0,说明原始坐标原点在Y方向上距离新的缩放中心点向下一个单位。 例子: #VRML V2.0 utf8 Shape { # 基准参考平面 appearance Appearance { material Material { diffuseColor 1 0.5 0.4 specularColor 0.7 0.4 0.4 ambientIntensity 0.15 shininess 0.9 } } geometry Box { size 8 0.1 3 } } Shape { # 标准圆柱体 appearance Appearance { material Material { diffuseColor 0.3 0.09 0.21 specularColor 0.67 0.58 0.83 ambientIntensity 0.0467 shininess 0.07 } } geometry Cylinder {} } Transform { # 左边圆柱体 translation -3 0 0 scale 1 2 1 center 0 -1 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0.32 0.54 0.26 specularColor 0.46 0.46 0.46 ambientIntensity 0.0933 shininess 0.51 } } geometry Cylinder {} } ] } Transform { # 右边圆柱体 translation 3 0 0 scale 1 2 1 center 0 2 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0.3 0.09 0.21 specularColor 0.67 0.58 0.83 ambientIntensity 0.0467 shininess 0.07 } } geometry Cylinder {} } ] } |
CopyRight 2018-2019 实验室设备网 版权所有 |