TrailGroup.cpp   TrailGroup.cpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "TrailGroup.hpp" #include "TrailGroup.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelPainter.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "renderer/StelRenderer.hpp"
TrailGroup::TrailGroup(float te) TrailGroup::TrailGroup(float te) : timeExtent(te), opacity(1.f)
: timeExtent(te)
, opacity(1.0f)
, lastTimeInHistory(0.0)
{ {
j2000ToTrailNative=Mat4d::identity(); j2000ToTrailNative=Mat4d::identity();
j2000ToTrailNativeInverted=Mat4d::identity(); j2000ToTrailNativeInverted=Mat4d::identity();
} }
TrailGroup::~TrailGroup() static QVector<Vec3d> vertexArray;
static QVector<Vec4f> colorArray;
void TrailGroup::draw(StelCore* core, StelPainter* sPainter)
{ {
for(int t = 0; t < allTrails.size(); t++) glEnable(GL_BLEND);
{ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
delete allTrails[t].vertexBuffer;
}
}
void TrailGroup::draw(StelCore* core, StelRenderer* renderer)
{
renderer->setBlendMode(BlendMode_Alpha);
float currentTime = core->getJDay(); float currentTime = core->getJDay();
StelProjector::ModelViewTranformP transfo = core->getJ2000ModelViewT ransform(); StelProjector::ModelViewTranformP transfo = core->getJ2000ModelViewT ransform();
transfo->combine(j2000ToTrailNativeInverted); transfo->combine(j2000ToTrailNativeInverted);
StelProjectorP projector = core->getProjection(transfo); sPainter->setProjector(core->getProjection(transfo));
foreach (const Trail& trail, allTrails)
// We skip some positions to avoid drawing too many vertices when th
e history is long.
int totalPositions = 0;
foreach(const Trail& trail, allTrails)
{ {
totalPositions += trail.posHistory.size();
}
const int desiredMaxTotalTrailVertices = 8192;
const int skip = std::max(1, totalPositions / desiredMaxTotalTrailVe
rtices);
for(int t = 0; t < allTrails.size(); t++)
{
Trail& trail(allTrails[t]);
Planet* hpl = dynamic_cast<Planet*>(trail.stelObject.data()) ; Planet* hpl = dynamic_cast<Planet*>(trail.stelObject.data()) ;
if (hpl != NULL) if (hpl!=NULL)
{ {
// Avoid drawing the trails if the object is the hom e planet // Avoid drawing the trails if the object is the hom e planet
QString homePlanetName = hpl == NULL ? "" : hpl->get QString homePlanetName = hpl->getEnglishName();
EnglishName(); if (homePlanetName==StelApp::getInstance().getCore()
if (homePlanetName == StelApp::getInstance().getCore ->getCurrentLocation().planetName)
()->getCurrentLocation().planetName)
{
continue; continue;
}
}
const QVector<Vec3f>& posHistory = trail.posHistory;
// Construct the vertex buffer if not yet constructed, other
wise clear it.
if(NULL == trail.vertexBuffer)
{
trail.vertexBuffer =
renderer->createVertexBuffer<ColoredVertex>(
PrimitiveType_LineStrip);
} }
else const QList<Vec3d>& posHistory = trail.posHistory;
{ vertexArray.resize(posHistory.size());
trail.vertexBuffer->unlock(); colorArray.resize(posHistory.size());
trail.vertexBuffer->clear(); for (int i=0;i<posHistory.size();++i)
} {
float colorRatio = 1.f-(currentTime-times.at(i))/tim
// Hand-optimized as this previously took up to 9% of time w eExtent;
hen colorArray[i].set(trail.color[0], trail.color[1], tr
// trail groups were enabled. Now it's up to 3%. Further opt ail.color[2], colorRatio*opacity);
imization vertexArray[i]=posHistory.at(i);
// is possible, but would lead to more uglification. }
int posCount = posHistory.size(); sPainter->setVertexPointer(3, GL_DOUBLE, vertexArray.constDa
int p = 0; ta());
const float timeMult = 1.0f / timeExtent; sPainter->setColorPointer(4, GL_FLOAT, colorArray.constData(
ColoredVertex vertex; ));
for (p = 0; p < posCount - 1; ++p) sPainter->enableClientStates(true, false, true);
{ sPainter->drawFromArray(StelPainter::LineStrip, vertexArray.
// Skip if too many positions, but don't skip the la size(), 0, true);
st position. sPainter->enableClientStates(false);
if(p % skip != 0)
{
continue;
}
const float colorRatio = 1.0f - (currentTime - times
.at(p)) * timeMult;
vertex.color = Vec4f(trail.color[0], trail.color[1],
trail.color[2], colorRatio * opacity);
vertex.position = posHistory.at(p);
trail.vertexBuffer->addVertex(vertex);
}
// Last vertex (separate to avoid a branch in the code above
)
const float colorRatio = 1.0f - (currentTime - times.at(p))
* timeMult;
vertex.color = Vec4f(trail.color[0], trail.color[1], trail.c
olor[2], colorRatio * opacity);
vertex.position = posHistory.at(p);
trail.vertexBuffer->addVertex(vertex);
trail.vertexBuffer->lock();
renderer->drawVertexBuffer(trail.vertexBuffer, NULL, project
or);
} }
} }
// Add 1 point to all the curves at current time and suppress too old point s // Add 1 point to all the curves at current time and suppress too old point s
void TrailGroup::update() void TrailGroup::update()
{ {
const double time = StelApp::getInstance().getCore()->getJDay(); times.append(StelApp::getInstance().getCore()->getJDay());
const double timeDelta = for (QList<Trail>::Iterator iter=allTrails.begin();iter!=allTrails.e
times.size() == 0 ? 1000.0 : std::fabs(lastTimeInHistory - t nd();++iter)
ime);
// Only add a position if enough time has passed.
if(timeDelta > StelCore::JD_MINUTE)
{ {
times.append(time); iter->posHistory.append(j2000ToTrailNative*iter->stelObject-
lastTimeInHistory = time; >getJ2000EquatorialPos(StelApp::getInstance().getCore()));
for (QList<Trail>::Iterator iter=allTrails.begin();iter!=all
Trails.end();++iter)
{
const Vec3d p = j2000ToTrailNative *
iter->stelObject->getJ2000Equatorial
Pos(StelApp::getInstance().getCore());
iter->posHistory.append(Vec3f(p[0], p[1], p[2]));
}
} }
if (StelApp::getInstance().getCore()->getJDay()-times.at(0)>timeExte nt) if (StelApp::getInstance().getCore()->getJDay()-times.at(0)>timeExte nt)
{ {
times.pop_front(); times.pop_front();
for (QList<Trail>::Iterator iter=allTrails.begin();iter!=all Trails.end();++iter) for (QList<Trail>::Iterator iter=allTrails.begin();iter!=all Trails.end();++iter)
{ {
iter->posHistory.pop_front(); iter->posHistory.pop_front();
} }
} }
} }
 End of changes. 13 change blocks. 
106 lines changed or deleted 37 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/