Constellation.cpp   Constellation.cpp 
skipping to change at line 21 skipping to change at line 21
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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 <algorithm>
#include <QString>
#include <QTextStream>
#include <QDebug>
#include <QFontMetrics>
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "Constellation.hpp" #include "Constellation.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "renderer/StelCircleArcRenderer.hpp" #include "StelTexture.hpp"
#include "renderer/StelRenderer.hpp" #include "StelPainter.hpp"
#include "renderer/StelTextureNew.hpp"
#include "renderer/StelIndexBuffer.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include <algorithm>
#include <QString>
#include <QTextStream>
#include <QDebug>
#include <QFontMetrics>
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() Constellation::Constellation()
: asterism(NULL) : numberOfSegments(0)
, artTexture(NULL) , asterism(NULL)
, artVertices(NULL)
, artIndices(NULL)
{ {
} }
Constellation::~Constellation() Constellation::~Constellation()
{ {
if (NULL != asterism) {delete[] asterism;} delete[] asterism;
if (NULL != artTexture) {delete artTexture;} asterism = NULL;
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 162 skipping to change at line 101
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(StelRenderer* renderer, StelProjectorP projec tor, const StelCore* core, const SphericalCap& viewportHalfspace) const void Constellation::drawOptim(StelPainter& sPainter, const StelCore* core, const SphericalCap& viewportHalfspace) const
{ {
// Avoid drawing when not visible if (lineFader.getInterstate()<=0.0001f)
if (lineFader.getInterstate() <= 0.001f)
{
return; return;
}
renderer->setGlobalColor(lineColor[0], lineColor[1], sPainter.setColor(lineColor[0], lineColor[1], lineColor[2], lineFade
lineColor[2], lineFader.getInterstate()); r.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();
StelCircleArcRenderer(renderer, projector) sPainter.drawGreatCircleArc(star1, star2, &viewportHalfspace
.drawGreatCircleArc(star1, star2, &viewportHalfspace );
);
} }
} }
void Constellation::drawName(StelRenderer* renderer, QFont& font) const void Constellation::drawName(StelPainter& sPainter) const
{ {
if (nameFader.getInterstate() <= 0.001f) if (!nameFader.getInterstate())
{
return; return;
} sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], nameF
ader.getInterstate());
renderer->setFont(font); sPainter.drawText(XYname[0], XYname[1], nameI18, 0., -sPainter.getFo
renderer->setGlobalColor(labelColor[0], labelColor[1], ntMetrics().width(nameI18)/2, 0, false);
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 void Constellation::drawArtOptim(StelPainter& sPainter, const SphericalRegi
(StelRenderer* renderer, StelProjectorP projector, const SphericalRe on& region) const
gion& region) const
{ {
const float intensity = artFader.getInterstate(); const float intensity = artFader.getInterstate();
// Art polygon not yet generated (only generated once the texture is if (artTexture && intensity && region.intersects(boundingCap))
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(); sPainter.setColor(intensity,intensity,intensity);
if (StelApp::getInstance().getVisionModeNight())
renderer->setGlobalColor(intensity, 0.0, 0.0); // The texture is not fully loaded
else if (artTexture->bind()==false)
renderer->setGlobalColor(intensity,intensity,intensi return;
ty);
renderer->drawVertexBuffer(artVertices, artIndices, projecto sPainter.drawStelVertexArray(artPolygon);
r);
} }
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 247 skipping to change at line 179
} }
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(StelRenderer* renderer, StelProjector P projector) const void Constellation::drawBoundaryOptim(StelPainter& sPainter) const
{ {
if (boundaryFader.getInterstate() < 0.001) if (!boundaryFader.getInterstate())
{
return; return;
}
renderer->setBlendMode(BlendMode_Alpha); sPainter.enableTexture2d(false);
renderer->setGlobalColor(boundaryColor[0], boundaryColor[1], glEnable(GL_BLEND);
boundaryColor[2], boundaryFader.getIntersta glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa
te()); rency mode
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;
int size = singleSelected ? isolatedBoundarySegments.size() if (singleSelected) size = isolatedBoundarySegments.size();
: sharedBoundarySegments.size(); else size = sharedBoundarySegments.size();
const SphericalCap& viewportHalfspace = projector->getBoundingCap(); const SphericalCap& viewportHalfspace = sPainter.getProjector()->get BoundingCap();
for (int i = 0; i < size; i++) for (i=0;i<size;i++)
{ {
std::vector<Vec3f>* points = singleSelected ? isolatedBounda if (singleSelected) points = isolatedBoundarySegments[i];
rySegments[i] else points = sharedBoundarySegments[i];
: sharedBoundary
Segments[i];
for (int j = 0; j < static_cast<int>(points->size()) - 1; j+ +) for (j=0;j<points->size()-1;j++)
{ {
const Vec3f pt1 = points->at(j) ; pt1 = points->at(j);
const Vec3f pt2 = points->at(j +1); 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]);
const Vec3d ptd1(pt1[0], pt1[1], pt1[2]); ptd2.set(pt2[0], pt2[1], pt2[2]);
const Vec3d ptd2(pt2[0], pt2[1], pt2[2]); sPainter.drawGreatCircleArc(ptd1, ptd2, &viewportHal
StelCircleArcRenderer(renderer, projector) fspace);
.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:
for (int i=2*numberOfSegments-1;i>=0;i--) for (int i=2*numberOfSegments-1;i>=0;i--)
{ {
const float Mag = asterism[i]->getVMagnitude(0, false); const float Mag = asterism[i]->getVMagnitude(0);
if (Mag < maxMag) if (Mag < maxMag)
{ {
brightest = asterism[i]; brightest = asterism[i];
maxMag = Mag; maxMag = Mag;
} }
} }
return brightest; return brightest;
} }
 End of changes. 31 change blocks. 
152 lines changed or deleted 80 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/