net.ctdp.rfdynhud.gamedata
Class Track

java.lang.Object
  extended by net.ctdp.rfdynhud.gamedata.Track

public class Track
extends java.lang.Object

Model of a track with waypoints and utility methods

Author:
Marvin Froehlich (CTDP)

Nested Class Summary
protected static class Track.Waypoint
           
 
Constructor Summary
protected Track(Track.Waypoint[] waypointsTrack, Track.Waypoint[] waypointsPitlane, float sector1Length, float sector2Length, float trackLength, float minXPos, float maxXPos, float minYPos, float maxYPos, float minZPos, float maxZPos, float maxWidth)
           
 
Method Summary
 float getInterpolatedAngleToRoad(ScoringInfo scoringInfo)
          Gets the interpolated angle of the viewed vehicle to the road.
 void getInterpolatedPosition(boolean pitlane, float trackDistance, float scale, java.awt.geom.Point2D.Float point)
           
 boolean getInterpolatedVector(boolean pitlane, float trackDistance, TelemVect3 vector)
          Gets an interpolated vector along the track at the given waypoint.
 int getMaxTrackWidth(float scale)
          Gets the maximum track width.
 int getNumWaypoints(boolean pitlane)
          Gets the number of waypoints of the main track or the pitlane.
 float getScale(int targetWidth, int targetHeight)
          Calculates a scale factor for all values, if the track should be drawn on the given size.
 float getSector1Length()
          Gets the length of sector 1 in meters.
 float getSector2Length(boolean includingSector1)
          Gets the length of sector 2 in meters.
 float getSector3Length()
          Gets the length of sector 3 in meters.
 float getTrackLength()
          Gets the track length in meters.
 void getWaypointPosition(boolean pitlane, int waypointIndex, float scale, java.awt.Point point)
           
 void getWaypointPosition(boolean pitlane, int waypointIndex, TelemVect3 position)
          Gets the waypoint's position.
 byte getWaypointSector(boolean pitlane, int waypointIndex)
          Gets the sector, the requested waypoint is in.
 int getXExtend(float scale)
          Gets the extend along the x axis.
 int getYExtend(float scale)
          Gets the extend along the y axis.
 int getZExtend(float scale)
          Gets the extend along the z axis.
protected static net.ctdp.rfdynhud.gamedata.Track.ParseContainer parseAIW(java.io.File aiw)
           
static Track parseTrackFromAIW(java.io.File aiw)
          Parses an AIW file and returns a Track instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Track

protected Track(Track.Waypoint[] waypointsTrack,
                Track.Waypoint[] waypointsPitlane,
                float sector1Length,
                float sector2Length,
                float trackLength,
                float minXPos,
                float maxXPos,
                float minYPos,
                float maxYPos,
                float minZPos,
                float maxZPos,
                float maxWidth)
Method Detail

getSector1Length

public final float getSector1Length()
Gets the length of sector 1 in meters.

Returns:
the length of sector 1 in meters.

getSector2Length

public final float getSector2Length(boolean includingSector1)
Gets the length of sector 2 in meters.

Parameters:
includingSector1 -
Returns:
the length of sector 2 in meters.

getSector3Length

public final float getSector3Length()
Gets the length of sector 3 in meters.

Returns:
the length of sector 3 in meters.

getTrackLength

public final float getTrackLength()
Gets the track length in meters.

Returns:
the track length in meters.

getScale

public float getScale(int targetWidth,
                      int targetHeight)
Calculates a scale factor for all values, if the track should be drawn on the given size.

Parameters:
targetWidth - the target width to draw on
targetHeight - the target height to draw on
Returns:
a scale factor for all values.

getXExtend

public final int getXExtend(float scale)
Gets the extend along the x axis.

Parameters:
scale - the scale. See getScale(int, int)
Returns:
the extend along the x axis.

getYExtend

public final int getYExtend(float scale)
Gets the extend along the y axis.

Parameters:
scale - the scale. See getScale(int, int)
Returns:
the extend along the y axis.

getZExtend

public final int getZExtend(float scale)
Gets the extend along the z axis.

Parameters:
scale - the scale. See getScale(int, int)
Returns:
the extend along the z axis.

getMaxTrackWidth

public final int getMaxTrackWidth(float scale)
Gets the maximum track width.

Parameters:
scale - the scale. See getScale(int, int)
Returns:
the maximum track width.

getNumWaypoints

public final int getNumWaypoints(boolean pitlane)
Gets the number of waypoints of the main track or the pitlane.

Parameters:
pitlane - waypoints of main track or pitlane?
Returns:
the number of waypoints of the main track or the pitlane.

getWaypointSector

public final byte getWaypointSector(boolean pitlane,
                                    int waypointIndex)
Gets the sector, the requested waypoint is in.

Parameters:
pitlane - waypoint of main track or pitlane?
waypointIndex - the index of the waypoint
Returns:
the sector, the requested waypoint is in.

getWaypointPosition

public final void getWaypointPosition(boolean pitlane,
                                      int waypointIndex,
                                      TelemVect3 position)
Gets the waypoint's position.

Parameters:
pitlane - waypoint of main track or pitlane?
waypointIndex - the index of the waypoint
position - output buffer

getWaypointPosition

public final void getWaypointPosition(boolean pitlane,
                                      int waypointIndex,
                                      float scale,
                                      java.awt.Point point)
Parameters:
pitlane - waypoint of main track or pitlane?
waypointIndex - the index of the waypoint
scale - the scale. See getScale(int, int)
point - output buffer

getInterpolatedPosition

public final void getInterpolatedPosition(boolean pitlane,
                                          float trackDistance,
                                          float scale,
                                          java.awt.geom.Point2D.Float point)
Parameters:
pitlane - waypoint of main track or pitlane?
trackDistance - the distance along the track in meters
scale - the scale. See getScale(int, int)
point - output buffer

getInterpolatedVector

public final boolean getInterpolatedVector(boolean pitlane,
                                           float trackDistance,
                                           TelemVect3 vector)
Gets an interpolated vector along the track at the given waypoint.

Parameters:
pitlane - waypoint of main track or pitlane?
trackDistance - the distance along the track in meters
vector - output buffer
Returns:
success?

getInterpolatedAngleToRoad

public final float getInterpolatedAngleToRoad(ScoringInfo scoringInfo)
Gets the interpolated angle of the viewed vehicle to the road.

Parameters:
scoringInfo -
Returns:
the interpolated angle of the viewed vehicle to the road.

parseAIW

protected static net.ctdp.rfdynhud.gamedata.Track.ParseContainer parseAIW(java.io.File aiw)
                                                                   throws java.io.IOException
Throws:
java.io.IOException

parseTrackFromAIW

public static Track parseTrackFromAIW(java.io.File aiw)
                               throws java.io.IOException
Parses an AIW file and returns a Track instance.

Parameters:
aiw - the AIW file to parse
Returns:
a Track instance for the parsed AIW file.
Throws:
java.io.IOException - if there's something wrong with the file (missing, not readable, etc.).