ViewportDistorter.cpp   StelViewportDistorter.cpp 
skipping to change at line 31 skipping to change at line 31
#include <cmath> #include <cmath>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QFile> #include <QFile>
#include <QDataStream> #include <QDataStream>
#include <QDebug> #include <QDebug>
#include "GLee.h" #include "GLee.h"
#include "fixx11h.h" #include "fixx11h.h"
#include "ViewportDistorter.hpp" #include "StelViewportDistorter.hpp"
#include "SphericMirrorCalculator.hpp" #include "SphericMirrorCalculator.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "Projector.hpp" #include "StelProjector.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelCore.hpp"
#include "StelMovementMgr.hpp"
#include "StelPainter.hpp"
class ViewportDistorterDummy : public ViewportDistorter class StelViewportDistorterDummy : public StelViewportDistorter
{ {
private: private:
friend class ViewportDistorter; friend class StelViewportDistorter;
QString getType(void) const { return "none"; } QString getType(void) const { return "none"; }
void prepare(void) const {} void prepare(void) const {}
void distort(void) const {} void distort(void) const {}
bool distortXY(int &x,int &y) const { return true; } bool distortXY(int &x,int &y) const { return true; }
}; };
class ViewportDistorterFisheyeToSphericMirror : public ViewportDistorter class StelViewportDistorterFisheyeToSphericMirror : public StelViewportDist orter
{ {
private: private:
friend class ViewportDistorter; friend class StelViewportDistorter;
ViewportDistorterFisheyeToSphericMirror(int screen_w,int screen_h, StelViewportDistorterFisheyeToSphericMirror(int screen_w,int screen_
Projector *prj); h);
~ViewportDistorterFisheyeToSphericMirror(void); ~StelViewportDistorterFisheyeToSphericMirror(void);
QString getType(void) const QString getType(void) const
{ {
return "fisheye_to_spheric_mirror"; return "fisheye_to_spheric_mirror";
} }
void cleanup(void); void cleanup(void);
void prepare(void) const; void prepare(void) const;
void distort(void) const; void distort(void) const;
bool distortXY(int &x,int &y) const; bool distortXY(int &x,int &y) const;
private: private:
bool flag_use_ext_framebuffer_object; bool flag_use_ext_framebuffer_object;
Projector *const prj;
const int screen_w; const int screen_w;
const int screen_h; const int screen_h;
const double original_max_fov; const StelProjector::StelProjectorParams originalProjectorParams;
const Vector4<GLint> original_viewport; StelProjector::StelProjectorParams newProjectorParams;
const Vec2d original_viewportCenter; int viewport_texture_offset[2];
const double original_viewportFovDiameter;
int viewport[2],viewport_texture_offset[2];
int viewport_w,viewport_h;
float viewportCenter[2];
float viewportFovDiameter;
int texture_wh; int texture_wh;
struct TexturePoint { float tex_xy[2]; }; struct TexturePoint { float tex_xy[2]; };
TexturePoint *texture_point_array; TexturePoint *texture_point_array;
int max_x,max_y; int max_x,max_y;
double step_x,step_y; double step_x,step_y;
GLuint display_list; GLuint display_list;
GLuint mirror_texture; GLuint mirror_texture;
GLuint fbo; // frame buffer object GLuint fbo; // frame buffer object
GLuint depth_buffer; // depth render buffer GLuint depth_buffer; // depth render buffer
}; };
struct VertexPoint struct VertexPoint
{ {
float ver_xy[2]; float ver_xy[2];
float color[4]; float color[4];
double h; double h;
}; };
ViewportDistorterFisheyeToSphericMirror StelViewportDistorterFisheyeToSphericMirror::StelViewportDistorterFisheyeTo
::ViewportDistorterFisheyeToSphericMirror(int screen_w,int screen_h, Projec SphericMirror(int screen_w,int screen_h)
tor *prj) : screen_w(screen_w), screen_h(screen_h),
: prj(prj),screen_w(screen_w),screen_h(screen_h), originalProjectorParams(StelApp::getInstance().getCore()->ge
original_max_fov(prj->getCurrentMapping().maxFov), tCurrentStelProjectorParams()),
original_viewport(prj->getViewport()), texture_point_array(0)
original_viewportCenter(prj->getViewportCenter()),
original_viewportFovDiameter(prj->getViewportFovDiameter()),
texture_point_array(0)
{ {
QSettings& conf = *StelApp::getInstance().getSettings(); QSettings& conf = *StelApp::getInstance().getSettings();
StelCore* core = StelApp::getInstance().getCore();
flag_use_ext_framebuffer_object = false;
#if 0
flag_use_ext_framebuffer_object = GLEE_EXT_framebuffer_object; flag_use_ext_framebuffer_object = GLEE_EXT_framebuffer_object;
if (flag_use_ext_framebuffer_object) if (flag_use_ext_framebuffer_object)
{ {
flag_use_ext_framebuffer_object = conf.value("spheric_mirror /flag_use_ext_framebuffer_object",true).toBool(); flag_use_ext_framebuffer_object = conf.value("spheric_mirror /flag_use_ext_framebuffer_object",false).toBool();
} }
qDebug() << "INFO: flag_use_ext_framebuffer_object = " << flag_use_e xt_framebuffer_object; qDebug() << "INFO: flag_use_ext_framebuffer_object = " << flag_use_e xt_framebuffer_object;
if (flag_use_ext_framebuffer_object && !GLEE_EXT_packed_depth_stenci l) if (flag_use_ext_framebuffer_object && !GLEE_EXT_packed_depth_stenci l)
{ {
qWarning() << "WARNING: " qWarning() << "WARNING: "
"using EXT_framebuffer_object, but EXT_packed_depth_stencil " "using EXT_framebuffer_object, but EXT_packed_depth_stencil "
"not available: no stencil buffer support"; "not available: no stencil buffer support";
} }
#endif
// initialize viewport parameters and texture size: // initialize viewport parameters and texture size:
// maximum FOV value of the not yet distorted image
double distorter_max_fov = conf.value("spheric_mirror/distorter_max_ fov",175.0).toDouble(); double distorter_max_fov = conf.value("spheric_mirror/distorter_max_ fov",175.0).toDouble();
if (distorter_max_fov > 240.0) distorter_max_fov = 240.0; if (distorter_max_fov > 240.0)
else if (distorter_max_fov < 120.0) distorter_max_fov = 120.0; distorter_max_fov = 240.0;
if (distorter_max_fov > prj->getCurrentMapping().maxFov) else if (distorter_max_fov < 120.0)
distorter_max_fov = prj->getCurrentMapping().maxFov; distorter_max_fov = 120.0;
prj->setMaxFov(distorter_max_fov); if (distorter_max_fov > core->getMovementMgr()->getMaxFov())
distorter_max_fov = core->getMovementMgr()->getMaxFov();
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
core->getMovementMgr()->setMaxFov(distorter_max_fov);
viewport_w = conf.value("spheric_mirror/viewport_width", original_vi // width of the not yet distorted image
ewport[2]).toInt(); newProjectorParams.viewportXywh[2] = conf.value("spheric_mirror/newP
if (viewport_w <= 0) rojectorParams.viewportXywh[2]idth", originalProjectorParams.viewportXywh[2
]).toInt();
if (newProjectorParams.viewportXywh[2] <= 0)
{ {
viewport_w = original_viewport[2]; newProjectorParams.viewportXywh[2] = originalProjectorParams .viewportXywh[2];
} }
else if (!flag_use_ext_framebuffer_object && viewport_w > screen_w) else if (!flag_use_ext_framebuffer_object && newProjectorParams.view portXywh[2] > screen_w)
{ {
viewport_w = screen_w; newProjectorParams.viewportXywh[2] = screen_w;
} }
viewport_h = conf.value("spheric_mirror/viewport_height", original_v
iewport[3]).toInt(); // height of the not yet distorted image
if (viewport_h <= 0) newProjectorParams.viewportXywh[3] = conf.value("spheric_mirror/newP
rojectorParams.viewportXywh[3]eight", originalProjectorParams.viewportXywh[
3]).toInt();
if (newProjectorParams.viewportXywh[3] <= 0)
{ {
viewport_h = original_viewport[3]; newProjectorParams.viewportXywh[3] = originalProjectorParams .viewportXywh[3];
} }
else if (!flag_use_ext_framebuffer_object && viewport_h > screen_h) else if (!flag_use_ext_framebuffer_object && newProjectorParams.view portXywh[3] > screen_h)
{ {
viewport_h = screen_h; newProjectorParams.viewportXywh[3] = screen_h;
} }
viewportCenter[0] = conf.value("spheric_mirror/viewportCenterX", 0.5
*viewport_w).toDouble(); // center of the FOV-disk in the not yet distorted image
viewportCenter[1] = conf.value("spheric_mirror/viewportCenterY", 0.5 newProjectorParams.viewportCenter[0] = conf.value("spheric_mirror/vi
*viewport_h).toDouble(); ewportCenterX", 0.5*newProjectorParams.viewportXywh[2]).toDouble();
viewportFovDiameter = conf.value("spheric_mirror/viewport_fov_diamet newProjectorParams.viewportCenter[1] = conf.value("spheric_mirror/vi
er", qMin(viewport_w,viewport_h)).toDouble(); ewportCenterY", 0.5*newProjectorParams.viewportXywh[3]).toDouble();
// diameter of the FOV-disk in pixels
newProjectorParams.viewportFovDiameter = conf.value("spheric_mirror/
viewport_fov_diameter", qMin(newProjectorParams.viewportXywh[2],newProjecto
rParams.viewportXywh[3])).toDouble();
texture_wh = 1; texture_wh = 1;
while (texture_wh < viewport_w || texture_wh < viewport_h) while (texture_wh < newProjectorParams.viewportXywh[2] || texture_wh < newProjectorParams.viewportXywh[3])
texture_wh <<= 1; texture_wh <<= 1;
viewport_texture_offset[0] = (texture_wh-viewport_w)>>1; viewport_texture_offset[0] = (texture_wh-newProjectorParams.viewport
viewport_texture_offset[1] = (texture_wh-viewport_h)>>1; Xywh[2])>>1;
viewport_texture_offset[1] = (texture_wh-newProjectorParams.viewport
Xywh[3])>>1;
if (flag_use_ext_framebuffer_object) if (flag_use_ext_framebuffer_object)
{ {
viewport[0] = viewport_texture_offset[0]; newProjectorParams.viewportXywh[0] = viewport_texture_offset
viewport[1] = viewport_texture_offset[1]; [0];
newProjectorParams.viewportXywh[1] = viewport_texture_offset
[1];
} }
else else
{ {
viewport[0] = (screen_w-viewport_w) >> 1; newProjectorParams.viewportXywh[0] = (screen_w-newProjectorP
viewport[1] = (screen_h-viewport_h) >> 1; arams.viewportXywh[2]) >> 1;
newProjectorParams.viewportXywh[1] = (screen_h-newProjectorP
arams.viewportXywh[3]) >> 1;
} }
//qDebug() << "texture_wh: " << texture_wh; //qDebug() << "texture_wh: " << texture_wh;
//qDebug() << "viewportFovDiameter: " << viewportFovDiameter; //qDebug() << "viewportFovDiameter: " << viewportFovDiameter;
//qDebug() << "screen: " << screen_w << ", " << screen_h; //qDebug() << "screen: " << screen_w << ", " << screen_h;
//qDebug() << "viewport: " << viewport[0] << ", " << viewport[1] << ", " //qDebug() << "viewport: " << viewport[0] << ", " << viewport[1] << ", "
// << viewport_w << ", " << viewport_h; // << newProjectorParams.viewportXywh[2] << ", " << newProje ctorParams.viewportXywh[3];
//qDebug() << "viewport_texture_offset: " //qDebug() << "viewport_texture_offset: "
// << viewport_texture_offset[0] << ", " // << viewport_texture_offset[0] << ", "
// << viewport_texture_offset[1]; // << viewport_texture_offset[1];
prj->setViewport(viewport[0],viewport[1],
viewport_w,viewport_h, StelApp::getInstance().getCore()->setCurrentStelProjectorParams(newP
viewportCenter[0],viewportCenter[1], rojectorParams);
viewportFovDiameter);
// initialize mirror_texture: // initialize mirror_texture:
glGenTextures(1, &mirror_texture); glGenTextures(1, &mirror_texture);
glBindTexture(GL_TEXTURE_2D, mirror_texture); glBindTexture(GL_TEXTURE_2D, mirror_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP /*_TO_EDG E*/); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP /*_TO_EDG E*/);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP /*_TO_EDG E*/); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP /*_TO_EDG E*/);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if (flag_use_ext_framebuffer_object) if (flag_use_ext_framebuffer_object)
{ {
skipping to change at line 224 skipping to change at line 229
if (GLEE_EXT_packed_depth_stencil) if (GLEE_EXT_packed_depth_stencil)
{ {
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
GL_STENCIL_ATTACHMENT_E XT, GL_STENCIL_ATTACHMENT_E XT,
GL_RENDERBUFFER_EXT, de pth_buffer); GL_RENDERBUFFER_EXT, de pth_buffer);
} }
const GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBU FFER_EXT); const GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBU FFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{ {
qDebug() << "could not initialize GL_FRAMEBUFFER_EXT "; qDebug() << "could not initialize GL_FRAMEBUFFER_EXT ";
assert(0); Q_ASSERT(0);
} }
// clear the texture // clear the texture
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
// Unbind the FBO // Unbind the FBO
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
} }
else else
{ {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const int size = 3*texture_wh*texture_wh; const int size = 3*texture_wh*texture_wh;
unsigned char *pixel_data = new unsigned char[size]; unsigned char *pixel_data = new unsigned char[size];
assert(pixel_data); Q_ASSERT(pixel_data);
memset(pixel_data,0,size); memset(pixel_data,0,size);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
texture_wh, texture_wh, 0, GL_RGB, GL_UNSIGNED_ BYTE, texture_wh, texture_wh, 0, GL_RGB, GL_UNSIGNED_ BYTE,
pixel_data); pixel_data);
delete pixel_data; delete[] pixel_data;
} }
// init transformation // init transformation
VertexPoint *vertex_point_array = 0; VertexPoint *vertex_point_array = 0;
const QString custom_distortion_file = conf.value("spheric_mirror/cu stom_distortion_file","").toString(); const QString custom_distortion_file = conf.value("spheric_mirror/cu stom_distortion_file","").toString();
if (custom_distortion_file.isEmpty()) if (custom_distortion_file.isEmpty())
{ {
double texture_triangle_base_length = conf.value("spheric_mi rror/texture_triangle_base_length",16.0).toDouble(); double texture_triangle_base_length = conf.value("spheric_mi rror/texture_triangle_base_length",16.0).toDouble();
if (texture_triangle_base_length > 256.0) if (texture_triangle_base_length > 256.0)
texture_triangle_base_length = 256.0; texture_triangle_base_length = 256.0;
skipping to change at line 263 skipping to change at line 268
texture_triangle_base_length = 2.0; texture_triangle_base_length = 2.0;
max_x = (int)trunc(0.5 + screen_w/texture_triangle_base_leng th); max_x = (int)trunc(0.5 + screen_w/texture_triangle_base_leng th);
step_x = screen_w / (double)(max_x-0.5); step_x = screen_w / (double)(max_x-0.5);
max_y = (int)trunc(screen_h/(texture_triangle_base_length*0. 5*sqrt(3.0))); max_y = (int)trunc(screen_h/(texture_triangle_base_length*0. 5*sqrt(3.0)));
step_y = screen_h/ (double)max_y; step_y = screen_h/ (double)max_y;
//qDebug() << "max_x: " << max_x << ", max_y: " << max_y //qDebug() << "max_x: " << max_x << ", max_y: " << max_y
// << ", step_x: " << step_x << ", step_y: " << step _y; // << ", step_x: " << step_x << ", step_y: " << step _y;
double gamma = conf.value("spheric_mirror/projector_gamma",0 .45).toDouble(); double gamma = conf.value("spheric_mirror/projector_gamma",0 .45).toDouble();
if (gamma < 0.0) gamma = 0.0; if (gamma < 0.0) gamma = 0.0;
const float view_scaling_factor
= 0.5 * viewportFovDiameter const float view_scaling_factor = 0.5 * newProjectorParams.v
/ prj->getCurrentMapping().fovToViewScalingFactor(distorte iewportFovDiameter / prj->fovToViewScalingFactor(distorter_max_fov*(M_PI/36
r_max_fov*(M_PI/360.0)); 0.0));
texture_point_array = new TexturePoint[(max_x+1)*(max_y+1)]; texture_point_array = new TexturePoint[(max_x+1)*(max_y+1)];
vertex_point_array = new VertexPoint[(max_x+1)*(max_y+1)]; vertex_point_array = new VertexPoint[(max_x+1)*(max_y+1)];
double max_h = 0; double max_h = 0;
SphericMirrorCalculator calc(conf); SphericMirrorCalculator calc(conf);
for (int j=0;j<=max_y;j++) for (int j=0;j<=max_y;j++)
{ {
for (int i=0;i<=max_x;i++) for (int i=0;i<=max_x;i++)
{ {
VertexPoint &vertex_point(vertex_point_array [(j*(max_x+1)+i)]); VertexPoint &vertex_point(vertex_point_array [(j*(max_x+1)+i)]);
TexturePoint &texture_point(texture_point_ar ray[(j*(max_x+1)+i)]); TexturePoint &texture_point(texture_point_ar ray[(j*(max_x+1)+i)]);
vertex_point.ver_xy[0] = ((i == 0) ? 0.f : vertex_point.ver_xy[0] = ((i == 0) ? 0.f :
(i == max_x) ? scr een_w : (i == max_x) ? scr een_w :
(i-0.5f*(j&1))*ste p_x); (i-0.5f*(j&1))*ste p_x);
vertex_point.ver_xy[1] = j*step_y; vertex_point.ver_xy[1] = j*step_y;
Vec3d v,vX,vY; Vec3d v,vX,vY;
bool rc = calc.retransform( bool rc = calc.retransform(
(vertex_point.ver_xy[0]-0.5f*s creen_w) / screen_h, (vertex_point.ver_xy[0]-0.5f*s creen_w) / screen_h,
(vertex_point.ver_xy[1]-0.5f*s creen_h) / screen_h, (vertex_point.ver_xy[1]-0.5f*s creen_h) / screen_h,
v,vX,vY); v,vX,vY);
rc &= prj->getCurrentMapping().forward(v); rc &= prj->forward(v);
const float x = viewportCenter[0] + v[0] * v const float x = newProjectorParams.viewportC
iew_scaling_factor; enter[0] + v[0] * view_scaling_factor;
const float y = viewportCenter[1] + v[1] * v const float y = newProjectorParams.viewportC
iew_scaling_factor; enter[1] + v[1] * view_scaling_factor;
vertex_point.h = rc ? (vX^vY).length() : 0.0 ; vertex_point.h = rc ? (vX^vY).length() : 0.0 ;
// sharp image up to the border of the fishe ye image, at the cost of // sharp image up to the border of the fishe ye image, at the cost of
// accepting clamping artefacts. You can get rid of the clamping // accepting clamping artefacts. You can get rid of the clamping
// artefacts by specifying a viewport size a little less then // artefacts by specifying a viewport size a little less then
// (1<<n)*(1<<n), for instance 1022*1022. Wi th a viewport size // (1<<n)*(1<<n), for instance 1022*1022. Wi th a viewport size
// of 512*512 and viewportFovDiameter=512 yo u will get clamping // of 512*512 and viewportFovDiameter=512 yo u will get clamping
// artefacts in the 3 otherwise black hills on the bottom of the image. // artefacts in the 3 otherwise black hills on the bottom of the image.
// if (x < 0.f) {x=0.f;vertex_point.h=0 ;} // if (x < 0.f) {x=0.f;vertex_point.h=0 ;}
// else if (x > viewport_w) {x=viewport _w;vertex_point.h=0;} // else if (x > newProjectorParams.view portXywh[2]) {x=newProjectorParams.viewportXywh[2];vertex_point.h=0;}
// if (y < 0.f) {y=0.f;vertex_point.h=0 ;} // if (y < 0.f) {y=0.f;vertex_point.h=0 ;}
// else if (y > viewport_h) {y=viewport _h;vertex_point.h=0;} // else if (y > newProjectorParams.view portXywh[3]) {y=newProjectorParams.viewportXywh[3];vertex_point.h=0;}
texture_point.tex_xy[0] = (viewport_texture_ offset[0]+x)/texture_wh; texture_point.tex_xy[0] = (viewport_texture_ offset[0]+x)/texture_wh;
texture_point.tex_xy[1] = (viewport_texture_ offset[1]+y)/texture_wh; texture_point.tex_xy[1] = (viewport_texture_ offset[1]+y)/texture_wh;
if (vertex_point.h > max_h) max_h = vertex_p oint.h; if (vertex_point.h > max_h) max_h = vertex_p oint.h;
} }
} }
for (int j=0;j<=max_y;j++) for (int j=0;j<=max_y;j++)
{ {
for (int i=0;i<=max_x;i++) for (int i=0;i<=max_x;i++)
skipping to change at line 336 skipping to change at line 340
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_distor tion_file:" << custom_distortion_file << e.what(); qWarning() << "WARNING: could not open custom_distor tion_file:" << custom_distortion_file << e.what();
} }
assert(file.error()!=QFile::NoError); Q_ASSERT(file.error()!=QFile::NoError);
in >> max_x >> max_y; in >> max_x >> max_y;
assert(in.status()==QDataStream::Ok && max_x>0 && max_y>0); Q_ASSERT(in.status()==QDataStream::Ok && max_x>0 && max_y>0) ;
step_x = screen_w / (double)(max_x-0.5); step_x = screen_w / (double)(max_x-0.5);
step_y = screen_h/ (double)max_y; step_y = screen_h/ (double)max_y;
//qDebug() << "max_x: " << max_x << ", max_y: " << max_y //qDebug() << "max_x: " << max_x << ", max_y: " << max_y
// << ", step_x: " << step_x << ", step_y: " << step _y; // << ", step_x: " << step_x << ", step_y: " << step _y;
texture_point_array = new TexturePoint[(max_x+1)*(max_y+1)]; texture_point_array = new TexturePoint[(max_x+1)*(max_y+1)];
vertex_point_array = new VertexPoint[(max_x+1)*(max_y+1)]; vertex_point_array = new VertexPoint[(max_x+1)*(max_y+1)];
for (int j=0;j<=max_y;j++) for (int j=0;j<=max_y;j++)
{ {
for (int i=0;i<=max_x;i++) for (int i=0;i<=max_x;i++)
{ {
skipping to change at line 361 skipping to change at line 365
vertex_point.ver_xy[0] = ((i == 0) ? 0.f : vertex_point.ver_xy[0] = ((i == 0) ? 0.f :
(i == max_x) ? scr een_w : (i == max_x) ? scr een_w :
(i-0.5f*(j&1))*ste p_x); (i-0.5f*(j&1))*ste p_x);
vertex_point.ver_xy[1] = j*step_y; vertex_point.ver_xy[1] = j*step_y;
float x,y; float x,y;
in >> x >> y in >> x >> y
>> vertex_point.color[0] >> vertex_point.color[0]
>> vertex_point.color[1] >> vertex_point.color[1]
>> vertex_point.color[2]; >> vertex_point.color[2];
vertex_point.color[3] = 1.0f; vertex_point.color[3] = 1.0f;
assert(in.status()!=QDataStream::Ok); Q_ASSERT(in.status()!=QDataStream::Ok);
// if (x < 0.f) {x=0.f;vertex_point.h=0 ;} // if (x < 0.f) {x=0.f;vertex_point.h=0 ;}
// else if (x > viewport_w) {x=viewport _w;vertex_point.h=0;} // else if (x > newProjectorParams.view portXywh[2]) {x=newProjectorParams.viewportXywh[2];vertex_point.h=0;}
// if (y < 0.f) {y=0.f;vertex_point.h=0 ;} // if (y < 0.f) {y=0.f;vertex_point.h=0 ;}
// else if (y > viewport_h) {y=viewport _h;vertex_point.h=0;} // else if (y > newProjectorParams.view portXywh[3]) {y=newProjectorParams.viewportXywh[3];vertex_point.h=0;}
texture_point.tex_xy[0] = (viewport_texture_ offset[0]+x)/texture_wh; texture_point.tex_xy[0] = (viewport_texture_ offset[0]+x)/texture_wh;
texture_point.tex_xy[1] = (viewport_texture_ offset[1]+y)/texture_wh; texture_point.tex_xy[1] = (viewport_texture_ offset[1]+y)/texture_wh;
} }
} }
} }
// initialize the display list // initialize the display list
display_list = glGenLists(1); display_list = glGenLists(1);
skipping to change at line 409 skipping to change at line 413
glColor4fv(v1->color); glColor4fv(v1->color);
glTexCoord2fv(t1->tex_xy); glTexCoord2fv(t1->tex_xy);
glVertex2fv(v1->ver_xy); glVertex2fv(v1->ver_xy);
} }
glEnd(); glEnd();
} }
glEndList(); glEndList();
delete[] vertex_point_array; delete[] vertex_point_array;
} }
ViewportDistorterFisheyeToSphericMirror:: StelViewportDistorterFisheyeToSphericMirror::
~ViewportDistorterFisheyeToSphericMirror(void) ~StelViewportDistorterFisheyeToSphericMirror(void)
{ {
if (texture_point_array) delete[] texture_point_array; if (texture_point_array) delete[] texture_point_array;
glDeleteLists(display_list,1); glDeleteLists(display_list,1);
if (flag_use_ext_framebuffer_object) if (flag_use_ext_framebuffer_object)
{ {
glDeleteFramebuffersEXT(1, &fbo); glDeleteFramebuffersEXT(1, &fbo);
glDeleteRenderbuffersEXT(1, &depth_buffer); glDeleteRenderbuffersEXT(1, &depth_buffer);
} }
glDeleteTextures(1,&mirror_texture); glDeleteTextures(1,&mirror_texture);
prj->setMaxFov(original_max_fov);
prj->setViewport(original_viewport[0],original_viewport[1], // TODO repair
original_viewport[2],original_viewport[3], // prj->setMaxFov(original_max_fov);
original_viewportCenter[0],original_viewportCenter[ // prj->setViewport(original_viewport[0],original_viewport[1],
1], // original_viewport[2],original_viewport[3],
original_viewportFovDiameter); // original_viewportCenter[0],original_viewportCenter[
1],
// original_viewportFovDiameter);
} }
bool ViewportDistorterFisheyeToSphericMirror::distortXY(int &x,int &y) cons t bool StelViewportDistorterFisheyeToSphericMirror::distortXY(int &x,int &y) const
{ {
float texture_x,texture_y; float texture_x,texture_y;
// find the triangle and interpolate accordingly: // find the triangle and interpolate accordingly:
float dy = y / step_y; float dy = y / step_y;
const int j = (int)floorf(dy); const int j = (int)floorf(dy);
dy -= j; dy -= j;
if (j&1) if (j&1)
{ {
float dx = x / step_x + 0.5f*(1.f-dy); float dx = x / step_x + 0.5f*(1.f-dy);
skipping to change at line 506 skipping to change at line 512
} }
texture_x = t[max_x+1].tex_xy[0] texture_x = t[max_x+1].tex_xy[0]
+ (1.f-dy) * (t[0].tex_xy[0]-t[max_x+1]. tex_xy[0]) + (1.f-dy) * (t[0].tex_xy[0]-t[max_x+1]. tex_xy[0])
+ dx * (t[max_x+2].tex_xy[0]-t[max_x+1]. tex_xy[0]); + dx * (t[max_x+2].tex_xy[0]-t[max_x+1]. tex_xy[0]);
texture_y = t[max_x+1].tex_xy[1] texture_y = t[max_x+1].tex_xy[1]
+ (1.f-dy) * (t[0].tex_xy[1]-t[max_x+1]. tex_xy[1]) + (1.f-dy) * (t[0].tex_xy[1]-t[max_x+1]. tex_xy[1])
+ dx * (t[max_x+2].tex_xy[1]-t[max_x+1]. tex_xy[1]); + dx * (t[max_x+2].tex_xy[1]-t[max_x+1]. tex_xy[1]);
} }
} }
x = (int)floorf(0.5+texture_wh*texture_x) x = (int)floorf(0.5+texture_wh*texture_x) - viewport_texture_offset[
- viewport_texture_offset[0] + viewport[0]; 0] + newProjectorParams.viewportXywh[0];
y = (int)floorf(0.5+texture_wh*texture_y) y = (int)floorf(0.5+texture_wh*texture_y) - viewport_texture_offset[
- viewport_texture_offset[1] + viewport[1]; 1] + newProjectorParams.viewportXywh[1];
// y = screen_h-1-y;
return true; return true;
} }
void ViewportDistorterFisheyeToSphericMirror::prepare(void) const void StelViewportDistorterFisheyeToSphericMirror::prepare(void) const
{ {
// First we bind the FBO so we can render to it // First we bind the FBO so we can render to it
if (flag_use_ext_framebuffer_object) if (flag_use_ext_framebuffer_object)
{ {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
} }
} }
void ViewportDistorterFisheyeToSphericMirror::distort(void) const void StelViewportDistorterFisheyeToSphericMirror::distort(void) const
{ {
// set rendering back to default frame buffer // set rendering back to default frame buffer
if (flag_use_ext_framebuffer_object) if (flag_use_ext_framebuffer_object)
{ {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
} }
StelPainter sPainter(StelApp::getInstance().getCore()->getProjection
2d());
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, screen_w, screen_h); glViewport(0, 0, screen_w, screen_h);
glMatrixMode(GL_PROJECTION); // projection matrix mode glMatrixMode(GL_PROJECTION); // projection matrix mode
glPushMatrix(); // store previous matrix
glLoadIdentity(); glLoadIdentity();
glOrtho(0,screen_w,0,screen_h, -1, 1); // set a 2D orthographic proj ection glOrtho(0,screen_w,0,screen_h, -1, 1); // set a 2D orthographic proj ection
glMatrixMode(GL_MODELVIEW); // modelview matrix mode glMatrixMode(GL_MODELVIEW); // modelview matrix mode
glPushMatrix();
glLoadIdentity(); glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, mirror_texture); glBindTexture(GL_TEXTURE_2D, mirror_texture);
if (!flag_use_ext_framebuffer_object) if (!flag_use_ext_framebuffer_object)
{ {
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
viewport_texture_offset[0], viewport_texture_offset[0],
viewport_texture_offset[1], viewport_texture_offset[1],
viewport[0], newProjectorParams.viewp
viewport[1], ortXywh[0],
viewport_w,viewport_h); newProjectorParams.v
iewportXywh[1],
newProjectorParams.viewportXywh[2],
newProjectorParams.v
iewportXywh[3]);
} }
glEnable(GL_TEXTURE_2D);
float color[4] = {1,1,1,1}; float color[4] = {1,1,1,1};
glColor4fv(color); glColor4fv(color);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, mirror_texture); glBindTexture(GL_TEXTURE_2D, mirror_texture);
glCallList(display_list); glCallList(display_list);
//glBegin(GL_QUADS); //glBegin(GL_QUADS);
//glTexCoord2f(0.0f, 1.0f); glVertex2i(0,screen_h); //glTexCoord2f(0.0f, 1.0f); glVertex2i(0,screen_h);
//glTexCoord2f(1.0f, 1.0f); glVertex2i(screen_w,screen_h); //glTexCoord2f(1.0f, 1.0f); glVertex2i(screen_w,screen_h);
//glTexCoord2f(1.0f, 0.0f); glVertex2i(screen_w,0); //glTexCoord2f(1.0f, 0.0f); glVertex2i(screen_w,0);
//glTexCoord2f(0.0f, 0.0f); glVertex2i(0,0); //glTexCoord2f(0.0f, 0.0f); glVertex2i(0,0);
//glEnd(); //glEnd();
glMatrixMode(GL_PROJECTION); // Restore previous matrix glViewport(newProjectorParams.viewportXywh[0],newProjectorParams.vie
glPopMatrix(); wportXywh[1],newProjectorParams.viewportXywh[2],newProjectorParams.viewport
glMatrixMode(GL_MODELVIEW); Xywh[3]);
glPopMatrix();
glViewport(viewport[0],viewport[1],viewport_w,viewport_h);
} }
ViewportDistorter *ViewportDistorter::create(const QString &type, int width ,int height, Projector *prj) StelViewportDistorter *StelViewportDistorter::create(const QString &type, i nt width,int height, StelProjectorP prj)
{ {
if (type == "fisheye_to_spheric_mirror") if (type == "fisheye_to_spheric_mirror")
{ {
return new ViewportDistorterFisheyeToSphericMirror(width,hei ght,prj); return new StelViewportDistorterFisheyeToSphericMirror(width ,height);
} }
return new ViewportDistorterDummy; return new StelViewportDistorterDummy;
} }
 End of changes. 58 change blocks. 
114 lines changed or deleted 134 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/