StelViewportEffect.cpp   StelViewportEffect.cpp 
skipping to change at line 31 skipping to change at line 31
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "SphericMirrorCalculator.hpp" #include "SphericMirrorCalculator.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "renderer/StelIndexBuffer.hpp" #include "renderer/StelIndexBuffer.hpp"
#include "renderer/StelRenderer.hpp" #include "renderer/StelRenderer.hpp"
#include <QSettings> #include <QSettings>
#include <QFile> #include <QFile>
#include <QDir>
StelViewportDistorterFisheyeToSphericMirror::StelViewportDistorterFisheyeTo SphericMirror StelViewportDistorterFisheyeToSphericMirror::StelViewportDistorterFisheyeTo SphericMirror
(int screenWidth,int screenHeight, StelRenderer* renderer) (int screenWidth,int screenHeight, StelRenderer* renderer)
: screenWidth(screenWidth) : screenWidth(screenWidth)
, screenHeight(screenHeight) , screenHeight(screenHeight)
, originalProjectorParams(StelApp::getInstance().getCore()-> , originalProjectorParams(StelApp::getInstance().getCore()->
getCurrentStelProjectorParams()) getCurrentStelProjectorParams())
, maxTexCoords(1.0f, 1.0f) , maxTexCoords(1.0f, 1.0f)
, texCoordGrid(NULL) , texCoordGrid(NULL)
, vertexGrid(renderer->createVertexBuffer<Vertex>(PrimitiveType_Tria ngleStrip)) , vertexGrid(renderer->createVertexBuffer<Vertex>(PrimitiveType_Tria ngleStrip))
skipping to change at line 105 skipping to change at line 106
newProjectorParams.viewportCenter[1] = newProjectorParams.viewportCenter[1] =
conf.value("spheric_mirror/viewportCenterY", conf.value("spheric_mirror/viewportCenterY",
0.5*newProjectorParams.viewportXywh[3]).toFloat(); 0.5*newProjectorParams.viewportXywh[3]).toFloat();
// diameter of the FOV-disk in pixels // diameter of the FOV-disk in pixels
newProjectorParams.viewportFovDiameter = newProjectorParams.viewportFovDiameter =
conf.value("spheric_mirror/viewport_fov_diameter", conf.value("spheric_mirror/viewport_fov_diameter",
qMin(newProjectorParams.viewportXywh[2], qMin(newProjectorParams.viewportXywh[2],
newProjectorParams.viewportXywh[3])).toFloat(); newProjectorParams.viewportXywh[3])).toFloat();
texture_wh = 1; // Vestigial mirror texture dimensions: used to be a single value,
while (texture_wh < newProjectorParams.viewportXywh[2] || // the closest power of 2 higher or equal to the larger screen dimen
texture_wh < newProjectorParams.viewportXywh[3]) sion.
{ texture_w = newProjectorParams.viewportXywh[2];
texture_wh <<= 1; texture_h = newProjectorParams.viewportXywh[3];
} // while (texture_wh < newProjectorParams.viewportXywh[2] ||
// texture_wh < newProjectorParams.viewportXywh[3])
viewportTextureOffset[0] = (texture_wh-newProjectorParams.viewportXy // {
wh[2])>>1; // texture_wh <<= 1;
viewportTextureOffset[1] = (texture_wh-newProjectorParams.viewportXy // }
wh[3])>>1;
// TODO: Given the above, is there any point in this? --BM
newProjectorParams.viewportXywh[0] = (screenWidth-newProjectorParams .viewportXywh[2]) >> 1; newProjectorParams.viewportXywh[0] = (screenWidth-newProjectorParams .viewportXywh[2]) >> 1;
newProjectorParams.viewportXywh[1] = (screenHeight-newProjectorParam s.viewportXywh[3]) >> 1; newProjectorParams.viewportXywh[1] = (screenHeight-newProjectorParam s.viewportXywh[3]) >> 1;
StelApp::getInstance().getCore()->setCurrentStelProjectorParams(newP rojectorParams); StelApp::getInstance().getCore()->setCurrentStelProjectorParams(newP rojectorParams);
const QString customDistortionFileName = const QString customDistortionFileName =
conf.value("spheric_mirror/custom_distortion_file","").toString( ); QDir::fromNativeSeparators(conf.value("spheric_mirror/custom_dis tortion_file","").toString());
if (customDistortionFileName.isEmpty()) if (customDistortionFileName.isEmpty())
{ {
generateDistortion(conf, proj, distorterMaxFOV, renderer); generateDistortion(conf, proj, distorterMaxFOV, renderer);
} }
else if (!loadDistortionFromFile(customDistortionFileName, renderer) ) else if (!loadDistortionFromFile(customDistortionFileName, renderer) )
{ {
qDebug() << "Falling back to generated distortion"; qDebug() << "Falling back to generated distortion";
generateDistortion(conf, proj, distorterMaxFOV, renderer); generateDistortion(conf, proj, distorterMaxFOV, renderer);
} }
skipping to change at line 209 skipping to change at line 211
// 512*512 and viewportFovDiameter=512 you will get clamping artefacts // 512*512 and viewportFovDiameter=512 you will get clamping artefacts
// in the 3 otherwise black hills on the bottom of t he image. // in the 3 otherwise black hills on the bottom of t he image.
// if (x < 0.f) {x=0.f;height=0;} // if (x < 0.f) {x=0.f;height=0;}
// else if (x > newProjectorParams.viewportXywh [2]) // else if (x > newProjectorParams.viewportXywh [2])
// {x=newProjectorParams.viewportXywh[2];he ight=0;} // {x=newProjectorParams.viewportXywh[2];he ight=0;}
// if (y < 0.f) {y=0.f;height=0;} // if (y < 0.f) {y=0.f;height=0;}
// else if (y > newProjectorParams.viewportXywh [3]) // else if (y > newProjectorParams.viewportXywh [3])
// {y=newProjectorParams.viewportXywh[3];he ight=0;} // {y=newProjectorParams.viewportXywh[3];he ight=0;}
vertex.texCoord[0] = (viewportTextureOffset[0] + x) vertex.texCoord[0] = x / texture_w;
/ texture_wh; vertex.texCoord[1] = y / texture_h;
vertex.texCoord[1] = (viewportTextureOffset[1] + y)
/ texture_wh;
texCoordGrid[row * cols + col] = vertex.texCoord; texCoordGrid[row * cols + col] = vertex.texCoord;
vertexGrid->addVertex(vertex); vertexGrid->addVertex(vertex);
maxHeight = qMax(height, maxHeight); maxHeight = qMax(height, maxHeight);
} }
} }
// Generate grid colors. (Separate from previous loop as we need max height) // Generate grid colors. (Separate from previous loop as we need max height)
for (int row = 0; row <= maxGridY; row++) for (int row = 0; row <= maxGridY; row++)
skipping to change at line 242 skipping to change at line 244
color[0] = color[1] = color[2] = gray; color[0] = color[1] = color[2] = gray;
color[3] = 1.0f; color[3] = 1.0f;
vertexGrid->setVertex(cell, vertex); vertexGrid->setVertex(cell, vertex);
} }
} }
constructVertexBuffer(renderer); constructVertexBuffer(renderer);
delete[] heightGrid; delete[] heightGrid;
// FIXME: Comment out with /**/ after testing. --BM
qDebug() << "StelViewportDistorterFisheyeToSphericMirror():"
<< "screen_w:" << this->screenWidth
<< "screen_h:" << this->screenHeight << endl
<< "originalProjectorParams.viewportXywh:"
<< originalProjectorParams.viewportXywh[0]
<< originalProjectorParams.viewportXywh[1]
<< originalProjectorParams.viewportXywh[2]
<< originalProjectorParams.viewportXywh[3] << endl
<< "newProjectorParams.viewportXywh:"
<< newProjectorParams.viewportXywh[0]
<< newProjectorParams.viewportXywh[1]
<< newProjectorParams.viewportXywh[2]
<< newProjectorParams.viewportXywh[3] << endl
<< "originalProjectorParams.fov:"
<< originalProjectorParams.fov << endl
<< "newProjectorParams.fov:" << newProjectorParams.fov << e
ndl
<< "originalProjectorParams.viewportCenter:"
<< originalProjectorParams.viewportCenter[0]
<< originalProjectorParams.viewportCenter[1] << endl
<< "newProjectorParams.viewportCenter:"
<< newProjectorParams.viewportCenter[0]
<< newProjectorParams.viewportCenter[1] << endl
<< "originalProjectorParams.viewportFovDiameter:"
<< originalProjectorParams.viewportFovDiameter << endl
<< "newProjectorParams.viewportFovDiameter:"
<< newProjectorParams.viewportFovDiameter << endl
<< "originalProjectorParams.zNear,zFar:"
<< originalProjectorParams.zNear
<< originalProjectorParams.zFar << endl
<< "newProjectorParams.zNear,zFar:"
<< newProjectorParams.zNear
<< newProjectorParams.zFar << endl
//<< "viewport_texture_offset:"
//<< viewport_texture_offset[0]
//<< viewport_texture_offset[1] << endl
<< "texture_w:" << texture_w << endl
<< "texture_h:" << texture_h << endl
<< "max_x:" << maxGridX << endl
<< "max_y:" << maxGridY;
} }
void StelViewportDistorterFisheyeToSphericMirror::loadGenerationParameters void StelViewportDistorterFisheyeToSphericMirror::loadGenerationParameters
(const QSettings& conf, double& gamma) (const QSettings& conf, double& gamma)
{ {
// Load generation parameters. // Load generation parameters.
float triangleBaseLength = float triangleBaseLength =
conf.value("spheric_mirror/texture_triangle_base_length",16.f).t oFloat(); conf.value("spheric_mirror/texture_triangle_base_length",16.f).t oFloat();
if (triangleBaseLength > 256.f) if (triangleBaseLength > 256.f)
{ {
qDebug() << "spheric_mirror/texture_triangle_base_length too high : setting to 256.0"; qDebug() << "spheric_mirror/texture_triangle_base_length too high : setting to 256.0";
triangleBaseLength = 256.f; triangleBaseLength = 256.f;
} }
else if (triangleBaseLength < 2.0f) else if (triangleBaseLength < 2.0f)
{ {
qDebug() << "spheric_mirror/texture_triangle_base_length too low : setting to 2.0"; qDebug() << "spheric_mirror/texture_triangle_base_length too low : setting to 2.0";
triangleBaseLength = 2.f; triangleBaseLength = 2.f;
} }
#ifdef _MSC_BUILD // MSVC does not have a trunc function
maxGridX = (int)floor(0.5 + screenWidth / triangleBaseLength);
maxGridY = (int)floor(screenHeight / (triangleBaseLength * 0.5 * sqr
t(3.0)));
#else
maxGridX = (int)trunc(0.5 + screenWidth / triangleBaseLength); maxGridX = (int)trunc(0.5 + screenWidth / triangleBaseLength);
stepX = screenWidth / (double)(maxGridX - 0.5);
maxGridY = (int)trunc(screenHeight / (triangleBaseLength * 0.5 * sqr t(3.0))); maxGridY = (int)trunc(screenHeight / (triangleBaseLength * 0.5 * sqr t(3.0)));
#endif
stepX = screenWidth / (double)(maxGridX - 0.5);
stepY = screenHeight / (double)maxGridY; stepY = screenHeight / (double)maxGridY;
gamma = conf.value("spheric_mirror/projector_gamma",0.45).toDouble() ; gamma = conf.value("spheric_mirror/projector_gamma",0.45).toDouble() ;
if (gamma < 0.0) if (gamma < 0.0)
{ {
qDebug() << "Negative spheric_mirror/projector_gamma : setti ng to zero."; qDebug() << "Negative spheric_mirror/projector_gamma : setti ng to zero.";
gamma = 0.0; gamma = 0.0;
} }
} }
skipping to change at line 289 skipping to change at line 337
try try
{ {
file.setFileName(StelFileMgr::findFile(fileName)); file.setFileName(StelFileMgr::findFile(fileName));
file.open(QIODevice::ReadOnly); file.open(QIODevice::ReadOnly);
if (file.error() != QFile::NoError) if (file.error() != QFile::NoError)
throw("failed to open file"); throw("failed to open file");
in.setDevice(&file); in.setDevice(&file);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "WARNING: could not open custom_distortion_fil e:" << fileName << e.what(); qWarning() << "WARNING: could not open custom_distortion_fil e:" << QDir::toNativeSeparators(fileName) << e.what();
return false; return false;
} }
Q_ASSERT(file.error() != QFile::NoError); Q_ASSERT(file.error() != QFile::NoError);
in >> maxGridX >> maxGridY; in >> maxGridX >> maxGridY;
Q_ASSERT(in.status() == QTextStream::Ok && maxGridX > 0 && maxGridY > 0); Q_ASSERT(in.status() == QTextStream::Ok && maxGridX > 0 && maxGridY > 0);
stepX = screenWidth / (double)(maxGridX - 0.5); stepX = screenWidth / (double)(maxGridX - 0.5);
stepY = screenHeight / (double)maxGridY; stepY = screenHeight / (double)maxGridY;
const int cols = maxGridX + 1; const int cols = maxGridX + 1;
skipping to change at line 318 skipping to change at line 366
Vertex vertex; Vertex vertex;
// Clamp to screen extents. // Clamp to screen extents.
vertex.position[0] = (col == 0) ? 0.f : vertex.position[0] = (col == 0) ? 0.f :
(col == maxGridX) ? screenWidth : (col == maxGridX) ? screenWidth :
(col - 0.5f * (row & 1)) * stepX; (col - 0.5f * (row & 1)) * stepX;
vertex.position[1] = row * stepY; vertex.position[1] = row * stepY;
float x, y; float x, y;
in >> x >> y >> vertex.color[0] >> vertex.color[1] > > vertex.color[2]; in >> x >> y >> vertex.color[0] >> vertex.color[1] > > vertex.color[2];
vertex.color[3] = 1.0f; vertex.color[3] = 1.0f;
Q_ASSERT(in.status() != QTextStream::Ok); Q_ASSERT(in.status() != QTextStream::Ok);
vertex.texCoord[0] = (viewportTextureOffset[0] + x) vertex.texCoord[0] = x / texture_w;
/ texture_wh; vertex.texCoord[1] = y / texture_h;
vertex.texCoord[1] = (viewportTextureOffset[1] + y)
/ texture_wh;
texCoordGrid[row * cols + col] = vertex.texCoord; texCoordGrid[row * cols + col] = vertex.texCoord;
vertexGrid->addVertex(vertex); vertexGrid->addVertex(vertex);
} }
} }
constructVertexBuffer(renderer); constructVertexBuffer(renderer);
return true; return true;
skipping to change at line 448 skipping to change at line 496
const Vec2f t0 = t[0]; const Vec2f t0 = t[0];
//This vertex on next line //This vertex on next line
const Vec2f t1 = t[cols]; const Vec2f t1 = t[cols];
//Next vertex on next line //Next vertex on next line
const Vec2f t2 = t[cols + 1]; const Vec2f t2 = t[cols + 1];
textureX = t1[0] + (1.f-dy) * (t0[0]-t1[0]) + dx * ( t2[0]-t1[0]); textureX = t1[0] + (1.f-dy) * (t0[0]-t1[0]) + dx * ( t2[0]-t1[0]);
textureY = t1[1] + (1.f-dy) * (t0[1]-t1[1]) + dx * ( t2[1]-t1[1]); textureY = t1[1] + (1.f-dy) * (t0[1]-t1[1]) + dx * ( t2[1]-t1[1]);
} }
} }
x = texture_wh*textureX - viewportTextureOffset[0] + newProjectorPar x = texture_w*textureX + newProjectorParams.viewportXywh[0];
ams.viewportXywh[0]; y = texture_h*textureY + newProjectorParams.viewportXywh[1];
y = texture_wh*textureY - viewportTextureOffset[1] + newProjectorPar
ams.viewportXywh[1];
} }
void StelViewportDistorterFisheyeToSphericMirror::recalculateTexCoords(cons t QSizeF newMaxTexCoords) void StelViewportDistorterFisheyeToSphericMirror::recalculateTexCoords(cons t QSizeF newMaxTexCoords)
{ {
const float xMult = newMaxTexCoords.width() / maxTexCoords.width(); const float xMult = newMaxTexCoords.width() / maxTexCoords.width();
const float yMult = newMaxTexCoords.height() / maxTexCoords.height() ; const float yMult = newMaxTexCoords.height() / maxTexCoords.height() ;
vertexGrid->unlock(); vertexGrid->unlock();
const int length = vertexGrid->length(); const int length = vertexGrid->length();
Vertex vertex; Vertex vertex;
 End of changes. 12 change blocks. 
26 lines changed or deleted 69 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/