📄 ch21.htm
字号:
24 } # End Separator<BR>
25<BR>
26 Separator {<BR>
27 Material {<BR>
28 ambientColor .1 .1 .1<BR>
29 } # End Material<BR>
30 Transform {<BR>
31 translation .15 .1 0<BR>
32 } # End Transform<BR>
33 Cube {<BR>
34 width .1<BR>
35 height .2<BR>
36 depth .1<BR>
37 }<BR>
38<BR>
39 } # End Separator<BR>
40<BR>
41 Separator {<BR>
42 Material {<BR>
43 ambientColor .2 .2 .2<BR>
44 } # End Material<BR>
45 Transform {<BR>
46 translation .25 .15 0<BR>
47 } # End Transform<BR>
48 Cube {<BR>
49 width .1<BR>
50 height .3<BR>
51 depth .1<BR>
52 }<BR>
53<BR>
54 } # End Separator<BR>
55<BR>
56 Separator {<BR>
57 Material {<BR>
58 ambientColor .3 .3 .3<BR>
59 } # End Material<BR>
60 Transform {<BR>
61 translation .35 .2 0<BR>
62 } # End Transform<BR>
63 Cube {<BR>
64 width .1<BR>
65 height .4<BR>
66 depth .1<BR>
67 }<BR>
68<BR>
69 } # End Separator<BR>
70<BR>
71 Separator {<BR>
72 Material {<BR>
73 ambientColor .4 .4 .4<BR>
74 } # End Material<BR>
75 Transform {<BR>
76 translation .45 .25 0<BR>
77 } # End Transform<BR>
78 Cube {<BR>
79 width .1<BR>
80 height .5<BR>
81 depth .1<BR>
82 }<BR>
83<BR>
84 } # End Separator<BR>
85<BR>
86 Separator {<BR>
87 Material {<BR>
88 ambientColor .5 .5 .5<BR>
89 } # End Material<BR>
90 Transform {<BR>
91 translation .55 .3 0<BR>
92 } # End Transform<BR>
93 Cube {<BR>
94 width .1<BR>
95 height .6<BR>
96 depth .1<BR>
97 }<BR>
98<BR>
99 } # End Separator<BR>
100<BR>
101 Separator {<BR>
102 Material {<BR>
103 ambientColor .6 .6 .6<BR>
104 } # End Material<BR>
105 Transform {<BR>
106 translation .65 .35 0<BR>
107 } # End Transform<BR>
108 Cube {<BR>
109 width .1<BR>
110 height .7<BR>
111 depth .1<BR>
112 }<BR>
113<BR>
114 } # End Separator<BR>
115<BR>
116 Separator {<BR>
117 Material {<BR>
118 ambientColor .7 .7 .7<BR>
119 } # End Material<BR>
120 Transform {<BR>
121 translation .75 .4 0<BR>
122 } # End Transform<BR>
123 Cube {<BR>
124 width .1<BR>
125 height .8<BR>
126 depth .1<BR>
127 }<BR>
128<BR>
129 } # End Separator<BR>
130<BR>
131 Separator {<BR>
132 Material {<BR>
133 ambientColor .8 .8 .8<BR>
134 } # End Material<BR>
135 Transform {<BR>
136 translation .85 .45 0<BR>
137 } # End Transform<BR>
138 Cube {<BR>
139 width .1<BR>
140 height .9<BR>
141 depth .1<BR>
142 }<BR>
143<BR>
144 } # End Separator<BR>
145<BR>
146 } # End Separator</FONT></TT>
</BLOCKQUOTE>
<HR>
<P>
The script can be modified to use cylinders instead of cubes with
a minor adjustment. The modified script to use cylinders is shown
in Listing 21.5. Note the use of <TT><FONT FACE="Courier">VRML::Cylinder</FONT></TT>
instead of <TT><FONT FACE="Courier">Cube</FONT></TT>. Also, note
how the parameters to <TT><FONT FACE="Courier">Cylinder</FONT></TT>
are different from <TT><FONT FACE="Courier">Cube</FONT></TT>,
but the calling sequence to put each <TT><FONT FACE="Courier">Cylinder</FONT></TT>
at its location is not very different from the calling sequence
used when placing <TT><FONT FACE="Courier">Cube</FONT></TT>s.
<P>
Listing 21.6 presents the output generated by the code in Listing
21.5. Compare Listing 21.6 with Listing 21.4 and notice how the
cylinders are translated and created. Figure 21.2 illustrates
using cylinders to represent data.
<P>
<A HREF="f21-2.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/f21-2.gif" ><B>Figure 21.2 : </B><I>Using cylinders to represent data.</I></A>
<HR>
<BLOCKQUOTE>
<B>Listing 21.5. Using cylinders instead of cubes to represent
data.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier"> 1 #!/usr/bin/perl<BR>
2<BR>
3 use VRML;<BR>
4 use VRML::Cylinder;<BR>
5<BR>
6 my $header = VRML::new();<BR>
7 $header->VRML::startHeader;<BR>
8<BR>
9 $header->VRML::startSeparator;<BR>
10<BR>
11 $header->VRML::setPointLight('location' => [1,1,1], 'color'
=> [0.2, 0.2, 0.5]);<BR>
12 $width = 0.1;<BR>
13 my @cubeb;<BR>
14<BR>
15 for ($i= 0; $i< 9; $i++) {<BR>
16 $j
= $width / 2 + $i * $width;<BR>
17 $ht
= $i * 0.1 + 0.1;<BR>
18 $cubeb[$i]
= $header->VRML::putCylinder(<BR>
19 'radius'
=> $width/2, 'height' => $ht , 'parts' => 'ALL',<BR>
20 'translation'
=> [$j,$ht/2,0],<BR>
21 'ambientColor'
=> [$i/10, $i/10,$i/10]<BR>
22 );
<BR>
23 }
<BR>
24<BR>
25 $header->VRML::stopSeparator;</FONT></TT>
</BLOCKQUOTE>
<HR>
<HR>
<BLOCKQUOTE>
<B>Listing 21.6. VRML output when using cylinders instead of cubes.
<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier"> 1 #VRML V1.0 ascii<BR>
2 #<BR>
3 # Created by VRML.pm flag<BR>
4 #<BR>
5<BR>
6 Separator {<BR>
7 PointLight {<BR>
8 location 1 1 1<BR>
9 color .2 .2 .5<BR>
10 } # End PointLight<BR>
11 Separator {<BR>
12 Material {<BR>
13 ambientColor 0 0 0<BR>
14 } # End Material<BR>
15 Transform {<BR>
16 translation .05 .05 0<BR>
17 } # End Transform<BR>
18 Cylinder {<BR>
19 parts ALL<BR>
20 radius .05<BR>
21 height .1<BR>
22 }<BR>
23<BR>
24 } # End Separator<BR>
25<BR>
26 Separator {<BR>
27 Material {<BR>
28 ambientColor .1 .1 .1<BR>
29 } # End Material<BR>
30 Transform {<BR>
31 translation .15 .1 0<BR>
32 } # End Transform<BR>
33 Cylinder {<BR>
34 parts ALL<BR>
35 radius .05<BR>
36 height .2<BR>
37 }<BR>
38<BR>
39 } # End Separator<BR>
40<BR>
41 Separator {<BR>
42 Material {<BR>
43 ambientColor .2 .2 .2<BR>
44 } # End Material<BR>
45 Transform {<BR>
46 translation .25 .15 0<BR>
47 } # End Transform<BR>
48 Cylinder {<BR>
49 parts ALL<BR>
50 radius .05<BR>
51 height .3<BR>
52 }<BR>
53<BR>
54 } # End Separator<BR>
55<BR>
56 Separator {<BR>
57 Material {<BR>
58 ambientColor .3 .3 .3<BR>
59 } # End Material<BR>
60 Transform {<BR>
61 translation .35 .2 0<BR>
62 } # End Transform<BR>
63 Cylinder {<BR>
64 parts ALL<BR>
65 radius .05<BR>
66 height .4<BR>
67 }<BR>
68<BR>
69 } # End Separator<BR>
70<BR>
71 Separator {<BR>
72 Material {<BR>
73 ambientColor .4 .4 .4<BR>
74 } # End Material<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -