From: Tea-man, teamsoho@XXXXXXXX.net

This is probably the last revision for the *.trk
definition. I've hit a roadblock. It appears that the 3do clipping engine
is related to the distance parameter. The distance
parameter is also in the 3do file of the trackname.3do.
It looks like it is defined in the type 12 flavor.
Also the type 8 flavor looks like a transform needed for the
clipping or defintion engine.

The Analysis is 99% complete for the *.trk file
It looks like this file can alter the track angle, hills,
define the arc of the curves, define grass, asphalt,
"the groove" the wall locations.

The problem however is matching this up with the *.3do file
and determining where is the vertex point for the arc which
defines the curved portion.


I've tried to move the location of the start/finish line by only
altering the *.trk filed but the outcome was limited. The s/f line
did move, however problems in the graphic clipping of the visuals
in the *.3do occured. Curved walls became straight polygons and
most of the track texture polygons did not show up.

Also, I've successfully moved back the walls or removed walls from the
*.trk file by altering the Wallsdat.txt file.


It seems that that the guys at BB&B have it all figured out by now
because I saw that they're planning to do a infield road course
at daytona. I guess they'll use the two banks of taladega and then
write out the new *.trk file and *.3do for the infield.


If you write up any useful program using this info, I'd appreciate
if you send me a copy.


I give thanks to Si, A.K.A. Frosty, Snowman, for giving me
a good head start to this *.trk definition analysis.
AND ALSO JON B^D
-------------------------------------------------------------
This is what I know about the *.trk files so far.
REVISED 4/11/98 defined Walldat9
Only value left that does not have a noticable effect is
[walldat 1]. Still dont know meaning/effect.
REVISED 3/27/98 Corrected meanings for Wallsdat Type 2,
defined Grassdat data
Revised definition of Elevdat Type 2.
REVISED 3/16/98 Corrected and revised definition
for Elevdat for type 1.
Changed references to #D lines to #E lines.
Revised definition of polygon/Elevation lines
REVISED 3/9/98 Original documentation.

I've only looked at Icr2 and some N1 *.trk files.
The program is still in Beta version until I can confirm the data
structure.
///////////////////////////////////////////////////////////////
************************************************************
0.0 Introducction- the *.trk file
**********************************************************
////////////////////////////////////////////////////////////////
The *.trk file ("hard" surfaces data ) is independent from
the *.3do file (visual graphics data).
The *.trk file data x,y,z has to correspond with the *.3do
file data so that the car and walls will be positioned in the
same place.
So far, it appears that there is a correspondence
whereby an identical correspondene of xyz data value for a
*.3do data point being the same for the xyz data
for the *.trk file.
If the *.trk file data is edited so that the data does not
"match" the *.3do file, the car will seem to go through walls;
float, or sink in the road surface, and hit invisible walls.
If "gaps" are opened between the "hard surfaces" during
editing of the *.trk file, the program may crash when the track
is loaded, or may crash if the AI or player car goes through a
"gap". Additionally, an edited file may cause the car to "jump"
to another position on or off the track (i.e. warping to another
place).
Also on an edited trk file the AI cars will follow an
"incorrect" line in relation to the visual midpoint of the track
as defined in the *.lp files because it is following the midpoint
as defined by the *.trk file. It seems the *.trk files also help
define the midpoint of the track for the *.lp to use. (for more
on *.lp files, read the info on *.lp editors in SimCyberworld,
The SimProject, The Pits, etc.)
It appears that the program assumes that the player car
will look towards the 0 degree heading at the
start/finish line, any rotation of the player car, the program
will calculate the new heading. This is used in the Graphics
clipping routine.
I think this is true because, I shifted the start finish location
of the Nazareth dog leg to a location between turn 1 and turn 2,
It caused to remove all textures and prevent showing the tire marks
defined in the 3do. Also the straight section between turns 3 and 1 disappeared
and can only be viewed when the players car is heading perpendiuclar to this section.

Additionally, it appears that the *.trk file must start at the s/f line and the
*.lp distance must start at the value zero at the begining of the *.trk file, see
the value [walldata 2].

