This file is indexed.

/usr/games/xracer-mktube is in xracer-tools 0.96.9.1-7.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/perl -w
# XRACER (C) 1999-2000 Richard W.M. Jones <rich@annexia.org> and other AUTHORS
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# $Id: xracer-mktube.pl,v 1.6 2000/01/02 14:13:32 rich Exp $

# You have made the basic tubular outline of the track in Blender,
# converted it to a mesh and saved it as a VideoScape file. This
# script takes that file and converts it to a list of roughly
# cylindrical segments. The result is saved as a suitable C
# file for the track, and also as an intermediate .tube file which
# is used by the other track processing scripts.

use strict;

use Getopt::Long;
use Data::Dumper;

use lib '../../XRacer/blib/lib'; # So you can run this without installing it.
use XRacer::Math;

# Read command line arguments.
my $nr_steps;
my $coutputfilename;
my $tubeoutputfilename;
my $verbose;
my $help;

GetOptions ("steps=i" => \$nr_steps,
	    "outputc=s" => \$coutputfilename,
	    "outputtube=s" => \$tubeoutputfilename,
	    "verbose" => \$verbose,
	    "help|?" => \$help);

if ($help)
  {
    print STDERR "$0 --steps STEPS [--outputc OUTPUTFILE] [--outputtube TUBEOUTPUTFILE] [--verbose] [INPUTFILE]\n";
    print STDERR "where: STEPS is the number of vertices in each segment\n";
    print STDERR "       OUTPUTFILE is the C file to write\n";
    print STDERR "       TUBEOUTPUTFILE is the .tube file to write\n";
    print STDERR "       INPUTFILE is the input VideoScape file\n";
    exit 1;
  }

die "--steps argument is required" if !$nr_steps;

# Read input lines.
my $state = "expect 3DG1";
my $vcount;
my $nr_segments;
my @vertices = ();

while (<>)
  {
    s/[\n\r]+$//g;		# Removes trailing CR, LF.

    if ($state eq "expect 3DG1")
      {
	die "expecting first line to be 3DG1" if $_ ne "3DG1";
	$state = "expect vcount";
      }
    elsif ($state eq "expect vcount")
      {
	die "expecting vertex count" if $_ !~ m/^[1-9][0-9]*$/;

	$vcount = $_;

	# Check that steps divides number of vertices.
	die "number of steps must divide number of vertices ($vcount)"
	  if ($vcount / $nr_steps != int ($vcount / $nr_steps));

	$nr_segments = $vcount / $nr_steps;

	$state = "reading vertices";
      }
    elsif ($state eq "reading vertices")
      {
	my @vs = split /[ \t]+/, $_;
	push @vertices, \@vs;
	$vcount--;
      }

    last if $state eq "reading vertices" && $vcount == 0;
  }

# Print a summary of the file.
print "number of vertices: ", scalar (@vertices), "\n" if $verbose;
print "number of segments: $nr_segments\n" if $verbose;

# Group the vertices by segment.
my @segments = ();

for (my $i = 0; $i < @vertices; $i += $nr_steps)
  {
    my @vs = ();

    for (my $j = $i; $j < $i + $nr_steps; $j++)
      {
	push @vs, $vertices[$j];
      }

    my %th = ('vertices' => \@vs,
	      'n' => $i / $nr_steps);

    push @segments, \%th;
  }

# Now process the vertices in each segment to fill in the rest
# of the information for each segment in the @segments array.
my $segment;
foreach $segment (@segments)
  {
    my $n = $segment->{n};
    my @vs = @{$segment->{vertices}};

    print "segment: $n, number of vertices: ", scalar (@vs), "\n" if $verbose;

    print "vertices: ", cinitializer (@vs), "\n" if $verbose;

    # Compute the midpoint of the enter plane.
    my $midpoint = XRacer::Math::midpoint (@vs);

    print "midpoint: $midpoint->[0], $midpoint->[1], $midpoint->[2]\n"
      if $verbose;

    # Compute the distance from each vertex to the midpoint. It
    # should be rougly the same. If not, then probably we are
    # not grouping the vertices correctly into segments (ie.
    # $nr_steps is wrong). Anyway, we should get the radius of
    # the tube this way.
    my $radius = XRacer::Math::distance ($vs[0], $midpoint);

    foreach (@vs)
      {
	my $d = XRacer::Math::distance ($_, $midpoint);

	if (abs ($radius - $d) > 0.01)
	  {
	    print STDERR "segment: $n: points do not form a circle\n";
	    print STDERR "  This probably means that the --steps argument is wrong.\n";
	    print STDERR "  Radius = $radius. Distance = $d.\n";
	    print STDERR "  Point = ",
	    $_->[0], ", ", $_->[1], ", ", $_->[2], "\n";
	    exit 1;
	  }
      }

    print "radius: $radius\n" if $verbose;

    # Calculate the enter plane. Assuming the points are coplanar,
    # we can just take ANY three points and compute the plane. However,
    # for more accuracy, take the midpoint and two points on the
    # edge which form a right angle.
    my $point1 = $vs[0];
    my $point2 = $vs[@vs/4];

    my $enterplane = XRacer::Math::plane_coefficients ($point1, $midpoint, $point2);

    print "enter plane coefficients: ",
    "$enterplane->[0], $enterplane->[1], $enterplane->[2], $enterplane->[3]\n"
      if $verbose;

    # Save all this information in the segment hash.
    $segment->{midpoint} = $midpoint;
    $segment->{radius} = $radius;
    $segment->{enterplane} = $enterplane;

    # Delete the vertices - don't need these any more, and we don't
    # particularly want them dumped out into the tube file.
    delete $segment->{vertices};
  }

# Write out the tube file.
if ($tubeoutputfilename)
  {
    open TUBE, ">$tubeoutputfilename"
      or die "$tubeoutputfilename: $!";

    print TUBE "# This is a TUBE file for XRacer. It is automatically generated.\n";

    print TUBE Dumper (\@segments);

    print TUBE "# End of file.\n";

    close TUBE;
  }

# Write the C file.
if ($coutputfilename)
  {
    open C, ">$coutputfilename"
      or die "$coutputfilename: $!";

    print C "/* This file describes the outline tube around the track.\n * It is automatically generated.\n */\n\n#include \"common.h\"\n\n";

    print C "int nr_segments = ", $nr_segments, ";\n";

    print C "GLfloat midpoints[][3] = ",
    cinitializer (map { $_->{midpoint} } @segments), ";\n";
    print C "GLfloat radii[] = ",
    cinitializer (map { $_->{radius} } @segments), ";\n";
    print C "GLfloat enterplanes[][4] = ",
    cinitializer (map { $_->{enterplane} } @segments), ";\n";

    print C "/* End of file. */\n";

    close C;

  }

exit 0;

#----------------------------------------------------------------------

# This small helper function takes a list of either numbers of
# array refs, and returns an equivalent C string for initializing
# a C multi-dimensional array or structure.
sub cinitializer
  {
    return "{ " . join (", ",
			map ({ ref ($_) eq 'ARRAY' ? cinitializer (@$_) : $_ }
			     @_)) . " }";
  }