⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch21.htm

📁 《Perl 5 Unreleased》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
&nbsp;75 Transform {<BR>

&nbsp;76 translation .45 .25 0<BR>

&nbsp;77 } # End Transform<BR>

&nbsp;78 Cylinder {<BR>

&nbsp;79 parts ALL<BR>

&nbsp;80 radius .05<BR>

&nbsp;81 height .5<BR>

&nbsp;82 }<BR>

&nbsp;83<BR>

&nbsp;84 } # End Separator<BR>

&nbsp;85<BR>

&nbsp;86 Separator {<BR>

&nbsp;87 Material {<BR>

&nbsp;88 ambientColor .5 .5 .5<BR>

&nbsp;89 } # End Material<BR>

&nbsp;90 Transform {<BR>

&nbsp;91 translation .55 .3 0<BR>

&nbsp;92 } # End Transform<BR>

&nbsp;93 Cylinder {<BR>

&nbsp;94 parts ALL<BR>

&nbsp;95 radius .05<BR>

&nbsp;96 height .6<BR>

&nbsp;97 }<BR>

&nbsp;98<BR>

&nbsp;99 } # End Separator<BR>

100<BR>

101&nbsp;&nbsp;Separator {<BR>

102&nbsp;&nbsp;Material {<BR>

103&nbsp;&nbsp;ambientColor .6 .6 .6<BR>

104&nbsp;&nbsp;} # End Material<BR>

105&nbsp;&nbsp;Transform {<BR>

106&nbsp;&nbsp;translation .65 .35 0<BR>

107&nbsp;&nbsp;} # End Transform<BR>

108&nbsp;&nbsp;Cylinder {<BR>

109&nbsp;&nbsp;parts ALL<BR>

110&nbsp;&nbsp;radius .05<BR>

111&nbsp;&nbsp;height .7<BR>

112&nbsp;&nbsp;}<BR>

113<BR>

114&nbsp;&nbsp;} # End Separator<BR>

115<BR>

116&nbsp;&nbsp;Separator {<BR>

117&nbsp;&nbsp;Material {<BR>

118&nbsp;&nbsp;ambientColor .7 .7 .7<BR>

119&nbsp;&nbsp;} # End Material<BR>

120&nbsp;&nbsp;Transform {<BR>

121&nbsp;&nbsp;translation .75 .4 0<BR>

122&nbsp;&nbsp;} # End Transform<BR>

123&nbsp;&nbsp;Cylinder {<BR>

124&nbsp;&nbsp;parts ALL<BR>

125&nbsp;&nbsp;radius .05<BR>

126&nbsp;&nbsp;height .8<BR>

127&nbsp;&nbsp;}<BR>

128<BR>

129&nbsp;&nbsp;} # End Separator<BR>

130<BR>

131&nbsp;&nbsp;Separator {<BR>

132&nbsp;&nbsp;Material {<BR>

133&nbsp;&nbsp;ambientColor .8 .8 .8<BR>

134&nbsp;&nbsp;} # End Material<BR>

135&nbsp;&nbsp;Transform {<BR>

136&nbsp;&nbsp;translation .85 .45 0<BR>

137&nbsp;&nbsp;} # End Transform<BR>

138&nbsp;&nbsp;Cylinder {<BR>

139&nbsp;&nbsp;parts ALL<BR>

140&nbsp;&nbsp;radius .05<BR>

141&nbsp;&nbsp;height .9<BR>

142&nbsp;&nbsp;}<BR>

143<BR>

144&nbsp;&nbsp;} # End Separator<BR>

145<BR>

146&nbsp;&nbsp;} # End Separator</FONT></TT>

</BLOCKQUOTE>

<HR>

<P>

The <TT><FONT FACE="Courier">for</FONT></TT> loop in Listing 21.5

is a pretty canned approach to generating the test data for this

chapter. In most cases, you'll want to generate your data in a

function of some sort and then display it. A sample usage of such

a function is shown in Listing 21.7.

<HR>

<BLOCKQUOTE>

<B>Listing 21.7. Using a function to get data for display.<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">&nbsp;1 #!/usr/bin/perl<BR>

&nbsp;2<BR>

&nbsp;3 use VRML;<BR>

&nbsp;4 use VRML::Cylinder;<BR>

&nbsp;5<BR>

