Constellation.cpp   Constellation.cpp 
skipping to change at line 31 skipping to change at line 31
#include <algorithm> #include <algorithm>
#include <QString> #include <QString>
#include <QTextStream> #include <QTextStream>
#include <QDebug> #include <QDebug>
#include <QFontMetrics> #include <QFontMetrics>
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "Constellation.hpp" #include "Constellation.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "StelTexture.hpp" #include "renderer/StelCircleArcRenderer.hpp"
#include "StelPainter.hpp" #include "renderer/StelRenderer.hpp"
#include "renderer/StelTextureNew.hpp"
#include "renderer/StelIndexBuffer.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
Vec3f Constellation::lineColor = Vec3f(0.4,0.4,0.8); Vec3f Constellation::lineColor = Vec3f(0.4,0.4,0.8);
Vec3f Constellation::labelColor = Vec3f(0.4,0.4,0.8); Vec3f Constellation::labelColor = Vec3f(0.4,0.4,0.8);
Vec3f Constellation::boundaryColor = Vec3f(0.8,0.3,0.3); Vec3f Constellation::boundaryColor = Vec3f(0.8,0.3,0.3);
bool Constellation::singleSelected = false; bool Constellation::singleSelected = false;
Constellation::Constellation() : asterism(NULL) Constellation::Constellation()
: asterism(NULL)
, artTexture(NULL)
, artVertices(NULL)
, artIndices(NULL)
{ {
} }
Constellation::~Constellation() Constellation::~Constellation()
{ {
if (asterism) delete[] asterism; if (NULL != asterism) {delete[] asterism;}
asterism = NULL; if (NULL != artTexture) {delete artTexture;}
if (NULL != artVertices) {delete artVertices;}
if (NULL != artIndices) {delete artIndices;}
asterism = NULL;
artTexture = NULL;
artVertices = NULL;
artIndices = NULL;
}
void Constellation::generateArtVertices(StelRenderer* renderer, const int r
esolution)
{
// Texture not yet loaded.
if (NULL == artTexture || !artTexture->getStatus() == TextureStatus_
Loaded)
{
// artVertices will be still NULL, and it will be generated
in a future
// call once the texture is loaded
return;
}
const QSize texSize = artTexture->getDimensions();
artVertices = renderer->createVertexBuffer<Vertex>(PrimitiveType_Tri
angles);
artIndices = renderer->createIndexBuffer(IndexType_U16);
const float mult = 1.0f / resolution;
// Create the vertex grid.
for (int y = 0; y <= resolution; ++y)
{
for (int x = 0; x <= resolution; ++x)
{
const float texX = x * mult;
const float texY = y * mult;
artVertices->addVertex
(Vertex(texCoordTo3D * Vec3f(texX * texSize.
width(), texY * texSize.height(), 0.0f),
Vec2f(texX, texY)));
}
}
// Use indices to form a triangle pair for every cell of the grid.
for (int y = 0; y < resolution; ++y)
{
for (int x = 0; x < resolution; ++x)
{
const uint sw = x * (resolution + 1) + y;
const uint se = (x + 1) * (resolution + 1) + y;
const uint nw = x * (resolution + 1) + y + 1;
const uint ne = (x + 1) * (resolution + 1) + y + 1;
artIndices->addIndex(nw);
artIndices->addIndex(se);
artIndices->addIndex(sw);
artIndices->addIndex(nw);
artIndices->addIndex(ne);
artIndices->addIndex(se);
}
}
artVertices->lock();
artIndices->lock();
} }
bool Constellation::read(const QString& record, StarMgr *starMgr) bool Constellation::read(const QString& record, StarMgr *starMgr)
{ {
unsigned int HP; unsigned int HP;
abbreviation.clear(); abbreviation.clear();
numberOfSegments = 0; numberOfSegments = 0;
QString buf(record); QString buf(record);
skipping to change at line 99 skipping to change at line 162
XYZname.set(0.,0.,0.); XYZname.set(0.,0.,0.);
for(unsigned int ii=0;ii<numberOfSegments*2;++ii) for(unsigned int ii=0;ii<numberOfSegments*2;++ii)
{ {
XYZname+= asterism[ii]->getJ2000EquatorialPos(StelApp::getIn stance().getCore()); XYZname+= asterism[ii]->getJ2000EquatorialPos(StelApp::getIn stance().getCore());
} }
XYZname.normalize(); XYZname.normalize();
return true; return true;
} }
void Constellation::drawOptim(StelPainter& sPainter, const StelCore* core, const SphericalCap& viewportHalfspace) const void Constellation::drawOptim(StelRenderer* renderer, StelProjectorP projec tor, const StelCore* core, const SphericalCap& viewportHalfspace) const
{ {
if (lineFader.getInterstate()<=0.0001f) // Avoid drawing when not visible
if (lineFader.getInterstate() <= 0.001f)
{
return; return;
}
sPainter.setColor(lineColor[0], lineColor[1], lineColor[2], lineFade renderer->setGlobalColor(lineColor[0], lineColor[1],
r.getInterstate()); lineColor[2], lineFader.getInterstate());
Vec3d star1; Vec3d star1;
Vec3d star2; Vec3d star2;
for (unsigned int i=0;i<numberOfSegments;++i) for (unsigned int i = 0; i < numberOfSegments; ++i)
{ {
star1=asterism[2*i]->getJ2000EquatorialPos(core); star1 = asterism[2 * i]->getJ2000EquatorialPos(core);
star2=asterism[2*i+1]->getJ2000EquatorialPos(core); star2 = asterism[2 * i + 1]->getJ2000EquatorialPos(core);
star1.normalize(); star1.normalize();
star2.normalize(); star2.normalize();
sPainter.drawGreatCircleArc(star1, star2, &viewportHalfspace StelCircleArcRenderer(renderer, projector)
); .drawGreatCircleArc(star1, star2, &viewportHalfspace
);
} }
} }
void Constellation::drawName(StelPainter& sPainter) const void Constellation::drawName(StelRenderer* renderer, QFont& font) const
{ {
if (!nameFader.getInterstate()) if (nameFader.getInterstate() <= 0.001f)
{
return; return;
sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], nameF }
ader.getInterstate());
sPainter.drawText(XYname[0], XYname[1], nameI18, 0., -sPainter.getFo renderer->setFont(font);
ntMetrics().width(nameI18)/2, 0, false); renderer->setGlobalColor(labelColor[0], labelColor[1],
labelColor[2], nameFader.getInterstate());
renderer->drawText(TextParams(XYname[0], XYname[1], nameI18)
.shift(-QFontMetrics(font).width(nameI18) * 0.5,
0.0f)
.useGravity());
} }
void Constellation::drawArtOptim(StelPainter& sPainter, const SphericalRegi void Constellation::drawArtOptim
on& region) const (StelRenderer* renderer, StelProjectorP projector, const SphericalRe
gion& region) const
{ {
const float intensity = artFader.getInterstate(); const float intensity = artFader.getInterstate();
if (artTexture && intensity && region.intersects(boundingCap)) // Art polygon not yet generated (only generated once the texture is
loaded)
if (NULL == artVertices) {return;}
Q_ASSERT_X(NULL != artIndices, Q_FUNC_INFO,
"Vertex buffer was generated but index buffer was not");
renderer->setCulledFaces(CullFace_Back);
// Don't draw if outside viewport.
if (intensity > 0.001f && region.intersects(boundingCap))
{ {
artTexture->bind();
if (StelApp::getInstance().getVisionModeNight()) if (StelApp::getInstance().getVisionModeNight())
sPainter.setColor(intensity, 0.0, 0.0); renderer->setGlobalColor(intensity, 0.0, 0.0);
else else
sPainter.setColor(intensity,intensity,intensity); renderer->setGlobalColor(intensity,intensity,intensi
ty);
// The texture is not fully loaded renderer->drawVertexBuffer(artVertices, artIndices, projecto
if (artTexture->bind()==false) r);
return;
sPainter.drawStelVertexArray(artPolygon);
} }
} renderer->setCulledFaces(CullFace_None);
// Draw the art texture
void Constellation::drawArt(StelPainter& sPainter) const
{
glBlendFunc(GL_ONE, GL_ONE);
sPainter.enableTexture2d(true);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
SphericalRegionP region = sPainter.getProjector()->getViewportConvex
Polygon();
drawArtOptim(sPainter, *region);
glDisable(GL_CULL_FACE);
} }
const Constellation* Constellation::isStarIn(const StelObject* s) const const Constellation* Constellation::isStarIn(const StelObject* s) const
{ {
for(unsigned int i=0;i<numberOfSegments*2;++i) for(unsigned int i=0;i<numberOfSegments*2;++i)
{ {
// asterism[i]==s test was not working // asterism[i]==s test was not working
if (asterism[i]->getEnglishName()==s->getEnglishName()) if (asterism[i]->getEnglishName()==s->getEnglishName())
{ {
skipping to change at line 180 skipping to change at line 247
} }
void Constellation::update(int deltaTime) void Constellation::update(int deltaTime)
{ {
lineFader.update(deltaTime); lineFader.update(deltaTime);
nameFader.update(deltaTime); nameFader.update(deltaTime);
artFader.update(deltaTime); artFader.update(deltaTime);
boundaryFader.update(deltaTime); boundaryFader.update(deltaTime);
} }
void Constellation::drawBoundaryOptim(StelPainter& sPainter) const void Constellation::drawBoundaryOptim(StelRenderer* renderer, StelProjector P projector) const
{ {
if (!boundaryFader.getInterstate()) if (boundaryFader.getInterstate() < 0.001)
{
return; return;
}
sPainter.enableTexture2d(false); renderer->setBlendMode(BlendMode_Alpha);
glEnable(GL_BLEND); renderer->setGlobalColor(boundaryColor[0], boundaryColor[1],
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa boundaryColor[2], boundaryFader.getIntersta
rency mode te());
sPainter.setColor(boundaryColor[0], boundaryColor[1], boundaryColor[
2], boundaryFader.getInterstate());
unsigned int i, j, size;
Vec3f pt1, pt2;
Vec3d ptd1, ptd2;
std::vector<Vec3f> *points;
if (singleSelected) size = isolatedBoundarySegments.size(); int size = singleSelected ? isolatedBoundarySegments.size()
else size = sharedBoundarySegments.size(); : sharedBoundarySegments.size();
const SphericalCap& viewportHalfspace = sPainter.getProjector()->get BoundingCap(); const SphericalCap& viewportHalfspace = projector->getBoundingCap();
for (i=0;i<size;i++) for (int i = 0; i < size; i++)
{ {
if (singleSelected) points = isolatedBoundarySegments[i]; std::vector<Vec3f>* points = singleSelected ? isolatedBounda
else points = sharedBoundarySegments[i]; rySegments[i]
: sharedBoundary
Segments[i];
for (j=0;j<points->size()-1;j++) for (int j = 0; j < static_cast<int>(points->size()) - 1; j+ +)
{ {
pt1 = points->at(j); const Vec3f pt1 = points->at(j) ;
pt2 = points->at(j+1); const Vec3f pt2 = points->at(j +1);
if (pt1*pt2>0.9999999f) if (pt1 * pt2 > 0.9999999f)
{
continue; continue;
ptd1.set(pt1[0], pt1[1], pt1[2]); }
ptd2.set(pt2[0], pt2[1], pt2[2]); const Vec3d ptd1(pt1[0], pt1[1], pt1[2]);
sPainter.drawGreatCircleArc(ptd1, ptd2, &viewportHal const Vec3d ptd2(pt2[0], pt2[1], pt2[2]);
fspace); StelCircleArcRenderer(renderer, projector)
.drawGreatCircleArc(ptd1, ptd2, &viewportHal
fspace);
} }
} }
} }
StelObjectP Constellation::getBrightestStarInConstellation(void) const StelObjectP Constellation::getBrightestStarInConstellation(void) const
{ {
float maxMag = 99.f; float maxMag = 99.f;
StelObjectP brightest; StelObjectP brightest;
// maybe the brightest star has always odd index, // maybe the brightest star has always odd index,
// so check all segment endpoints: // so check all segment endpoints:
 End of changes. 30 change blocks. 
73 lines changed or deleted 144 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/