嘗試中.....
作業(yè)要求:
? ? ?制作旋轉(zhuǎn)門,當(dāng)鼠標(biāo)在玻璃門上拖拽時(shí)玻璃門旋轉(zhuǎn)。
制作過程如下:
1、先建立1個(gè)橫向的立方體,充當(dāng)玻璃門1
代碼:
Transform {
?? ??? ??? ?translation?? ?0 0.6 0? ? ? ? ? ? ?#立方體向上移動(dòng)到0.6位置
?? ??? ??? ?children [
?? ??? ??? ? ?Shape {
?? ??? ? ? ??? ?appearance Appearance {? ?#外觀域
?? ??? ??? ??? ?material ?Material?? ?{
?? ??? ??? ??? ??? ?diffuseColor 0 0.2 0.5? ?#材質(zhì)顏色設(shè)置
?? ??? ??? ??? ??? ?transparency 0.6? ? ? ? ? #透明度設(shè)置
?? ??? ??? ??? ?}}
?? ??? ??? ??? ?geometry Box {? ? ? #立方體幾個(gè)造型節(jié)點(diǎn)??
?? ??? ??? ??? ??? ?size 2 1 0.1? ? ? ? ?#立方體的大小,三維坐標(biāo)代表長寬高
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} ]}
2、建立1個(gè)縱向的立方體,充當(dāng)玻璃門2
(復(fù)制上一個(gè)橫向的立方體,并旋轉(zhuǎn)90度即可)
代碼:
Transform {
?? ??? ??? ?translation?? ?0 0.6 0
?? ??? ??? ?rotation 0 1 0 1.571? ? ? ? #立方體繞著y軸旋轉(zhuǎn)90度
?? ??? ??? ?children [
?? ??? ??? ? ?Shape {
?? ??? ? ? ??? ?appearance Appearance {
?? ??? ??? ??? ?material ?Material?? ?{
?? ??? ??? ??? ??? ?diffuseColor 0 0.2 0.5
?? ??? ??? ??? ??? ?transparency 0.6
?? ??? ??? ??? ?}}
?? ??? ??? ??? ?geometry Box {
?? ??? ??? ??? ??? ?size 2 1 0.1
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} ]}
3、制作中間的柱子,應(yīng)該使用圓柱體幾何造型節(jié)點(diǎn)
代碼:
Transform {
?? ??? ??? ?translation?? ?0 0.6 0? ? ? ??#立方體向上移動(dòng)到0.6位置
?? ??? ??? ?children [
?? ??? ??? ? ?Shape {
?? ??? ? ? ??? ?appearance Appearance {
?? ??? ??? ??? ?material ?Material?? ?{
?? ??? ??? ??? ??? ?diffuseColor 0 1 0
?? ??? ??? ??? ?}}
?? ??? ??? ??? ?geometry Cylinder {? ? ?#圓柱體幾何造型節(jié)點(diǎn)
?? ??? ??? ??? ??? ?height 1.2? ? ? ? ? ? ? ? #圓柱體高為1.2
?? ??? ??? ??? ??? ?radius 0.05? ? ? ? ? ? ? #半徑為0.05
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} ]}
4、制作底面,應(yīng)該用圓柱體幾何造型節(jié)點(diǎn)
代碼:
Transform {?
?? ??? ??? ?children [
?? ??? ??? ? ?Shape {
?? ??? ? ? ??? ?appearance Appearance {
?? ??? ??? ??? ?material ?Material?? ?{
?? ??? ??? ??? ??? ?diffuseColor 0.8 0.2 0.1 ?
?? ??? ??? ??? ?}}
?? ??? ??? ??? ?geometry Cylinder {? ??#圓柱體幾何造型節(jié)點(diǎn)
?? ??? ??? ??? ??? ?height 0.06? ? ? ? ? ? ?#圓柱體高為1.2
?? ??? ??? ??? ??? ?radius 1.4? ? ? ? ? ? ? ?#高為1.4? ? ?
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} ]}
5、制作頂面,跟上面制作底面是一樣的
(在底面的基礎(chǔ)上修改位置即可)
代碼:
Transform {
?? ??? ??? ?translation?? ?0 1.2 0? ? ?#圓柱體向上移動(dòng)到1.2的位置上
?? ??? ??? ?children [
?? ??? ??? ? ?Shape {
?? ??? ? ? ??? ?appearance Appearance {
?? ??? ??? ??? ?material ?Material?? ?{
?? ??? ??? ??? ??? ?diffuseColor 0.8 0.2 0.1? ??? ??? ??? ??? ?
?? ??? ??? ??? ?}}
?? ??? ??? ??? ?geometry Cylinder {
?? ??? ??? ??? ??? ?height 0.06
?? ??? ??? ??? ??? ?radius 1.4?? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} ]}
6、在左右兩邊添加柱子
(復(fù)制“3、中間的柱子”的代碼,修改位置和半徑即可)
右邊柱子代碼:
?Transform {
?? ??? ??? ?translation?? ?1.2 0.6 0? ? ? ??#圓柱體向右移動(dòng)1.2,向上移動(dòng)到1.2的位置上
?? ??? ??? ?children [
?? ??? ??? ? ?Shape {
?? ??? ? ? ??? ?appearance Appearance {
?? ??? ??? ??? ?material ?Material?? ?{
?? ??? ??? ??? ??? ?diffuseColor 0.8 0.2 0.1
?? ??? ??? ??? ?}}
?? ??? ??? ??? ?geometry Cylinder {
?? ??? ??? ??? ??? ?height 1.2
?? ??? ??? ??? ??? ?radius 0.09?? ??? ??? ??? ?
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} ]}
左邊柱子代碼:
?Transform {
?? ??? ??? ?translation?? ?-1.2 0.6 0? ??#圓柱體向左移動(dòng)1.2,向上移動(dòng)到1.2的位置上
?? ??? ??? ?children [
?? ??? ??? ? ?Shape {
?? ??? ? ? ??? ?appearance Appearance {
?? ??? ??? ??? ?material ?Material?? ?{
?? ??? ??? ??? ??? ?diffuseColor 0.8 0.2 0.1? ??
?? ??? ??? ??? ?}}
?? ??? ??? ??? ?geometry Cylinder {
?? ??? ??? ??? ??? ?height 1.2
?? ??? ??? ??? ??? ?radius 0.09?? ??? ??? ??? ?
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} ]}
1-6是制作基本造型,接下來是動(dòng)畫制作部分
7、先將上面的1和2放在同一個(gè)坐標(biāo)節(jié)點(diǎn)下
如:Transform {
?? ?children [立方體1,立方體2? ]}
8、在7的基礎(chǔ)上修改,在Transform前面添加DEF lif
注:DEF的作用是在場(chǎng)景中需要多次使用的同一節(jié)點(diǎn),可以通過節(jié)點(diǎn)重定義后,在后面使用引用的方法多次調(diào)用。
如:DEF lif Transform {? ? ? #DEF給玻璃門的Transform節(jié)點(diǎn)命名為lif
?? ?children [立方體1,立方體2? ]}
9、利用圓柱體傳感器,使當(dāng)用鼠標(biāo)拖拽時(shí),造型軌跡會(huì)類似于圓柱體旋轉(zhuǎn),簡(jiǎn)單說就是鼠標(biāo)拖拽時(shí),造型會(huì)沿著y軸旋轉(zhuǎn)。
代碼:
?? ?DEF?? ?blm CylinderSensor?? ?{? ?#DEF給傳感器CylinderSensor節(jié)點(diǎn)命名為blm
?? ??? ?offset?? ?0.785? ? ?# 設(shè)定造型的初始旋轉(zhuǎn)角度,當(dāng)首次單擊鼠標(biāo)時(shí),造型繞圓柱體中心軸相對(duì)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 于初始位置旋轉(zhuǎn)角度。
? ? ? ? autoOffset?? ?TRUE? ? #是否自動(dòng)記憶上次旋轉(zhuǎn)的終點(diǎn)角度
}
10、最后一步,用ROUTE? TO,使事件出口和事件入口通過路徑相連
ROUTE 語句 從一個(gè)節(jié)點(diǎn)的事件出口到另一個(gè)節(jié)點(diǎn)的事件入口,傳送事件的路徑叫路由。
代碼:
ROUTE blm.rotation_changed TO lif.rotation
#當(dāng)CylinderSensor圓柱體傳感器節(jié)點(diǎn)發(fā)生改變時(shí),就會(huì)影響到Transform坐標(biāo)變換節(jié)點(diǎn)的改變
#rotation_changed(出事件):當(dāng)鼠標(biāo)拖拽造型時(shí),傳感器不斷輸出立方體幾何節(jié)點(diǎn)造型旋轉(zhuǎn)的角度值。
總體代碼:
#VRML V2.0 utf8 DEF lif Transform { children [ Transform { translation 0 0.6 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0 0.2 0.5 transparency 0.6 }} geometry Box { size 2 1 0.1 } } ]} Transform { translation 0 0.6 0 rotation 0 1 0 1.571 children [ Shape { appearance Appearance { material Material { diffuseColor 0 0.2 0.5 transparency 0.6 }} geometry Box { size 2 1 0.1 } } ]} ]} Transform { translation 0 0.6 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0 1 0 }} geometry Cylinder { height 1.2 radius 0.05 } } ]} Transform { translation 0 0 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0.8 0.2 0.1 }} geometry Cylinder { height 0.06 radius 1.4 } } ]} Transform { translation 0 1.2 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0.8 0.2 0.1 }} geometry Cylinder { height 0.06 radius 1.4 } } ]} Transform { translation -1.2 0.6 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0.8 0.2 0.1 }} geometry Cylinder { height 1.2 radius 0.09 } } ]} Transform { translation 1.2 0.6 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0.8 0.2 0.1 }} geometry Cylinder { height 1.2 radius 0.09 } } ]} DEF blm CylinderSensor { offset 0.785 autoOffset TRUE } ROUTE blm.rotation_changed TO lif.rotation
最后運(yùn)行結(jié)果:
?文章來源:http://www.zghlxwxcb.cn/news/detail-445282.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-445282.html
到了這里,關(guān)于虛擬現(xiàn)實(shí)技術(shù)vrml“動(dòng)畫交互“——旋轉(zhuǎn)門練習(xí)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!