📄 ch21.htm
字号:
75 Transform {<BR>
76 translation .45 .25 0<BR>
77 } # End Transform<BR>
78 Cylinder {<BR>
79 parts ALL<BR>
80 radius .05<BR>
81 height .5<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 Cylinder {<BR>
94 parts ALL<BR>
95 radius .05<BR>
96 height .6<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 Cylinder {<BR>
109 parts ALL<BR>
110 radius .05<BR>
111 height .7<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 Cylinder {<BR>
124 parts ALL<BR>
125 radius .05<BR>
126 height .8<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 Cylinder {<BR>
139 parts ALL<BR>
140 radius .05<BR>
141 height .9<BR>
142 }<BR>
143<BR>
144 } # End Separator<BR>
145<BR>
146 } # 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"> 1 #!/usr/bin/perl<BR>
2<BR>
3 use VRML;<BR>
4 use VRML::Cylinder;<BR>
5<BR>
6 sub getResults {<BR>
7 my
@answers;<BR>
8 my
$i;<BR>
9 for
($i = 0; $i < 9; $i++) {<BR>
10 $answers[$i]
= $i;<BR>
11 }
<BR>
12 return
(@answers);<BR>
13 }<BR>
14<BR>
15 my $header = VRML::new();<BR>
16 $header->VRML::startHeader;<BR>
17<BR>
18 $header->VRML::startSeparator;<BR>
19<BR>
20 $header->VRML::setPointLight('location' => [1,1,1], 'color'
=><BR>
Â[0.2, 0.2, 0.5]);<BR>
21 $width = 0.1;<BR>
22 my @cubeb;<BR>
23<BR>
24 @results = &getResults();<BR>
25<BR>
26 foreach $i (@results) {<BR>
27 $j
= $width / 2 + $i * $width;<BR>
28 $ht
= $i * 0.1 + 0.1;<BR>
29 $cubeb[$i]
= $header->VRML::putCylinder(<BR>
30 'radius'
=> $width/2, 'height' => $ht , 'parts' =><BR>
Â'ALL',<BR>
31 'translation'
=> [$j,$ht/2,0],<BR>
32 'ambientColor'
=> [$i/10, $i/10,$i/10]<BR>
33 );
<BR>
34 }
<BR>
35<BR>
36 $header->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"> 1 #!/usr/bin/perl<BR>
2<BR>
3 use VRML;<BR>
4 use VRML::Cube;<BR>
5 use VRML::Cylinder;<BR>
6<BR>
7 sub getResults {<BR>
8 my
@answers;<BR>
9 my
$i;<BR>
10 for
($i = 0; $i < 9; $i++) {<BR>
11 $answers[$i]
= $i;<BR>
12 }
<BR>
13 return
(@answers);<BR>
14 }<BR>
15<BR>
16 my $header = VRML::new();<BR>
17 $header->VRML::startHeader;<BR>
18<BR>
19 $header->VRML::startSeparator;<BR>
20 $width = 0.1;<BR>
21 my @cyl;<BR>
22<BR>
23 @results = &getResults();<BR>
24<BR>
25 foreach $i (@results) {<BR>
26 $j
= $width / 2 + $i * $width;<BR>
27 $ht
= $i * 0.1 + 0.1;<BR>
28 $cyl[$i]
= $header->VRML::putCylinder(<BR>
29 'radius'
=> $width/2, 'height' => $ht , 'parts' =><BR>
Â'ALL',
<BR>
30 'translation'
=> [$j,$ht/2,0],<BR>
31 'ambientColor'
=> [$i/10, $i/10,$i/10]<BR>
32 );
<BR>
33 }
<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 = &getResults();<BR>
42<BR>
43 foreach $i (@results) {<BR>
44 $j
= $width / 2 + $i * $width;<BR>
45 $ht
= $i * 0.1 + 0.1;<BR>
46 $cub[$i]
= $header->VRML::putCube(<BR>
47 'width'
=> $width/2, 'height' => $ht , 'depth' =><BR>
Â$width,
<BR>
48 'translation'
=> [$j,$ht/2,$width],<BR>
49 'ambientColor'
=> [$i/10, $i/10,$i/10]<BR>
50 );
<BR>
51
}<BR>
52 $header->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 + -