Commit 16269a8d authored by Amaury Johnen's avatar Amaury Johnen

change translation of the model so that view is stay fixed when selecting rotation center

parent 5063b1b6
......@@ -58,7 +58,7 @@ static void lassoZoom(drawContext *ctx, mousePosition &click1, mousePosition &cl
tmp.wnr[1] = 0.5 * (click1.wnr[1] + click2.wnr[1]);
tmp.recenter(ctx);
ctx->initPosition();
ctx->initPosition(false);
drawContext::global()->draw();
FlGui::instance()->manip->update();
}
......
......@@ -232,6 +232,20 @@ static void general_options_rotation_center_select_cb(Fl_Widget *w, void *data)
opt_general_rotation_center0(0, GMSH_SET|GMSH_GUI, pc.x());
opt_general_rotation_center1(0, GMSH_SET|GMSH_GUI, pc.y());
opt_general_rotation_center2(0, GMSH_SET|GMSH_GUI, pc.z());
// Recompute model translation so that the view is not changed:
double vp[3];
drawContext *ctx = FlGui::instance()->getCurrentOpenglWindow()->getDrawContext();
gluProject(pc.x(), pc.y(), pc.z(), ctx->model, ctx->proj, ctx->viewport, &vp[0], &vp[1], &vp[2]);
double wnr[3]; // look at mousePosition::recenter()
wnr[0] =
(ctx->vxmin + vp[0] / (double)ctx->viewport[2] * (ctx->vxmax - ctx->vxmin))
/ ctx->s[0] - ctx->t[0] + ctx->t_init[0] / ctx->s[0];
wnr[1] =
(ctx->vymin + vp[1] / (double)ctx->viewport[3] * (ctx->vymax - ctx->vymin))
/ ctx->s[1] - ctx->t[1] + ctx->t_init[1] / ctx->s[1];
ctx->t[0] += wnr[0] - CTX::instance()->rotationCenter[0];
ctx->t[1] += wnr[1] - CTX::instance()->rotationCenter[1];
}
CTX::instance()->pickElements = 0;
CTX::instance()->mesh.changed = ENT_ALL;
......
......@@ -300,7 +300,7 @@ void drawContext::draw3d()
initProjection();
initRenderModel();
if(!CTX::instance()->camera) initPosition();
if(!CTX::instance()->camera) initPosition(true);
drawAxes();
drawGeom();
drawBackgroundImage(true);
......@@ -560,10 +560,10 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick)
// Put the origin of World coordinates at center of viewport
// (this is necessary for the scaling to be applied at center of viewport)
vxmin -= CTX::instance()->cg[0];
vxmax -= CTX::instance()->cg[0];
vymin -= CTX::instance()->cg[1];
vymax -= CTX::instance()->cg[1];
// vxmin -= CTX::instance()->cg[0];
// vxmax -= CTX::instance()->cg[0];
// vymin -= CTX::instance()->cg[1];
// vymax -= CTX::instance()->cg[1];
// store what one pixel represents in world coordinates
pixel_equiv_x = (vxmax - vxmin) / (viewport[2] - viewport[0]);
......@@ -749,13 +749,16 @@ void drawContext::initRenderModel()
glDisable(GL_LIGHTING);
}
void drawContext::initPosition()
void drawContext::initPosition(bool saveMatrices)
{
// FIXME: Regarder ici
// Those operations are applied at the model in the view coordinates
// in opposite order
glScaled(s[0], s[1], s[2]);
// glTranslated(t[0], t[1], t[2]);
glTranslated(t[0]-CTX::instance()->cg[0],
t[1]-CTX::instance()->cg[1],
t[2]-CTX::instance()->cg[2]);
glTranslated(t[0], t[1], t[2]);
// glTranslated(t[0]-CTX::instance()->cg[0],
// t[1]-CTX::instance()->cg[1],
// t[2]-CTX::instance()->cg[2]);
if(CTX::instance()->rotationCenterCg)
glTranslated(CTX::instance()->cg[0],
CTX::instance()->cg[1],
......@@ -780,8 +783,10 @@ void drawContext::initPosition()
// store the projection and modelview matrices at this precise moment (so that
// we can use them at any later time, even if the context has changed, i.e.,
// even if we are out of draw())
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetDoublev(GL_MODELVIEW_MATRIX, model);
if (saveMatrices) {
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetDoublev(GL_MODELVIEW_MATRIX, model);
}
for(int i = 0; i < 6; i++)
glClipPlane((GLenum)(GL_CLIP_PLANE0 + i), CTX::instance()->clipPlane[i]);
......@@ -916,7 +921,7 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post,
// 3d stuff
initProjection(x, y, w, h);
initPosition();
initPosition(false);
drawGeom();
if(mesh) drawMesh();
if(post) drawPost();
......
......@@ -202,7 +202,7 @@ class drawContext {
void setEulerAnglesFromRotationMatrix();
void initProjection(int xpick=0, int ypick=0, int wpick=0, int hpick=0);
void initRenderModel();
void initPosition();
void initPosition(bool saveMatrices);
void unproject(double winx, double winy, double p[3], double d[3]);
void viewport2World(double vp[3], double xyz[3]);
void world2Viewport(double xyz[3], double vp[3]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment