X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fthreedee%2FThreeDModel.java;fp=src%2Ftim%2Fprune%2Fthreedee%2FThreeDModel.java;h=abe166c837f88d5c65def6dd947eeedd9b4209f7;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/threedee/ThreeDModel.java b/src/tim/prune/threedee/ThreeDModel.java new file mode 100644 index 0000000..abe166c --- /dev/null +++ b/src/tim/prune/threedee/ThreeDModel.java @@ -0,0 +1,203 @@ +package tim.prune.threedee; + +import tim.prune.data.DataPoint; +import tim.prune.data.PointScaler; +import tim.prune.data.Track; + +/** + * Class to hold a 3d model of the track data, + * including all points and scaling operations. + * Used by java3d and also Pov export functions + */ +public class ThreeDModel +{ + private Track _track = null; + private Track _terrainTrack = null; + private PointScaler _scaler = null; + private double _scaleFactor = 1.0; + private double _altFactor = 1.0; + private double _externalScaleFactor = 1.0; + // MAYBE: How to store rods (lifts) in data? + private byte[] _pointTypes = null; + private byte[] _pointHeights = null; + + // Constants for point types + public static final byte POINT_TYPE_WAYPOINT = 1; + public static final byte POINT_TYPE_NORMAL_POINT = 2; + public static final byte POINT_TYPE_SEGMENT_START = 3; + + + /** + * Constructor + * @param inTrack Track object + */ + public ThreeDModel(Track inTrack) + { + _track = inTrack; + } + + + /** + * @param inTrack terrain track to set + */ + public void setTerrain(Track inTrack) + { + _terrainTrack = inTrack; + } + + /** + * @return the number of points in the model + */ + public int getNumPoints() + { + if (_track == null) return 0; + return _track.getNumPoints(); + } + + /** + * @param inFactor altitude exaggeration factor (default 1.0) + */ + public void setAltitudeFactor(double inFactor) + { + _altFactor = inFactor; + } + + /** + * @param inSize size of model + */ + public void setModelSize(double inSize) + { + _externalScaleFactor = inSize; + } + + /** + * Scale all points and calculate factors + */ + public void scale() + { + // Use PointScaler to sort out x and y values + _scaler = new PointScaler(_track); + _scaler.addTerrain(_terrainTrack); + _scaler.scale(); // Add 10% border + + // cap altitude scale factor if it's too big + double maxAlt = _scaler.getAltitudeRange() * _altFactor; + if (maxAlt > 0.5) + { + // capped + // System.out.println("Capped alt factor from " + _altFactor + " to " + (_altFactor * 0.5 / maxAlt)); + _altFactor = _altFactor * 0.5 / maxAlt; + } + + // calculate point types and height codes + calculatePointTypes(); + } + + + /** + * Calculate the point types and height codes + */ + private void calculatePointTypes() + { + int numPoints = getNumPoints(); + _pointTypes = new byte[numPoints]; + _pointHeights = new byte[numPoints]; + // Loop over points in track + for (int i=0; i