mirror of https://github.com/vitalif/openscad
Improved view distance
parent
38f50db0e0
commit
0340d4e0a1
|
@ -7,8 +7,10 @@
|
|||
#define FAR_FAR_AWAY 100000.0
|
||||
|
||||
OffscreenView::OffscreenView(size_t width, size_t height)
|
||||
: orthomode(false), showaxes(true), showfaces(true), showedges(false), viewer_distance(500),
|
||||
object_rot_x(35), object_rot_y(0), object_rot_z(25)
|
||||
: orthomode(false), showaxes(true), showfaces(true), showedges(false),
|
||||
object_rot_x(35), object_rot_y(0), object_rot_z(25),
|
||||
camera_eye_x(0), camera_eye_y(0), camera_eye_z(0),
|
||||
camera_center_x(0), camera_center_y(0), camera_center_z(0)
|
||||
{
|
||||
for (int i = 0; i < 10; i++) this->shaderinfo[i] = 0;
|
||||
this->ctx = create_offscreen_context(width, height);
|
||||
|
@ -158,27 +160,27 @@ void OffscreenView::setupPerspective()
|
|||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY);
|
||||
gluPerspective(90, w_h_ratio, 0.1*(this->camera_center_y - this->camera_eye_y),
|
||||
3*(this->camera_center_y - this->camera_eye_y));
|
||||
}
|
||||
|
||||
void OffscreenView::setupOrtho(double distance, bool offset)
|
||||
void OffscreenView::setupOrtho(bool offset)
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
if(offset)
|
||||
glTranslated(-0.8, -0.8, 0);
|
||||
double l = distance/10;
|
||||
if (offset) glTranslated(-0.8, -0.8, 0);
|
||||
double l = (this->camera_eye_y - this->camera_center_y)/10;
|
||||
glOrtho(-w_h_ratio*l, +w_h_ratio*l,
|
||||
-(1/w_h_ratio)*l, +(1/w_h_ratio)*l,
|
||||
-FAR_FAR_AWAY, +FAR_FAR_AWAY);
|
||||
-(1/w_h_ratio)*l, +(1/w_h_ratio)*l,
|
||||
-FAR_FAR_AWAY, +FAR_FAR_AWAY);
|
||||
}
|
||||
|
||||
void OffscreenView::paintGL()
|
||||
{
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
if (orthomode)
|
||||
setupOrtho(viewer_distance);
|
||||
if (orthomode) setupOrtho();
|
||||
else setupPerspective();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
@ -187,9 +189,9 @@ void OffscreenView::paintGL()
|
|||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// glTranslated(object_trans_x, object_trans_y, object_trans_z);
|
||||
gluLookAt(this->camera_eye_x, this->camera_eye_y, this->camera_eye_z,
|
||||
this->camera_center_x, this->camera_center_y, this->camera_center_z,
|
||||
0.0, 0.0, 1.0);
|
||||
|
||||
glRotated(object_rot_x, 1.0, 0.0, 0.0);
|
||||
glRotated(object_rot_y, 0.0, 1.0, 0.0);
|
||||
|
@ -202,7 +204,7 @@ void OffscreenView::paintGL()
|
|||
glLineWidth(1);
|
||||
glColor3d(0.5, 0.5, 0.5);
|
||||
glBegin(GL_LINES);
|
||||
double l = viewer_distance/10;
|
||||
double l = 3*(this->camera_eye_y - this->camera_center_y);
|
||||
glVertex3d(-l, 0, 0);
|
||||
glVertex3d(+l, 0, 0);
|
||||
glVertex3d(0, -l, 0);
|
||||
|
@ -231,3 +233,15 @@ bool OffscreenView::save(const char *filename)
|
|||
{
|
||||
return save_framebuffer(this->ctx, filename);
|
||||
}
|
||||
|
||||
void OffscreenView::setCamera(double xpos, double ypos, double zpos,
|
||||
double xcenter, double ycenter, double zcenter)
|
||||
{
|
||||
this->camera_eye_x = xpos;
|
||||
this->camera_eye_y = ypos;
|
||||
this->camera_eye_z = zpos;
|
||||
this->camera_center_x = xcenter;
|
||||
this->camera_center_y = ycenter;
|
||||
this->camera_center_z = zcenter;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,12 @@ public:
|
|||
~OffscreenView();
|
||||
void setRenderer(class Renderer* r);
|
||||
|
||||
void setCamera(double xpos, double ypos, double zpos,
|
||||
double xcenter, double ycenter, double zcenter);
|
||||
void initializeGL();
|
||||
void resizeGL(int w, int h);
|
||||
void setupPerspective();
|
||||
void setupOrtho(double distance,bool offset=false);
|
||||
void setupOrtho(bool offset=false);
|
||||
void paintGL();
|
||||
bool save(const char *filename);
|
||||
|
||||
|
@ -26,12 +28,17 @@ private:
|
|||
double object_rot_x;
|
||||
double object_rot_y;
|
||||
double object_rot_z;
|
||||
double camera_eye_x;
|
||||
double camera_eye_y;
|
||||
double camera_eye_z;
|
||||
double camera_center_x;
|
||||
double camera_center_y;
|
||||
double camera_center_z;
|
||||
|
||||
bool orthomode;
|
||||
bool showaxes;
|
||||
bool showfaces;
|
||||
bool showedges;
|
||||
float viewer_distance;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -211,6 +211,12 @@ int main(int argc, char *argv[])
|
|||
QDir::setCurrent(original_path.absolutePath());
|
||||
|
||||
csgInfo.glview = new OffscreenView(512,512);
|
||||
BoundingBox bbox = csgInfo.root_chain->getBoundingBox();
|
||||
|
||||
Vector3d center = (bbox.min() + bbox.max()) / 2;
|
||||
double radius = (bbox.max() - bbox.min()).norm() / 2;
|
||||
csgInfo.glview->setCamera(center[0], center[1] - 2 * radius, center[2],
|
||||
center[0], center[1], center[2]);
|
||||
|
||||
glewInit();
|
||||
#ifdef DEBUG
|
||||
|
|
Loading…
Reference in New Issue