#!/usr/bin/env python
## trk-convert - Turn a RARS .trk file into the C++ code for a Vamos track.
## This file is part of Vamos Automotive Simulator.
## Copyright (C) 2001 Sam Varner
##
## 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
# Many thanks to those who produced the tracks for RARS, and to the
# developers who placed this project under the GPL. I owe you.
# Usage: trk-convert trackfile.trk [ trackfile.cc ]
# If you don't specify at output file, the code is send to standard
# output. After converting, save the file as `track.cc' and
# recomplie. You need the file `trk-convert-header' in the current
# directory to produce the C++ file.
# notes on cleanup...
import sys
import re
from math import pi
header = """
textures/sky_sides.png
textures/sky_top.png
textures/sky_bottom.png
1.0
0.1
1.0
0.0
0.01
100.0
textures/track2.png
200.0
0.7
0.1
5.0
20.0
0.03
2.0
textures/grass.png
10.0
12.0
0.8
0.0
40.0
200.0
0.05
2.0
textures/gravel3.png
10.0
10.0
1.0
0.8
1.0
5.0
0.0
1.0
textures/blue-tires.png
0.33
3.0
1.0
0.1
1.0
0.0
0.0
1.0
textures/rail.png
0.5
10.0
1.0
0.1
1.0
0.0
0.0
1.0
textures/wall.png
1.0
10.0
1.0
0.1
1.0
0.0
0.06
2.0
textures/blue-kerb.png
2.0
4.0
[ wall grass kerb track kerb grass rail ]
[ wall track kerb track kerb grass rail ]
[ wall grass kerb track kerb gravel tires ]
[ wall track kerb track kerb gravel tires ]
[ tires gravel kerb track kerb grass rail ]
"""
# Give a usage message if not enough arguments were passed or if the first
# argument can't be opened as a file.
help = 0
angle_type = ''
progname = sys.argv [0].split ('/')[-1]
trackfile = ''
close = 0
argv = sys.argv [1:]
argc = len (sys.argv)
if argc < 2 or argc > 4: help = 1
else:
if argv [0] == '-r' or argv [0] == '--radians':
angle_type = 'radians'
argv = argv [1:]
elif argv [0] == '-d' or argv [0] == '--degrees':
angle_type = 'degrees'
argv = argv [1:]
elif argv [0] == '-l' or argv [0] == '--length':
angle_type = 'length'
argv = argv [1:]
elif argv [0] == '-c' or argv [0] == '--close':
close = 1
argv = argv [1:]
if argv:
try:
track = open (argv [0])
trackfile = argv [0].split ('/')[-1]
except IOError: help = 1
if help:
print 'Usage: trk-convert [ [ -r | --radians ] | [ -d | --degrees ]'
print '| [ -l | --length ] ] trackfile.trk [ trackfile.cc ]'
sys.exit (1)
else:
argv = argv [1:]
# If an output file argument is given, redirect the prints to the file.
if argv:
sys.stdout = open (argv [0], 'w')
# Convert feet to meters.
def meters (feet):
return feet * 0.3048 # exact
# This regex matches a straight or curve definition.
segment_regex = re.compile ('[ \t]*([-0-9\.]+)[ \t]+([0-9\.]+).*')
# Thas regex matches a line with only whitespace.
blank_regex = re.compile ('[ \t]*\n')
print ''
print '' % \
(trackfile, progname)
print ''