Implemented an option to display just the portion of object's trajectory that it has travelled as of the current time. Currently, there is no keystroke bound to toggle this option on and off; it can only be enabled from scripts (.cel and .celx)
parent
3e2f5186b7
commit
8fd1d6ff26
|
@ -224,7 +224,7 @@ void EllipticalOrbit::sample(double start, double t, int nSamples,
|
|||
{
|
||||
double dE = 2 * PI / (double) nSamples;
|
||||
for (int i = 0; i < nSamples; i++)
|
||||
proc.sample(positionAtE(dE * i));
|
||||
proc.sample(t, positionAtE(dE * i));
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,7 +245,7 @@ void CachingOrbit::sample(double start, double t, int nSamples,
|
|||
{
|
||||
double dt = t / (double) nSamples;
|
||||
for (int i = 0; i < nSamples; i++)
|
||||
proc.sample(positionAtTime(start + dt * i));
|
||||
proc.sample(start + dt * i, positionAtTime(start + dt * i));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
class OrbitSampleProc
|
||||
{
|
||||
public:
|
||||
virtual void sample(const Point3d&) = 0;
|
||||
virtual void sample(double t, const Point3d&) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -827,7 +827,7 @@ class OrbitRenderer : public OrbitSampleProc
|
|||
public:
|
||||
OrbitRenderer() {};
|
||||
|
||||
void sample(const Point3d& p)
|
||||
void sample(double, const Point3d& p)
|
||||
{
|
||||
glVertex3f(astro::kilometersToAU((float) p.x * 100),
|
||||
astro::kilometersToAU((float) p.y * 100),
|
||||
|
@ -843,13 +843,19 @@ private:
|
|||
class OrbitSampler : public OrbitSampleProc
|
||||
{
|
||||
public:
|
||||
vector<Point3f>* samples;
|
||||
vector<Renderer::OrbitSample>* samples;
|
||||
|
||||
OrbitSampler(vector<Point3f>* _samples) : samples(_samples) {};
|
||||
void sample(const Point3d& p)
|
||||
OrbitSampler(vector<Renderer::OrbitSample>* _samples) : samples(_samples) {};
|
||||
void sample(double t, const Point3d& p)
|
||||
{
|
||||
Renderer::OrbitSample samp;
|
||||
samp.pos = Point3f((float) p.x, (float) p.y, (float) p.z);
|
||||
samp.t = t;
|
||||
samples->insert(samples->end(), samp);
|
||||
#if 0
|
||||
samples->insert(samples->end(),
|
||||
Point3f((float) p.x, (float) p.y, (float) p.z));
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -857,7 +863,7 @@ public:
|
|||
|
||||
void Renderer::renderOrbit(Body* body, double t)
|
||||
{
|
||||
vector<Point3f>* trajectory = NULL;
|
||||
vector<OrbitSample>* trajectory = NULL;
|
||||
for (vector<CachedOrbit*>::const_iterator iter = orbitCache.begin();
|
||||
iter != orbitCache.end(); iter++)
|
||||
{
|
||||
|
@ -933,13 +939,42 @@ void Renderer::renderOrbit(Body* body, double t)
|
|||
glBegin(GL_LINE_LOOP);
|
||||
else
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (vector<Point3f>::const_iterator p = trajectory->begin();
|
||||
p != trajectory->end(); p++)
|
||||
|
||||
if ((renderFlags & ShowPartialTrajectories) == 0 ||
|
||||
body->getOrbit()->isPeriodic())
|
||||
{
|
||||
glVertex3f(astro::kilometersToAU(p->x),
|
||||
astro::kilometersToAU(p->y),
|
||||
astro::kilometersToAU(p->z));
|
||||
// Show the complete trajectory
|
||||
for (vector<OrbitSample>::const_iterator p = trajectory->begin();
|
||||
p != trajectory->end(); p++)
|
||||
{
|
||||
glVertex3f(astro::kilometersToAU(p->pos.x),
|
||||
astro::kilometersToAU(p->pos.y),
|
||||
astro::kilometersToAU(p->pos.z));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show the portion of the trajectory travelled up to this point
|
||||
for (vector<OrbitSample>::const_iterator p = trajectory->begin();
|
||||
p != trajectory->end() && p->t < t; p++)
|
||||
{
|
||||
glVertex3f(astro::kilometersToAU(p->pos.x),
|
||||
astro::kilometersToAU(p->pos.y),
|
||||
astro::kilometersToAU(p->pos.z));
|
||||
}
|
||||
|
||||
// If we're midway through a non-periodic trajectory, we will need
|
||||
// to render a partial orbit segment.
|
||||
if (p != trajectory->end())
|
||||
{
|
||||
Point3d pos = body->getOrbit()->positionAtTime(t);
|
||||
glVertex3f((float) astro::kilometersToAU(pos.x),
|
||||
(float) astro::kilometersToAU(pos.y),
|
||||
(float) astro::kilometersToAU(pos.z));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ class Renderer
|
|||
ShowAutoMag = 0x4000,
|
||||
ShowCometTails = 0x8000,
|
||||
ShowMarkers = 0x10000,
|
||||
ShowPartialTrajectories = 0x20000,
|
||||
};
|
||||
|
||||
enum StarStyle
|
||||
|
@ -405,10 +406,18 @@ class Renderer
|
|||
|
||||
DetailOptions detailOptions;
|
||||
|
||||
public:
|
||||
struct OrbitSample
|
||||
{
|
||||
double t;
|
||||
Point3f pos;
|
||||
};
|
||||
|
||||
private:
|
||||
struct CachedOrbit
|
||||
{
|
||||
Body* body;
|
||||
std::vector<Point3f> trajectory;
|
||||
std::vector<OrbitSample> trajectory;
|
||||
bool keep;
|
||||
};
|
||||
std::vector<CachedOrbit*> orbitCache;
|
||||
|
|
|
@ -234,7 +234,7 @@ void SampledOrbit::sample(double start, double t, int nSamples,
|
|||
double end = start + t;
|
||||
double current = start;
|
||||
|
||||
proc.sample(positionAtTime(current));
|
||||
proc.sample(current, positionAtTime(current));
|
||||
|
||||
while (current < end)
|
||||
{
|
||||
|
@ -268,7 +268,7 @@ void SampledOrbit::sample(double start, double t, int nSamples,
|
|||
}
|
||||
else
|
||||
{
|
||||
proc.sample(goodpt);
|
||||
proc.sample(current + gooddt, goodpt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue