StelPainter.cpp   StelPainter.cpp 
skipping to change at line 21 skipping to change at line 21
* 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 "StelPainter.hpp" #include "StelPainter.hpp"
#include <QtOpenGL> #include <QtOpenGL>
#include "StelApp.hpp"
#include "StelLocaleMgr.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelProjectorClasses.hpp" #include "StelProjectorClasses.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QDebug> #include <QDebug>
#include <QString> #include <QString>
#include <QSettings> #include <QSettings>
#include <QLinkedList> #include <QLinkedList>
#include <QPainter> #include <QPainter>
#include <QMutex> #include <QMutex>
skipping to change at line 458 skipping to change at line 459
static Vec3f lightPos3; static Vec3f lightPos3;
static Vec4f ambientLight; static Vec4f ambientLight;
static Vec4f diffuseLight; static Vec4f diffuseLight;
float c; float c;
const bool isLightOn = light.isEnabled(); const bool isLightOn = light.isEnabled();
if (isLightOn) if (isLightOn)
{ {
lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]); lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]);
Vec3f tmpv(0.f); Vec3f tmpv(0.f);
prj->getModelViewTransform()->forward(tmpv); // -posCenterEy e prj->getModelViewTransform()->forward(tmpv); // -posCenterEy e
lightPos3 -= tmpv; //lightPos3 -= tmpv;
//lightPos3 = prj->modelViewMatrixf.transpose().multiplyWith outTranslation(lightPos3); //lightPos3 = prj->modelViewMatrixf.transpose().multiplyWith outTranslation(lightPos3);
prj->getModelViewTransform()->getApproximateLinearTransfo(). transpose().multiplyWithoutTranslation(Vec3d(lightPos3[0], lightPos3[1], li ghtPos3[2]));
prj->getModelViewTransform()->backward(lightPos3); prj->getModelViewTransform()->backward(lightPos3);
lightPos3.normalize(); lightPos3.normalize();
ambientLight = light.getAmbient(); ambientLight = light.getAmbient();
diffuseLight = light.getDiffuse(); diffuseLight = light.getDiffuse();
} }
const float nsign = orientInside?-1.f:1.f; const float nsign = orientInside?-1.f:1.f;
const float dr = (rMax-rMin) / stacks; const float dr = (rMax-rMin) / stacks;
const float dtheta = 2.f * M_PI / slices; const float dtheta = 2.f * M_PI / slices;
skipping to change at line 613 skipping to change at line 615
void StelPainter::drawTextGravity180(float x, float y, const QString& ws, f loat xshift, float yshift) void StelPainter::drawTextGravity180(float x, float y, const QString& ws, f loat xshift, float yshift)
{ {
float dx, dy, d, theta, psi; float dx, dy, d, theta, psi;
dx = x - prj->viewportCenter[0]; dx = x - prj->viewportCenter[0];
dy = y - prj->viewportCenter[1]; dy = y - prj->viewportCenter[1];
d = std::sqrt(dx*dx + dy*dy); d = std::sqrt(dx*dx + dy*dy);
// If the text is too far away to be visible in the screen return // If the text is too far away to be visible in the screen return
if (d>qMax(prj->viewportXywh[3], prj->viewportXywh[2])*2) if (d>qMax(prj->viewportXywh[3], prj->viewportXywh[2])*2)
return; return;
theta = M_PI + std::atan2(dx, dy - 1); theta = std::atan2(dy - 1, dx);
psi = std::atan2((float)qPainter->fontMetrics().width(ws)/ws.length( ),d + 1) * 180./M_PI; psi = std::atan2((float)qPainter->fontMetrics().width(ws)/ws.length( ),d + 1) * 180./M_PI;
if (psi>5) if (psi>5) {
psi = 5; psi = 5;
}
const float cosr = std::cos(-theta * M_PI/180.); float cWidth = (float)qPainter->fontMetrics().width(ws)/ws.length();
const float sinr = std::sin(-theta * M_PI/180.); float xVc = prj->viewportCenter[0] + xshift;
float yVc = prj->viewportCenter[1] + yshift;
float initX = x + xshift*cosr - yshift*sinr;
float initY = y + yshift*sinr + yshift*cosr; QString lang = StelApp::getInstance().getLocaleMgr().getAppLanguage(
);
for (int i=0;i<ws.length();++i) if (!QString("ar fa ur he yi").contains(lang)) {
for (int i=0; i<ws.length(); ++i)
{
x = d * std::cos (theta) + xVc ;
y = d * std::sin (theta) + yVc ;
drawText(x, y, ws[i], 90. + theta*180./M_PI, 0., 0.)
;
// Compute how much the character contributes to the
angle
theta += psi * M_PI/180. * (1 + ((float)qPainter->fo
ntMetrics().width(ws[i]) - cWidth)/ cWidth);
}
}
else
{ {
drawText(initX, initY, ws[i], -theta*180./M_PI+psi*i, 0., 0. int slen = ws.length();
); for (int i=0;i<slen;i++)
xshift = (float)qPainter->fontMetrics().width(ws.mid(i,1)) * {
1.05; x = d * std::cos (theta) + xVc;
initX+=xshift*std::cos(-theta+psi*i * M_PI/180.); y = d * std::sin (theta) + yVc;
initY+=xshift*std::sin(-theta+psi*i * M_PI/180.); drawText(x, y, ws[slen-1-i], 90. + theta*180./M_PI,
0., 0.);
theta += psi * M_PI/180. * (1 + ((float)qPainter->fo
ntMetrics().width(ws[slen-1-i]) - cWidth)/ cWidth);
}
} }
} }
void StelPainter::drawText(const Vec3d& v, const QString& str, float angleD eg, float xshift, float yshift, bool noGravity) void StelPainter::drawText(const Vec3d& v, const QString& str, float angleD eg, float xshift, float yshift, bool noGravity)
{ {
Vec3d win; Vec3d win;
prj->project(v, win); prj->project(v, win);
drawText(win[0], win[1], str, angleDeg, xshift, yshift, noGravity); drawText(win[0], win[1], str, angleDeg, xshift, yshift, noGravity);
} }
skipping to change at line 670 skipping to change at line 686
void StelPainter::drawText(float x, float y, const QString& str, float angl eDeg, float xshift, float yshift, bool noGravity) void StelPainter::drawText(float x, float y, const QString& str, float angl eDeg, float xshift, float yshift, bool noGravity)
{ {
Q_ASSERT(qPainter); Q_ASSERT(qPainter);
if (prj->gravityLabels && !noGravity) if (prj->gravityLabels && !noGravity)
{ {
drawTextGravity180(x, y, str, xshift, yshift); drawTextGravity180(x, y, str, xshift, yshift);
} }
else else
{ {
static const int cacheLimitByte = 7000000; static const int cacheLimitByte = 10000000;
static QCache<QByteArray,StringTexture> texCache(cacheLimitB yte); static QCache<QByteArray,StringTexture> texCache(cacheLimitB yte);
int pixelSize = qPainter->font().pixelSize(); int pixelSize = qPainter->font().pixelSize();
QByteArray hash = str.toUtf8() + QByteArray::number(pixelSiz e); QByteArray hash = str.toUtf8() + QByteArray::number(pixelSiz e);
const StringTexture* cachedTex = texCache.object(hash); const StringTexture* cachedTex = texCache.object(hash);
if (cachedTex == NULL) // need to create texture if (cachedTex == NULL) // need to create texture
{ {
StringTexture* newTex = new StringTexture(); StringTexture* newTex = new StringTexture();
// Create temp image and render text into it // Create temp image and render text into it
skipping to change at line 1580 skipping to change at line 1596
static Vec3f lightPos3; static Vec3f lightPos3;
static Vec4f ambientLight; static Vec4f ambientLight;
static Vec4f diffuseLight; static Vec4f diffuseLight;
float c; float c;
const bool isLightOn = light.isEnabled(); const bool isLightOn = light.isEnabled();
if (isLightOn) if (isLightOn)
{ {
lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]); lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]);
Vec3f tmpv(0.f); Vec3f tmpv(0.f);
prj->getModelViewTransform()->forward(tmpv); // -posCenterEy e prj->getModelViewTransform()->forward(tmpv); // -posCenterEy e
lightPos3 -= tmpv; //lightPos3 -= tmpv;
//lightPos3 = prj->modelViewMatrixf.transpose().multiplyWith outTranslation(lightPos3); //lightPos3 = prj->modelViewMatrixf.transpose().multiplyWith outTranslation(lightPos3);
prj->getModelViewTransform()->getApproximateLinearTransfo(). transpose().multiplyWithoutTranslation(Vec3d(lightPos3[0], lightPos3[1], li ghtPos3[2]));
prj->getModelViewTransform()->backward(lightPos3); prj->getModelViewTransform()->backward(lightPos3);
lightPos3.normalize(); lightPos3.normalize();
ambientLight = light.getAmbient(); ambientLight = light.getAmbient();
diffuseLight = light.getDiffuse(); diffuseLight = light.getDiffuse();
} }
GLfloat x, y, z; GLfloat x, y, z;
GLfloat s=0.f, t=0.f; GLfloat s=0.f, t=0.f;
GLint i, j; GLint i, j;
GLfloat nsign; GLfloat nsign;
skipping to change at line 1626 skipping to change at line 1643
// cannot use triangle fan on texturing (s coord. at top/bottom tip varies) // cannot use triangle fan on texturing (s coord. at top/bottom tip varies)
// If the texture is flipped, we iterate the coordinates backward. // If the texture is flipped, we iterate the coordinates backward.
const GLfloat ds = (flipTexture ? -1.f : 1.f) / slices; const GLfloat ds = (flipTexture ? -1.f : 1.f) / slices;
const GLfloat dt = nsign / stacks; // from inside texture is reverse d const GLfloat dt = nsign / stacks; // from inside texture is reverse d
// draw intermediate as quad strips // draw intermediate as quad strips
static QVector<double> vertexArr; static QVector<double> vertexArr;
static QVector<float> texCoordArr; static QVector<float> texCoordArr;
static QVector<float> colorArr; static QVector<float> colorArr;
static QVector<unsigned int> indiceArr; static QVector<unsigned int> indiceArr;
texCoordArr.resize(0); texCoordArr.resize(0);
vertexArr.resize(0); vertexArr.resize(0);
colorArr.resize(0); colorArr.resize(0);
indiceArr.resize(0); indiceArr.resize(0);
for (i = 0,cos_sin_rho_p = cos_sin_rho; i < stacks; ++i,cos_sin_rho_ p+=2) for (i = 0,cos_sin_rho_p = cos_sin_rho; i < stacks; ++i,cos_sin_rho_ p+=2)
{ {
s = !flipTexture ? 0.f : 1.f; s = !flipTexture ? 0.f : 1.f;
for (j = 0,cos_sin_theta_p = cos_sin_theta; j<=slices;++j,co s_sin_theta_p+=2) for (j = 0,cos_sin_theta_p = cos_sin_theta; j<=slices;++j,co s_sin_theta_p+=2)
{ {
x = -cos_sin_theta_p[1] * cos_sin_rho_p[1]; x = -cos_sin_theta_p[1] * cos_sin_rho_p[1];
y = cos_sin_theta_p[0] * cos_sin_rho_p[1]; y = cos_sin_theta_p[0] * cos_sin_rho_p[1];
z = nsign * cos_sin_rho_p[0]; z = nsign * cos_sin_rho_p[0];
texCoordArr << s << t; texCoordArr << s << t;
if (isLightOn) if (isLightOn)
skipping to change at line 1932 skipping to change at line 1951
fshader4->compileSourceCode(fsrc4); fshader4->compileSourceCode(fsrc4);
texturesColorShaderProgram = new QGLShaderProgram(QGLContext::curren tContext()); texturesColorShaderProgram = new QGLShaderProgram(QGLContext::curren tContext());
texturesColorShaderProgram->addShader(vshader4); texturesColorShaderProgram->addShader(vshader4);
texturesColorShaderProgram->addShader(fshader4); texturesColorShaderProgram->addShader(fshader4);
texturesColorShaderProgram->link(); texturesColorShaderProgram->link();
texturesColorShaderVars.projectionMatrix = texturesColorShaderProgra m->uniformLocation("projectionMatrix"); texturesColorShaderVars.projectionMatrix = texturesColorShaderProgra m->uniformLocation("projectionMatrix");
texturesColorShaderVars.texCoord = texturesColorShaderProgram->attri buteLocation("texCoord"); texturesColorShaderVars.texCoord = texturesColorShaderProgram->attri buteLocation("texCoord");
texturesColorShaderVars.vertex = texturesColorShaderProgram->attribu teLocation("vertex"); texturesColorShaderVars.vertex = texturesColorShaderProgram->attribu teLocation("vertex");
texturesColorShaderVars.color = texturesColorShaderProgram->attribut eLocation("color"); texturesColorShaderVars.color = texturesColorShaderProgram->attribut eLocation("color");
texturesColorShaderVars.texture = texturesColorShaderProgram->unifor mLocation("tex"); texturesColorShaderVars.texture = texturesColorShaderProgram->unifor mLocation("tex");
#endif #endif
} }
void StelPainter::setArrays(const Vec3d* vertice, const Vec2f* texCoords, c onst Vec3f* colorArray, const Vec3f* normalArray) void StelPainter::setArrays(const Vec3d* vertice, const Vec2f* texCoords, c onst Vec3f* colorArray, const Vec3f* normalArray)
{ {
enableClientStates(vertice, texCoords, colorArray, normalArray); enableClientStates(vertice, texCoords, colorArray, normalArray);
setVertexPointer(3, GL_DOUBLE, vertice); setVertexPointer(3, GL_DOUBLE, vertice);
setTexCoordPointer(2, GL_FLOAT, texCoords); setTexCoordPointer(2, GL_FLOAT, texCoords);
setColorPointer(3, GL_FLOAT, colorArray); setColorPointer(3, GL_FLOAT, colorArray);
setNormalPointer(GL_FLOAT, normalArray); setNormalPointer(GL_FLOAT, normalArray);
skipping to change at line 1988 skipping to change at line 2008
Q_ASSERT(normalArray.pointer); Q_ASSERT(normalArray.pointer);
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(normalArray.type, 0, normalArray.pointer); glNormalPointer(normalArray.type, 0, normalArray.pointer);
} }
if (colorArray.enabled) if (colorArray.enabled)
{ {
Q_ASSERT(colorArray.pointer); Q_ASSERT(colorArray.pointer);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(colorArray.size, colorArray.type, 0, colorArr ay.pointer); glColorPointer(colorArray.size, colorArray.type, 0, colorArr ay.pointer);
} }
#else #else
QGLShaderProgram* pr=NULL; QGLShaderProgram* pr=NULL;
const Mat4f& m = getProjector()->getProjectionMatrix(); const Mat4f& m = getProjector()->getProjectionMatrix();
const QMatrix4x4 qMat(m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[1 3], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]); const QMatrix4x4 qMat(m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[1 3], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]);
if (!texCoordArray.enabled && !colorArray.enabled && !normalArray.en abled) if (!texCoordArray.enabled && !colorArray.enabled && !normalArray.en abled)
{ {
pr = basicShaderProgram; pr = basicShaderProgram;
pr->bind(); pr->bind();
 End of changes. 16 change blocks. 
19 lines changed or deleted 44 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/