diff ..\celestia-cvs\celestia\src\celengine/parseobject.cpp src\celengine/parseobject.cpp 3c3 < // Copyright (C) 2004 Chris Laurel --- > // Copyright (C) 2004-2007 Chris Laurel 49a50,83 > /*! > * Create a new Keplerian orbit from an ssc property table: > * > * EllipticalOrbit > * { > * # One of the following is required to specify orbit size: > * SemiMajorAxis > * PericenterDistance > * > * # Required > * Period > * > * Eccentricity (default: 0.0) > * Inclination (default: 0.0) > * AscendingNode (default: 0.0) > * > * # One or none of the following: > * ArgOfPericenter (default: 0.0) > * LongOfPericenter (default: 0.0) > * > * Epoch (default J2000.0) > * > * # One or none of the following: > * MeanAnomaly (default: 0.0) > * MeanLongitude (default: 0.0) > * } > * > * If usePlanetUnits is true: > * Period is in Julian years > * SemiMajorAxis or PericenterDistance is in AU > * Otherwise: > * Period is in Julian days > * SemiMajorAxis or PericenterDistance is in kilometers. > */ 126a161,216 > /*! > * Create a new sampled orbit from an ssc property table: > * > * SampledTrajectory > * { > * Source > * Interpolation "Cubic" | "Linear" > * DoublePrecision > * } > * > * Source is the only required field. Interpolation defaults to cubic, and > * DoublePrecision defaults to true. > */ > static Orbit* > CreateSampledTrajectory(Hash* trajData, const string& path) > { > string sourceName; > if (!trajData->getString("Source", sourceName)) > { > clog << "SampledTrajectory is missing a source.\n"; > return NULL; > } > > // Read interpolation type; string value must be either "Linear" or "Cubic" > // Default interpolation type is cubic. > string interpolationString; > TrajectoryInterpolation interpolation = TrajectoryInterpolationCubic; > if (trajData->getString("Interpolation", interpolationString)) > { > if (!compareIgnoringCase(interpolationString, "linear")) > interpolation = TrajectoryInterpolationLinear; > else if (!compareIgnoringCase(interpolationString, "cubic")) > interpolation = TrajectoryInterpolationCubic; > else > clog << "Unknown interpolation type " << interpolationString << endl; // non-fatal error > } > > // Double precision is true by default > bool useDoublePrecision = true; > trajData->getBoolean("DoublePrecision", useDoublePrecision); > TrajectoryPrecision precision = useDoublePrecision ? TrajectoryPrecisionDouble : TrajectoryPrecisionSingle; > > DPRINTF(1, "Attempting to load sampled trajectory from source '%s'\n", sourceName.c_str()); > ResourceHandle orbitHandle = GetTrajectoryManager()->getHandle(TrajectoryInfo(sourceName, path, interpolation, precision)); > Orbit* orbit = GetTrajectoryManager()->find(orbitHandle); > if (orbit == NULL) > { > clog << "Could not load sampled trajectory from '" << sourceName << "'\n"; > } > > clog << "Interpolation: " << interpolation << ", precision: " << precision << endl; > clog << "Orbit: " << (void*) orbit << "\n"; > return orbit; > } > > 285a376 > // Trajectory calculated by Lua script 301a393,410 > // New 1.5.0 style for sampled trajectories. Permits specification of > // precision and interpolation type. > Value* sampledTrajDataValue = planetData->getValue("SampledTrajectory"); > if (sampledTrajDataValue != NULL) > { > if (sampledTrajDataValue->getType() != Value::HashType) > { > clog << "Object has incorrect syntax for SampledTrajectory.\n"; > return NULL; > } > else > { > return CreateSampledTrajectory(sampledTrajDataValue->getHash(), path); > } > } > > // Old style for sampled trajectories. Assumes cubic interpolation and > // single precision. 308c417,420 < GetTrajectoryManager()->getHandle(TrajectoryInfo(sampOrbitFile, path)); --- > GetTrajectoryManager()->getHandle(TrajectoryInfo(sampOrbitFile, > path, > TrajectoryInterpolationCubic, > TrajectoryPrecisionSingle)); 314,315c426 < clog << "Could not load sampled orbit file '" << < sampOrbitFile << "'\n"; --- > clog << "Could not load sampled orbit file '" << sampOrbitFile << "'\n"; diff ..\celestia-cvs\celestia\src\celengine/samporbit.cpp src\celengine/samporbit.cpp 20a21 > #include 31c32 < struct Sample --- > template struct Sample 34c35 < float x, y, z; --- > T x, y, z; 37c38 < bool operator<(const Sample& a, const Sample& b) --- > template bool operator<(const Sample& a, const Sample& b) 42c43 < class SampledOrbit : public CachingOrbit --- > template class SampledOrbit : public CachingOrbit 45c46 < SampledOrbit(); --- > SampledOrbit(TrajectoryInterpolation); 65c66 < vector samples; --- > vector > samples; 70,76c71 < enum InterpolationType < { < Linear = 0, < Cubic = 1, < }; < < InterpolationType interpolation; --- > TrajectoryInterpolation interpolation; 80c75 < SampledOrbit::SampledOrbit() : --- > template SampledOrbit::SampledOrbit(TrajectoryInterpolation _interpolation) : 84c79 < interpolation(Cubic) --- > interpolation(_interpolation) 89c84 < SampledOrbit::~SampledOrbit() --- > template SampledOrbit::~SampledOrbit() 94c89 < void SampledOrbit::addSample(double t, double x, double y, double z) --- > template void SampledOrbit::addSample(double t, double x, double y, double z) 100,103c95,98 < Sample samp; < samp.x = (float) x; < samp.y = (float) y; < samp.z = (float) z; --- > Sample samp; > samp.x = (T) x; > samp.y = (T) y; > samp.z = (T) z; 108c103 < double SampledOrbit::getPeriod() const --- > template double SampledOrbit::getPeriod() const 114c109 < bool SampledOrbit::isPeriodic() const --- > template bool SampledOrbit::isPeriodic() const 120c115 < void SampledOrbit::getValidRange(double& begin, double& end) const --- > template void SampledOrbit::getValidRange(double& begin, double& end) const 127c122 < double SampledOrbit::getBoundingRadius() const --- > template double SampledOrbit::getBoundingRadius() const 156c151 < Point3d SampledOrbit::computePosition(double jd) const --- > template Point3d SampledOrbit::computePosition(double jd) const 169c164 < Sample samp; --- > Sample samp; 175,177c170,172 < vector::const_iterator iter = lower_bound(samples.begin(), < samples.end(), < samp); --- > vector >::const_iterator iter = lower_bound(samples.begin(), > samples.end(), > samp); 192c187 < if (interpolation == Linear) --- > if (interpolation == TrajectoryInterpolationLinear) 194,195c189,190 < Sample s0 = samples[n - 1]; < Sample s1 = samples[n]; --- > Sample s0 = samples[n - 1]; > Sample s1 = samples[n]; 202c197 < else if (interpolation == Cubic) --- > else if (interpolation == TrajectoryInterpolationCubic) 204c199 < Sample s0, s1, s2, s3; --- > Sample s0, s1, s2, s3; 250c245 < Vec3d SampledOrbit::computeVelocity(double jd) const --- > template Vec3d SampledOrbit::computeVelocity(double jd) const 279c274 < if (interpolation == Linear) --- > if (interpolation == TrajectoryInterpolationLinear) 287c282 < else if (interpolation == Cubic) --- > else if (interpolation == TrajectoryInterpolationCubic) 333,334c328,329 < void SampledOrbit::sample(double start, double t, int, < OrbitSampleProc& proc) const --- > template void SampledOrbit::sample(double start, double t, int, > OrbitSampleProc& proc) const 384c379 < Orbit* LoadSampledOrbit(const string& filename) --- > template SampledOrbit* LoadSampledOrbit(const string& filename, TrajectoryInterpolation interpolation, T) 390c385,388 < SampledOrbit* orbit = new SampledOrbit(); --- > SampledOrbit* orbit = NULL; > > orbit = new SampledOrbit(interpolation); > 421a420,431 > > > Orbit* LoadSampledTrajectorySinglePrec(const string& filename, TrajectoryInterpolation interpolation) > { > return LoadSampledOrbit(filename, interpolation, 0.0f); > } > > > Orbit* LoadSampledTrajectoryDoublePrec(const string& filename, TrajectoryInterpolation interpolation) > { > return LoadSampledOrbit(filename, interpolation, 0.0); > } diff ..\celestia-cvs\celestia\src\celengine/samporbit.h src\celengine/samporbit.h 3c3 < // Copyright (C) 2002, Chris Laurel --- > // Copyright (C) 2002-2007, Chris Laurel 16c16,29 < extern Orbit* LoadSampledOrbit(const std::string& name); --- > enum TrajectoryInterpolation > { > TrajectoryInterpolationLinear, > TrajectoryInterpolationCubic, > }; > > enum TrajectoryPrecision > { > TrajectoryPrecisionSingle, > TrajectoryPrecisionDouble > }; > > extern Orbit* LoadSampledTrajectoryDoublePrec(const std::string& name, TrajectoryInterpolation interpolation); > extern Orbit* LoadSampledTrajectorySinglePrec(const std::string& name, TrajectoryInterpolation interpolation); diff ..\celestia-cvs\celestia\src\celengine/trajmanager.cpp src\celengine/trajmanager.cpp 3c3 < // Copyright (C) 2001 Chris Laurel --- > // Copyright (C) 2001-2007 Chris Laurel 11a12 > #include 22a24,25 > static const char UniqueSuffixChar = '!'; > 33a37,42 > // Ensure that trajectories with different interpolation or precision get resolved to different objects by > // adding a 'uniquifying' suffix to the filename that encodes the properties other than filename which can > // distinguish two trajectories. This suffix is stripped before the file is actually loaded. > char uniquifyingSuffix[32]; > sprintf(uniquifyingSuffix, "%c%u%u", UniqueSuffixChar, (unsigned int) interpolation, (unsigned int) precision); > 37d45 < // cout << "Resolve: testing [" << filename << "]\n"; 40c48 < return filename; --- > return filename + uniquifyingSuffix; 43c51 < return baseDir + "/" + source; --- > return baseDir + "/" + source + uniquifyingSuffix; 48,49c56,74 < DPRINTF(1, "Loading trajectory: %s\n", filename.c_str()); < // cout << "Loading trajectory: " << filename << '\n'; --- > // strip off the uniquifying suffix > string::size_type uniquifyingSuffixStart = filename.rfind(UniqueSuffixChar); > string strippedFilename(filename, 0, uniquifyingSuffixStart); > > DPRINTF(1, "Loading trajectory: %s\n", strippedFilename.c_str()); > > Orbit* sampTrajectory = NULL; > switch (precision) > { > case TrajectoryPrecisionSingle: > sampTrajectory = LoadSampledTrajectoryDoublePrec(strippedFilename, interpolation); > break; > case TrajectoryPrecisionDouble: > sampTrajectory = LoadSampledTrajectorySinglePrec(strippedFilename, interpolation); > break; > default: > assert(0); > break; > } 51c76 < return LoadSampledOrbit(filename); --- > return sampTrajectory; diff ..\celestia-cvs\celestia\src\celengine/trajmanager.h src\celengine/trajmanager.h 3c3 < // Copyright (C) 2001 Chris Laurel --- > // Copyright (C) 2001-2007 Chris Laurel 16a17 > #include 23a25,26 > TrajectoryInterpolation interpolation; > TrajectoryPrecision precision; 26,27c29,32 < const std::string _path = "") : < source(_source), path(_path) {}; --- > const std::string _path = "", > TrajectoryInterpolation _interpolation = TrajectoryInterpolationCubic, > TrajectoryPrecision _precision = TrajectoryPrecisionSingle) : > source(_source), path(_path), interpolation(_interpolation), precision(_precision) {}; 32a38,41 > // Sort trajectory info records. The same trajectory can be loaded multiple times with > // different attributes for precision and interpolation. How the ordering is defined isn't > // as important making this operator distinguish between trajectories with either different > // sources or different attributes. 35,36c44,57 < if (ti0.source == ti1.source) < return ti0.path < ti1.path; --- > if (ti0.interpolation == ti1.interpolation) > { > if (ti0.precision == ti1.precision) > { > if (ti0.source == ti1.source) > return ti0.path < ti1.path; > else > return ti0.source < ti1.source; > } > else > { > return ti0.precision < ti1.precision; > } > } 38c59,61 < return ti0.source < ti1.source; --- > { > return ti0.interpolation < ti1.interpolation; > }