&nbsp;6 sub getResults {<BR>

&nbsp;7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my

@answers;<BR>

&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my

$i;<BR>

&nbsp;9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for

($i = 0; $i &lt; 9; $i++) {<BR>

10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$answers[$i]

= $i;<BR>

11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

<BR>

12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return

(@answers);<BR>

13 }<BR>

14<BR>

15 my $header = VRML::new();<BR>

16 $header-&gt;VRML::startHeader;<BR>

17<BR>

18 $header-&gt;VRML::startSeparator;<BR>

19<BR>

20 $header-&gt;VRML::setPointLight('location' =&gt; [1,1,1], 'color'

=&gt;<BR>

&nbsp;&nbsp;&nbsp;&Acirc;[0.2, 0.2, 0.5]);<BR>

21 $width = 0.1;<BR>

22 my @cubeb;<BR>

23<BR>

24 @results = &amp;getResults();<BR>

25<BR>

26 foreach $i (@results) {<BR>

27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$j

= $width / 2 + $i * $width;<BR>

28&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ht

= $i * 0.1 + 0.1;<BR>

29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$cubeb[$i]

= $header-&gt;VRML::putCylinder(<BR>

30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'radius'

=&gt; $width/2, 'height' =&gt; $ht , 'parts' =&gt;<BR>

&nbsp;&nbsp; &Acirc;'ALL',<BR>

31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'translation'

=&gt; [$j,$ht/2,0],<BR>

32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ambientColor'

=&gt; [$i/10, $i/10,$i/10]<BR>

33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);

<BR>

34&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

<BR>

35<BR>

36 $header-&gt;VRML::stopSeparator;</FONT></TT>

</BLOCKQUOTE>

<HR>

<P>

In Listing 21.7, the subroutine <TT><FONT FACE="Courier">getResults</FONT></TT>

is used to generate the data required for display. The <TT><FONT FACE="Courier">getResults</FONT></TT>

subroutine in this example is only doing what the <TT><FONT FACE="Courier">for</FONT></TT>

loop did. However, there is nothing preventing you from replacing

the <TT><FONT FACE="Courier">getResults</FONT></TT> code to access

data, for example.

<P>

More than one column of data is also possible. Look at Listing

21.8. The output from this run is not listed here but is shown

in Figure 21.3.

<P>

<A HREF="f21-3.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/f21-3.gif" ><B>Figure 21.3 : </B><I>Using boxes and cylinders to represent data.</I></A>

<HR>

<BLOCKQUOTE>

<B>Listing 21.8. Using multiple columns.<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">&nbsp;1&nbsp;#!/usr/bin/perl<BR>

&nbsp;2<BR>

&nbsp;3 use VRML;<BR>

&nbsp;4 use VRML::Cube;<BR>

&nbsp;5 use VRML::Cylinder;<BR>

&nbsp;6<BR>

&nbsp;7 sub getResults {<BR>

&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my

@answers;<BR>

&nbsp;9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my

$i;<BR>

10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for

($i = 0; $i &lt; 9; $i++) {<BR>

11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$answers[$i]

= $i;<BR>

12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

<BR>

13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return

(@answers);<BR>

14 }<BR>

15<BR>

16 my $header = VRML::new();<BR>

17 $header-&gt;VRML::startHeader;<BR>

18<BR>

19 $header-&gt;VRML::startSeparator;<BR>

20 $width = 0.1;<BR>

21 my @cyl;<BR>

22<BR>

23 @results = &amp;getResults();<BR>

24<BR>

25 foreach $i (@results) {<BR>

26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$j

= $width / 2 + $i * $width;<BR>

27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ht

= $i * 0.1 + 0.1;<BR>

28&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$cyl[$i]

= $header-&gt;VRML::putCylinder(<BR>

29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'radius'

=&gt; $width/2, 'height' =&gt; $ht , 'parts' =&gt;<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&Acirc;'ALL',

<BR>

30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'translation'

=&gt; [$j,$ht/2,0],<BR>

31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ambientColor'

=&gt; [$i/10, $i/10,$i/10]<BR>

32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);

<BR>

33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

<BR>

34<BR>

35 #<BR>

36 # Start second column.<BR>

37 #<BR>

38 $width = 0.1;<BR>

39 my @cub;<BR>

40<BR>

41 @results = &amp;getResults();<BR>

42<BR>

43 foreach $i (@results) {<BR>

44&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$j

= $width / 2 + $i * $width;<BR>

45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ht

= $i * 0.1 + 0.1;<BR>

46&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$cub[$i]

= $header-&gt;VRML::putCube(<BR>

47&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'width'

=&gt; $width/2, 'height' =&gt; $ht , 'depth' =&gt;<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&Acirc;$width,

<BR>

48&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'translation'

=&gt; [$j,$ht/2,$width],<BR>

49&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ambientColor'

=&gt; [$i/10, $i/10,$i/10]<BR>

50&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);

<BR>

51&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

}<BR>

52 $header-&gt;VRML::stopSeparator;</FONT></TT>

</BLOCKQUOTE>

<HR>

<P>

In the code shown in Listing 21.8, two columns of data are created.

Note the use of the Z offset in doing the translation of <TT><FONT FACE="Courier">Cylinder</FONT></TT>s.

Also note that only one separator node is used for the entire

image and one for each node.

<H2><A NAME="HowtoViewYourWorld"><B><FONT SIZE=5 COLOR=#FF0000>How

to View Your World</FONT></B></A></H2>

<P>

There are several VRML viewers available on the market today.

Some are totally free of charge, some free of charge up to 30

days, and the rest require a fee of anywhere from $50 to thousands

of dollars. The following is a list of some of the vendors, their

viewers, and what they have to offer. Most of the browsers are

for Windows NT or Windows 95, but there are quite a few for UNIX

workstations. A few of these are listed here. However, I would

advise you to do a search on the Internet for a more comprehensive

list. Here's the list:

<UL>

<LI>WorldView-A Windows 95, NT, and 3.1 product by InterVista,

Inc.

<LI>NavFlyer-Made by Micro Green, Inc. Requires Win32 if you are

running under Windows NT. Also requires the WinG graphics library.

<LI>WbFX-Runs with Mosaic and the 16-bit version of Netscape only.

Made only for Windows 3.1 by Paper Software, Inc.

</UL>

<P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -