add message ---
(perl script) ---
(sample wrl db)
<html>
<head>
<title>Get Message</title>
</head>
<body>
<h1>Type a short message:</h1>
<p>
<hr>
<form method="POST" action="/cgi-bin/mlbin/vrmlGraf.pl">
<input size=30 name="message">
<input type="submit" value="Add it!">
</form>
<hr>
</body>
</html>
-------------------------------
#!/usr/local/bin/perl
# add a new randomly translated text node
# limit number to N messages (count messages)
#
# Uses Steven E. Brenner's "cgi-lib.pl"
# available from http://cgi-lib.stanford.edu/cgi-lib/
#
require("cgi-lib.pl"); # use the library
&ReadParse; # parse the form's fields into "in" array
# collect the form data into easy to use variable names
$message = $in{'message'};
# read in the old wrl
open(WRL, "graf.wrl");
@lines = <WRL>;
close(WRL);
# reopen file to write out the new version
open(WRL, ">graf.wrl");
$numMessages = 0;
foreach $line (@lines) {
# look at line
# if it is place for new message, write out the new message,
# and a new place marker
if($line =~ /NEXT MESSAGE GOES HERE/) {
$x = (int((rand(10)-5)*10)/10);
$y = (int((rand(10)-5)*10)/10);
$z = (int((rand(10)-5)*10)/10);
$t = $x." ".$y." ".$z;
$rx = (int(rand()*100)/100);
$ry = (int(rand()*100)/100);
$rz = (int(rand()*100)/100);
$a = (int(rand(6.28)*10)/10);
$r = $rx." ".$ry." ".$rz." ".$a;
print WRL "\# NEXT MESSAGE GOES HERE\n";
print WRL "Message { t $t r $r string \"$message\" }\n\n";
}
# otherwise just reprint the line
else {
# if it's a message line, only print a limited number
if($line =~ /^Message/) {
$numMessages += 1;
if($numMessages < 20) {
print WRL $line;
}
}
# print all other lines
else { print WRL $line; }
}
}
close(WRL);
# reopen and reread the new file
open(WRL, "graf.wrl");
@lines = <WRL>;
close(WRL);
# send the file type to the browser
print "Content-type: model/vrml\n\n"; # note! must have both \n
# send the new file
foreach $line (@lines) { print $line; }
----------------------------------
#VRML V2.0 utf8
NavigationInfo { type "EXAMINE" }
PROTO Message [
field MFString string ""
field SFVec3f t 0 0 0
field SFRotation r 0 0 1 0
]
{
Transform {
translation IS t
rotation IS r
children Shape {
appearance Appearance {
material Material {}
}
geometry Text { string IS string }
}
}
}
# NEXT MESSAGE GOES HERE
Message { t 4.2 -0.2 -4.9 r 0.73 0.05 0.54 1.2 string "Dirt cheap" }
Message { t -1 1.1 -2.8 r 0.5 0.12 0.97 2.8 string "must sleep" }
Message { t 2 1.9 2.5 r 0.07 0.01 0.45 4.2 string "What next?" }
Message { t 1.7 -1.5 -3.9 r 0.3 0.13 0.65 2.9 string "Hrmmmm..." }
Message { t 0 -1.2 -2.3 r 0.73 0.07 0.23 1.1 string "four" }
Message { t -2.6 0.3 1.1 r 0.86 0.2 0.09 4.8 string "3 3 3 3" }
Message { t -0.6 3 1.6 r 0.66 0.93 0.03 5.3 string "22222" }