******************************
0.1 The *.trk file structure Overview
*******************************
The *.trk file structure is in four sections:
Note the wordbtye is 4 bytes in length.


BEGINING OF FILE:
/HEX addr/ /SECTION/ /DECIMAL addr & LENGTH/
00h-43h "HEADERDATA" SECTION ==>00d byte to 67d byte
length: 17 4-byte words, or 68d bytes long.

44h-WWWh "SCTNDAT" SECTION,
(or SECTION POINTERS) ==>68d byte to WWWd byte
where WWWd = 68d + (value at 16d *4 bytes)
WWWh = 44h + (value at 10h *4 bytes)
or WWW = 44h + [#S * 4 bytes]
length:= value at offset 16d * 4 bytes
= #S * 4 bytes

***-XXXh "ELEVDAT" SECTION==>(WWW+1)d byte to XXXd byte
where XXXd = WWWd+
[value at offset 12d *
value at offset 16d *
8 words* 4 bytes]
XXXh = WWWh+ [value at offset 0Ch
* value at offset 10h
*8 words* 4 bytes]
or XXXh = XXXh+[#E * #S * 8 words * 4 words]
length: =(value at offset 12d)
*(value at offset 16d)
*8 words *4 bytes
= #E * #S * 8 words *4 bytes

***-YYYh "GRASSDAT" SECTION ==>(XXX+1)d byte to YYYd byte
where YYYd= XXXd + value at offset 20d
or YYYh= XXXh + value at offset 14h
length: value at offset 20d or 14h

***-EOF "WALLSDAT" SECTION ==>(YYY+1)d byte to EOF
length: value at offset 24d or 18h


There are pointers within the "Wallsection" which points to the
elevdat and grassdat data.
All data of each section begins immediately after the preceeding
section.
All data is in the Intel format little endian format.
All data / wordbyte is a signed integer which is 4 bytes in
length.

//////////////////////////////////////////////////////////////////////
***********************************************************************
1.0 THE STRUCTURE OF EACH SECTION OF THE *.TRK FILE
***********************************************************************
/////////////////////////////////////////////////////////////////////

****************************
1.1 The HEADER SECTION (headrdat.txt)
--The first section of *.trk--
*****************************
The header array has 17 words. Each word element is a 4-byte
signed integer in the Intel, little endian format of the
least to most significant byte.

/word#/ /hex or dec offset/ /Meaning/

000 00-03h 00d Spells out KART in ASCII
001 04-07h 04d Always = 00000001
002 08-0Bh 08d Track distance in 1/20millimeters
Used in *.lp files and in Wallsection.
003 0C-0Fh 12d The # of elevation lines #E along the
width of track section ("#E lines").
004 10h-13h 16d The # of track sections #S defining the
length of the track
005 14-17h 20d The length in bytes of the grass section
(grassdat.txt)
006 18-1Bh 24d The length in bytes of the walls section
(wallsdat.txt)
007 1c-43h 28d #E0 line location
008 32d #E1 line location
009 36d #E2 line location
010 40d #E3 ... etc
011 44d ...
012 48d ...
013 52d ...
014 56d ...
015 60d ...
016 64d #E9 line location
** RESERVED Space #L1-#L10 for 10 4-byte values, uses #E values,
others set to zero. minimum used 2, seen up to 5 used.
Used to set the location of the #E lines along the
length of all track sections relative to the zero midline point.

***********************
1.2 The "Track SECTIONS Pointer SECTION"(sctndat.txt)
An Offset Pointer data set for the fifth section
--The second section of *.trk---
**********************
The data are a list of long intergers.
The data is a list of 4-byte length pointers to the offsets of the data from the start of the "wallsdat data". See notes below about the wallsdat section data.
Number of elements in list corresponds to the header value #S at offset addr 16d(10h).
The track sections begin at the start/finish line and continues around the track in the direction in which the cars travel.

########
EXAMPLE
#######
Data sctndat.hex for nwenglnd.trk.
/Word#/ /Example/ /REMARKS/
000 00000000 1st data set (wallsubset#0) location at zero bytes offset
in the Wallsdat Section
001 00000070 Wallsubset#001 begins at 0x70h bytes offset.
...continues...
020 00000758 d Wallsubset#20 begins at 0x0758h offset
021 000007C8 d Wallsubset#21 begins at 0x07C8h offset

******************
1.3 The ELEVATION data SECTION (elevdat.txt or elevdat.hex)
Defining the polygon orientation and pitch/curvature
- The third section of *.trk -
******************
#####################
1.31 The format of the Elevation section
#####################
The elevation section is made of "#S sets" of data.
The number of sets of data is deined by the value of #S.
Each "#S set" represents each track section defining the hard track surface.

There are two types of "#S set". One type is for Straight sections, the other type is for Curved sections.

Each #S set defines the position, elevation, and orientation of a given number of polygons ACROSS THE WIDTH of the track FOR A GIVEN DISTANCE from the start/finish line.
The number of polygons across the width of the track corresponds to the value #E.
The polygons begin at the start/finish line.
Each "#S set" polygon is defined for a given DISTANCE from the start/finish line.
Each "#S set" polygon has a given LENGTH in the direction of the driveline.
The "#S set" polygon is defined and continutes down along the length of the track until it returns back to the start/finish line.

In each "#S set", the number of lines of data in each #S set is equal to the value of #E.
Each of "#E line" corresponds to a line along THE LENGTH OF THE TRACK at a given distance ACRROSS THE TRACK. Each "#E line" defines the shape and orientation of the edges a respective polygon, in other words, the "#E line" is analogous to an elevation line on a topographic map.
Each respective "#E line" location along the WITDTH of the track is defined by values #L1-#L10 as defined in the header.

#############################
FIGURE 1 #S set midline definition
##############################
TYPICAL #S set polygon, (example from Nazareth where #E=3)
(TOP VIEW, not to Scale)
==> Direction of car travel ==>
O========== grandstand wall M ======================O
: :
: :
:...........................M........................ #E2
: :
:***** "LP" position = 0 (zero) midline of track ***:
: :
:...........................M....................... #E1
: :
: :
: :
:...........................M........................ #E0
:========== pit separation wall ====================:
: :
: :
O===========pit wall =======M=======================O

LEGEND: m = midpoint line of #E line
'=' = Visual wall (data in track.3do file)
shown in figure for visual reference.
'...' = #E Elevation line
':' = Begin / end of polygon
'*' = Zero position of *.lp file, usually the midpoint of the track.
Length of the #S is defined by in the Walldat section.

#####################
1.32 The "#S set", The track section polygon data set
######################
The number of sets of #S set data in the Elevation section corresponds to the number of track sections #S as defined in the header. In each #S set, there are #E lines of data defining the edges of a polygon from the outermost to the innermost polygon at a given track section #S. The value of #E is defined in the header. Each #E line of data has eight (8) 4-byte words.

There are two different formats of data in each #E line. One format is for a straight section (type=1). Another format is for a Curve section (type=2).

Note: The header value #E also corresponds to the number of polygons defined on the across the width of the track. You may be able to see it visually by viewing the [trackname].3do file by using the program 3DOEDIT.EXE by Bassino.

The value "#E line" location along the WIDTH of the track section APPEARS TO be defined in the header at offset 1c-43h (hex) in the header. I have seen the number range from 2-4.


######################
1.33 The "#E line", and meaning of each "#E Elevation line"
Used to define the orientation of each polygon across the width
of the track at a given #S set
######################
I think that each "#E line" defines and corresponds to a location on the track width from the outside width of the track (by the grandstands, away from the pits) to the midpoint of the track, and to point at or along the pit lane white hashed lane marker. The location is defined in the header 1d-43(hex).

The 1st #E line defines a line next to the outer wall (in an oval track). The next #E line defines a line next to a midline of the track (but I dont think it defines the *.lp midline).
The next line generally corresponds to another line of the track, however road courses with grass and walls on both sides, this observation may not be true. More lines will define more "E lines" which are more "inward" toward the infield.

The last line will always correspond to a line nearest the infield.
The most "inward" line will define the merge lane and the pits itself.

AN EXAMPLE:
For Nazareth in ICR2 the header defined #S = 21 and #E = 3.
Now we read the data in Elevation section.
Begining of the elevation section:
8 4-byte words.. ( #E line=0 of #S=0 defines an elevation line at/near the outer wall.)
8 4-byte words.. ( #E line=1 of #S=0 defines an elevation line on the edge of the track.)
8 4-byte word.. ( #E line=2 of #S=0 defines an elevation line near the pit/sep)
Continuing along the datafile, we read the next elevation set#1.
... This repeats 21 times, one set for each track section along the length of the track.
Also in this example, there will be 63 "lines" of data (21 * 3).


##########################
1.34 The meaning of each value within each "#E line"
##########################
NOTE:
In my program, note that the first column is a reference number
when refering to the data references in the Wallsdat section and
is NOT actual data used in the *.trk file.
The Col.#1 - Col.#8 are the eight 4-byte word data of one #E elevation line.

In each "#E elevation line" of a "track section #S", there are 8 4-byte fields.
There are two types of track sections defined in the "wallsdat"
section of the *.trk file.
We will talk about this later in the fifth section, last section
of the *.trk file.

The types of track sections are:

Type 1 = Straight track section. Type 2 = Curved track section.
Each track type has a different data format.

#######################################
1.35 Elevation data format
for a Type 1 Track section = STRAIGHT
#######################################
Wordbyte MEANING
[Edat1] #Zend, height value at end from #Zmid
defines curvature from midpoint to end of #E line
Z value is additive from midpoint height #Zmid
Car not pitched, no effect on car physics
[Edat2] #Zmid, height value at midpoint from #Zref
defines curvature from begin to midpoint of #E line
Elevation value is NOT additive from the elevation values
of the immediately preceeding polygon #S set.
Car not pitched, no effect on car physics
[Edat3] #Zslope, delta elevation from #Zref at the end of polygon
Creates a slope where car is pitched
No physics effects on car.
[Edat4] #Zref, reference baseline elevation throughout polygon
[Edat5] #P end, curvature and pitch of car at end of polygon
Value is angle or elevation?
Value is additive from the midpoint value defined in #Pmid.
Car appears to pitch to this value as it reaches the end.
Unknown if it is a distance or an angle value?
Value effects car physics.
[Edat6] curvature and pitch of car at midpoint #Pmid
See notes to [Edat5]
Value not additive from previous values from different polygon
[Edat7] X coord of the start point of the #E line
whereby X is along the East/West as seen in Bassino's 3doedit.
** data not edited for changing the elevation banking
[Edat8] Y coord of point of start of #E line
whereby Y is along the North/South as seen in Bassino's 3doedit.
** data not edited for changing the elevation banking


#########################################
1.36 FIGURES SHOWING THE
EFFECTS on #E line for TYPE 1
########################################
Symbols Legend:
_
O--o Car with no pitch Xx Car path
Mm Mid point of #E line
I--I Base line Elevation, Edat4
o Car pitched at an angle A
/
/O

##########################################
FIGURE 2
ELEVATION CURVATURE EFFECT: Edat1, Edat2
##########################################
Where Edat4= e4
for Edat1=-2z, Edat2= z, other values = zero
NOT TO SCALE, length dependent upon Wdat???)
Height = e4+z ---------X
xmx
x m x
Curve Edat2=z _ x m x
O--o m x
x m x
x m x
x m x
x m x
x x m x
I---Baseline elevation--M-------x---height = e4 ---I
-m _x
-m O--o Curve Edat1=-2z
-m x
-m x
-m x
-m x
-m x
-m x
-m x
-m ---Height= -z X



########################################
FIGURE 3
ELEVATION CURVATURE EFFECT: Edat1, Edat2
#######################################
Where Edat4= e4
for Edat1=-2z, Edat2= z, other values = zero
(NOT TO SCALE, length dependent upon Wdat??)
m ---Height = 2z +e4X
m x
Curve Edat5=z m x
note:additive effect m _ x
m O--o x
m x
m x
m x
m x
m x
Mx ----------Height = z + e4
x
x m
Curve Edat6=z x m
x m
_ x m
O--o x m
x m
x m
x x m
I---Baseline elevation --M-----height = e4------I



####################
FIGURE 4 - ANGLE EFFECT of Edat3
(NOT TO SCALE)
###################

Height = z + e4 -----M X
m x
m x
Curve Edat3=z m x
(linear effect) m x
_ X
O--o x m
x m
x m
x m
I---Baseline elevation--M-----height = e4 -----I

###############################
FIGURE 5 CAR PITCH EFFECT: Edat5, Edat6
###############################
Where Edat4= e4
for Edat5 = -2a, Edat5 = a, other values = zero

FIGURE (NOT TO SCALE, length dependent upon Wdat???)

Postive value a
Pitches car up to angle a at midpoint
o o
_ / / _
O--o /O /O O--o O\
I-----------------M---------------- \ I
(level) o
(piched up) (pitched down)
Negative value -2a
Pitches car down to angle -a at
the end of the polygon.

NOTE Angle value is APPLIED to the car physics.
i.e. the weight car "feels" this angle.

#######################################
1.36 Elevation data format
for a Type 2 Track section = CURVE
#######################################

Elevation data format For a Type 2 Track section = CURVE
Wordbyte MEANING
[Edat1] #Zend Same as type 1, curvature height at end of polygon
[Edat2] #Zmid Same as type 1, curvature height at end of midpint
[Edat3] #Zslope Same as type 1, slope, height value at end of polygon
[Edat4] #Zref Same as type 1, baseline height
[Edat5] #Pend Same as type 1, pitch (height/angle)at end of polygon
[Edat6] #Pmid Same as type 1, pitch (height/angle) at end of midpoint
[Edat7] #R Radius distance #R to a point on the #E line, see Wallsdat section.
[Edat8] EOF, Always CCCCCCCC (hex) or -858993460 (dec)

WHEN EDITING
*** If the player car pit position and the track x,y,r value is not set
correctly, after track loading, it may immedately crash the
program because the player car is sits in a "pit stall" which
causes the program to crash.


*********************************
1.4 The GRASS/Road texture SECTION (grass.dat or grass.hex)
Defining the polygon textures
- The fourth section of the *.trk file -
****************************
I havent looked into this much, but I guess that this affects the
suface definition of the polygon as a grass or road surface.
A grass type would be bumpy, with lower friction coefficent?
A road type would be smooth, with higher friction coefficent?
1st two words appear to be position data which are mostly the
same except when there is a change of polygon width, i.e. the
track widens to form the deceleration lane into the pits, the
pits itself, the acceleration lane merge area, and the grassy
or run off areas. This data changes alot for road courses
because of the varible width of the grassy runoffs.
The last data appears to be at type.
################################
Typical format of the grass.dat
[gdat 1] [gdat 2] [Gdat 3]
#############################
[gdat1] location at begin of #S polygon
[gdat2] location at end of #S polygon
[gdat3] type 46 Asphalt texture, may be "the groove"? or regular friction?
skidding causes white smoke
54 Asphalt texture, "the groove"? or regular friction?
skidding causes white smoke
06 loose grass/sod/dirt, much less friction than hard grass
skidding causes brown smoke
22 hard grass, steerable/drivable grass
skidding causes brown smoke


####################
EXAMPLE
####################

Trkdec version Beta 3.A
Data grassdat.txt for nwenglnd.trk. Do Not Distribute--
Development copy.
ref# data1 data2 data3
000 -0178000 -0178000 046
001 -0178000 -0178000 046
002 0212000 0212000 046
003 -0178000 -0178000 046
004 0212000 0212000 054
005 0218000 0218000 046
006 0300000 0300000 046
007 0506000 0424000 006 <===CHANGE in Gdat #1,#2
008 -0178000 -0178000 046 when track width changed
009 0212000 0212000 054 i.e end of pit lane/merge area
010 0218000 0218000 046
011 0300000 0300000 046
012 0426000 0382771 006 <==CHANGE OF Gdat 1 & 2
013 -0178000 -0178000 046 for a changed track width
014 0212000 0212000 054 ... continutes
----------------------------------------



******************************
1.5 The WALLS SECTION
-the fifth section, last section of the *.trk file -
****************************
The Walls section defines the vertical wall positions, the track
length (used in the *.lp files and in elevation section?)
pointers to the grass and pointers to #S sets in the elevation
section, a car/ai orientation matrix... others...?
For easier reference, I will follow the format of my program for
the discussion Walls section
Each data is a long signed interger.

The walls defined by the infinite in the vertical plane, i.e.
there is no way to "jump" over the wall. The edges of the walls
begin and end at each #S section

########################
1.51 The format of the wallsdat section for each #S section
#######################
[Wdata 1][Wdata 2][Wdata 3]
[Wdata 4][Wdata 5][Wdata 6][Wdata 7][Wdata 8][Wdata 9]
[Wdata 10][Wdata 11][Wdata 12][Wdata 13]
[walldat1][walldat2][walldat3][walldat4][walldat5];Outerwall
[walldat1][walldat2][walldat3][walldat4][walldat5];PitSepWall,if any.
[walldat1][walldat2][walldat3][walldat4][walldat5];Pit/InfieldWall.
..... repeats for each #S set...
.... continues to the end of the *.trk file.

#######################
1.52 The meaning of the walls data section
#######################

Word Meaning (notes) (n.#)
----- -------
[Wdata 1] Track section type, either 1 or 2
[Wdata 2] Starting point Distance for this track section
[Wdata 3] Length of this track section (n.1)

[Wdata 4] for Type 1:
Inital Heading angle -2147483648 to 2147483647
Angle in degrees: (Longbyte value/(2147483647))*180
Global heading: 0 = 0 degree (X direction)
2147483647 = 180 degree heading
-2147483647 = -180 degree heading

for Type 2, Initial Heading angle?
usually the first type 2 heading is the same
as the heading of the last type 1 data before the curve

[Wdata 5] for Type 2, X location of vertex #R raduis vector
for Type 1, Cosine (heading angle) value
where G=214783647, PI=3.1415...,
data5 = 0.5 G * COS ( #Wdata4 * PI / G)

[Wdata 6] for Type 2, Y location of vertex for #R radus vector
for Type 1, Sine (heading angle)
data6 = 0.5 G * SIN ( data4 * PI / G)

[Wdata 7] for type 2, Half of Sector angle of the arc
defined in track section
observations:
Smaller values will cause gaps before/after the curve
Larger values define a larger arc
Sum of all these angles will equal 180 degrees.
for type 1, Sine (neg of heading angle)
data7 = 0.5 G * SIN ( -(data4 * PI) / G)

[Wdata 8]for type 2, EOF (n.2)
for type 1, Cosine (neg of heading angle)
data8 = 0.5 G * COS ( - (data4 * PI) / G)

[Wdata 9] for type 2, EOF (n.2)
******!!!!!!for type 1, ??? always near 90 degrees????????????????
****** appears when edat 0,1 or 3,5 is defined
********* affects the wall impact, provides a tangential acceleration
*** to simulate a side wall impact to spin the car
*** also affects the car at end of the polgon, if not correct
*** the car may "jump" to another place.
*may be trig function describing Z or warping of the polygon?????

[Wdata 10]ref# pointer to the start of data in the elevation data
[Wdata 11]number of data in the grass data for this Track section
[Wdata 12]ref# pointer to the start of data in the grass data
[Wdata 13]Number of #E line data sets that follows immediately after this data.
[walldat 1]Walldatset type,
???????? known: 0,4,6,.. others? dont know meaning????????
[walldat 2]wall begin point from the midline at the start of the #S polygon
[walldat 3]wall end point from the midline at the end of the #S polygon
[walldat 4] EOF (n.2)
[walldat 5] EOF (n.2)

(notes)
Actual Values may be off due to Cosine/Sine round off Errors of
the angles.
But these values are close enough to about +/- .01 degrees for 5
different tracks that I have tested (some road courses/some ovals)
(n.1) the total length of the track should equal the header array
at word 2 of the header, (at offset 8d of the *.trk file)
(n.2) eof is CCCCCCCC hex or -858993460 dec


*** END OF PRIMER TEXT***