#!/usr/local/bin/perl5
# Set program defaults
$starfile = "starfile";
# Perl5 Modules utilized.
use CGI qw(:cgi-lib);
#Read in Data from WWW Form
&ReadParse;
#
# =============================================================
# EFFECTIVE PROGRAM BREAK : PART 1 - GETTING THE NEARBY STARS
# =============================================================
#
#
# Read in initial variables from the shell in case we're testing this...
#
$current = $ARGV[0];
$range = $ARGV[1];
#
# Set variables from form and do some error checking. If there are
# variables already supplied (e.g. from the shell), then don't bother
# reseting them from the "form data".
#
if ($#ARGV < 0) {
$header = 1;
$current = $in{'star'};
$range = $in{'range'};
}
# convert range into a distance squared number
$sqrange = $range**2;
if ($range < 1) {
print "Content-type: text/html\n\n";
print "
ERROR
\n";
exit;
}
if ($current < 1) {
print "Content-type: text/html\n\n";
print "ERROR
\n";
exit;
}
#
# Load up stardata into @data
#
open(DATA,"$starfile") || die "Sorry, but $starfile couldn't be opened.\n";
@data = ;
close(DATA);
# STARFILE format:
# $fields[0] is star number
# $fields[1] is class
# $fields[2] is star class
# $fields[3] is star size
# $fields[4] is magnitude
# $fields[5] is X
# $fields[6] is Y
# $fields[7] is Z
# $fields[8] is the System Name
# First, determine what are the XYZ coordinates of our "central" star
foreach (@data) {
if (/^$current:/) {
@fields = split(/:/);
$cx = $fields[5];
$cy = $fields[6];
$cz = $fields[7];
}
}
foreach (@data) {
# compute distance to our central coordinates and add that to the
# beginning of the string for the stardata.
@fields = split(/:/);
$starnum = $fields[0];
$dx = $fields[5]-$cx;
$dy = $fields[6]-$cy;
$dz = $fields[7]-$cz;
$sqdistance = $dx**2 + $dy**2 + $dz**2;
# determine if the sq.distance is less than the sq.range
# specified. If push the location (new format) into the
# results array. The results array fields will be formatted:
# $fields[0] is distance to central star
# $fields[1] is star number
# $fields[2] is class
# $fields[3] is star class
# $fields[4] is star size
# $fields[5] is magnitude
# $fields[6] is X
# $fields[7] is Y
# $fields[8] is Z
# $fields[9] is the System Name
if ($sqdistance <= $sqrange) {
#
# diagnostic - print out result fields
#
# print "$sqdistance:$_";
#
# place all results into a hash table for later processing based
# on Star Number.
#
push(@results,"$sqdistance:$_");
}
}
#
# =============================================================
# EFFECTIVE PROGRAM BREAK : PART 2 - CREATING THE MAP
# =============================================================
#
#
# Print out VRML header
#
if ($header > 0) {
print "Content-type: x-world/x-vrml\n\n";
}
print "#VRML V1.0 ascii\n";
print "Separator {\n";
print "PointLight {\n";
print " on TRUE\n";
print " intensity 1\n";
print " color 1 1 1\n";
print " location 0 0 -1000\n";
print "}\n";
print "PointLight {\n";
print " on TRUE\n";
print " intensity 1\n";
print " color 1 1 1\n";
print " location 0 0 1000\n";
print "}\n";
foreach $current (@results) {
print "# *** WORKING ON *** $current\n";
# $fields[0] is distance to central star
# $fields[1] is star number
# $fields[2] is class
# $fields[3] is star class
# $fields[4] is star size
# $fields[5] is magnitude
# $fields[6] is X
# $fields[7] is Y
# $fields[8] is Z
# $fields[9] is the System Name
@fields = split(/:/,$current);
chop($fields[9]);
$starnum = $fields[1];
$Xvalue = $fields[6];
$Yvalue = $fields[7];
$Zvalue = $fields[8];
if ( $fields[0] < 1 ) {
$color = "diffuseColor 1 0 0";
} elsif ( $fields[0] < 4 ) {
$color = "diffuseColor 1 0 1";
} elsif ( $fields[0] < 9 ) {
$color = "diffuseColor 1 1 0";
} elsif ( $fields[0] < 16 ) {
$color = "diffuseColor 0 1 0";
} elsif ( $fields[0] < 25 ) {
$color = "diffuseColor 0 1 1";
} elsif ( $fields[0] < 36 ) {
$color = "diffuseColor 0 0 1";
} else {
$color = "diffuseColor 1 1 1";
}
print " Separator {\n";
print " # STAR: $fields[1], NAME: $fields[9]\n";
print " Material { $color }\n";
print " Translation { translation $fields[6] $fields[7] $fields[8] }\n";
print " Sphere { radius .25 }\n";
print " Separator {\n";
print " Translation { translation 0.25 0 0}\n";
print " Material { diffuseColor 1 1 1 }\n";
print " FontStyle { size 0.3 }\n";
print " AsciiText { string \"$fields[9]\" }\n";
print " }\n";
if ($fields[3] =~ 'G') {
print " Separator {\n";
print " Material { diffuseColor 0.3 0.3 0 }\n";
print " Translation { translation 0.15 -0.15 0}\n";
print " Sphere { radius .1 }\n";
print " }\n";
}
print " }\n";
#
# Build a list of Jump Routes based on nearby stars. List
# them into a new array "Jump" based on lower starnumber.
#
#
foreach $jumpcheck (@results) {
@fields = split(/:/,$jumpcheck);
if ($fields[1] == $starnum) { next } # SKIP if same star...
chop($fields[9]);
$this_star = $fields[1];
$deltaX = $fields[6]-$Xvalue;
$deltaY = $fields[7]-$Yvalue;
$deltaZ = $fields[8]-$Zvalue;
$sq_distance = $deltaX**2 + $deltaY**2 + $deltaZ**2;
if ($this_star < $starnum) {
$jumpname = "$this_star:$starnum";
} else {
$jumpname = "$starnum:$this_star";
}
if ($sq_distance < 1) {
$add = 1;
foreach $damnit (@jump1) {
if ($jumpname eq $damnit) { $add = 0 }
}
if ($add == 1) {
push (@jump1,$jumpname);
}
} elsif ($sq_distance < 4) {
$add = 1;
foreach $damnit (@jump2) {
if ($jumpname eq $damnit) { $add = 0 }
}
if ($add == 1) {
push (@jump2,$jumpname);
}
}
}
}
#
# =============================================================
# EFFECTIVE PROGRAM BREAK : PART 3 - CREATE JUMP ROUTES
# =============================================================
#
foreach (@jump1) {
($starA,$starB) = split(/:/);
@catchdata = grep(/^$starA/,@data);
# print "# $catchdata[0]\n";
@fields = split(/:/,$catchdata[0]);
$Xvalue = $fields[5];
$Yvalue = $fields[6];
$Zvalue = $fields[7];
@catchdata = grep(/^$starB/,@data);
# print "# $catchdata[0]\n";
@fields = split(/:/,$catchdata[0]);
$Avalue = $fields[5];
$Bvalue = $fields[6];
$Cvalue = $fields[7];
$deltaX = $Avalue-$Xvalue;
$deltaY = $Bvalue-$Yvalue;
$deltaZ = $Cvalue-$Zvalue;
if ($deltaX > $deltaY) {
if ($deltaZ > $deltaX) {
$base = 'Z';
} else {
$base = 'X';
}
} else {
if ($deltaZ > $deltaY) {
$base = 'Z';
} else {
$base = 'Y';
}
}
if ($base eq 'X') {
$pt1 = $Yvalue+0.05;
$pt2 = $Yvalue-0.05;
$pt3 = $Zvalue+0.05;
$pt4 = $Zvalue-0.05;
$pt5 = $Bvalue+0.05;
$pt6 = $Bvalue-0.05;
$pt7 = $Cvalue+0.05;
$pt8 = $Cvalue-0.05;
print " Separator {\n";
print " # Jump 1 - $starA:$starB\n";
print " Material { diffuseColor 0 1 0 }\n";
print " Coordinate3 {\n";
print " point [\n";
print " 0.0 $pt1 $pt3,\n";
print " 0.0 $pt1 $pt4,\n";
print " 0.0 $pt2 $pt3,\n";
print " 0.0 $pt2 $pt4,\n";
print " 0.0 $pt5 $pt7,\n";
print " 0.0 $pt5 $pt8,\n";
print " 0.0 $pt6 $pt7,\n";
print " 0.0 $pt6 $pt8\n";
print " ]\n";
print " }\n";
}
if ($base eq 'Y') {
$pt1 = $Xvalue+0.05;
$pt2 = $Xvalue-0.05;
$pt3 = $Zvalue+0.05;
$pt4 = $Zvalue-0.05;
$pt5 = $Avalue+0.05;
$pt6 = $Avalue-0.05;
$pt7 = $Cvalue+0.05;
$pt8 = $Cvalue-0.05;
print " Separator {\n";
print " # Jump 1 - $starA:$starB\n";
print " Material { diffuseColor 0 1 0 }\n";
print " Coordinate3 {\n";
print " point [\n";
print " $pt1 0.0 $pt3,\n";
print " $pt1 0.0 $pt4,\n";
print " $pt2 0.0 $pt3,\n";
print " $pt2 0.0 $pt4,\n";
print " $pt5 0.0 $pt7,\n";
print " $pt5 0.0 $pt8,\n";
print " $pt6 0.0 $pt7,\n";
print " $pt6 0.0 $pt8\n";
print " ]\n";
print " }\n";
}
if ($base eq 'Z') {
$pt1 = $Xvalue+0.05;
$pt2 = $Xvalue-0.05;
$pt3 = $Yvalue+0.05;
$pt4 = $Yvalue-0.05;
$pt5 = $Avalue+0.05;
$pt6 = $Avalue-0.05;
$pt7 = $Bvalue+0.05;
$pt8 = $Bvalue-0.05;
print " Separator {\n";
print " # Jump 1 - $starA:$starB\n";
print " Material { diffuseColor 0 1 0 }\n";
print " Coordinate3 {\n";
print " point [\n";
print " $pt1 $pt3 0.0,\n";
print " $pt1 $pt4 0.0,\n";
print " $pt2 $pt3 0.0,\n";
print " $pt2 $pt4 0.0,\n";
print " $pt5 $pt7 0.0,\n";
print " $pt5 $pt8 0.0,\n";
print " $pt6 $pt7 0.0,\n";
print " $pt6 $pt8 0.0\n";
print " ]\n";
print " }\n";
}
print " IndexedFaceSet {\n";
print " CoordIndex [\n";
print " 0, 1, 2, 3, -1,\n";
print " 4, 7, 6, 5, -1,\n";
print " 0, 4, 5, 1, -1,\n";
print " 2, 6, 7, 3, -1,\n";
print " 3, 7, 4, 0, -1,\n";
print " 1, 5, 6, 2\n";
print " ]\n";
print " }\n";
}
#
# =============================================================
# EFFECTIVE PROGRAM BREAK : PART 4 - FINAL VRML CODING
# =============================================================
#
#
# Print out final VRML stuff
#
print "}\n";
print "\n\n";
#
# Quit
#
exit;