Commit 1c9461f1 authored by Christophe Geuzaine's avatar Christophe Geuzaine

Merge branch 'guiRotCenter' into 'master'

put origin world coordinate at center viewport + make sure model does not move when changing rotation center See merge request !165
parents eeb564c8 c670a555
Pipeline #2079 passed with stage
in 122 minutes 26 seconds
......@@ -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();
}
......
......@@ -24,6 +24,7 @@ typedef unsigned long intptr_t;
#include "graphicWindow.h"
#include "openglWindow.h"
#include "paletteWindow.h"
#include "manipWindow.h"
#include "extraDialogs.h"
#include "drawContext.h"
#include "Options.h"
......@@ -232,6 +233,11 @@ 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());
drawContext *ctx =
FlGui::instance()->getCurrentOpenglWindow()->getDrawContext();
ctx->recenterForRotationCenterChange(pc);
FlGui::instance()->manip->update();
}
CTX::instance()->pickElements = 0;
CTX::instance()->mesh.changed = ENT_ALL;
......@@ -257,11 +263,25 @@ static void general_options_ok_cb(Fl_Widget *w, void *data)
const char *name = (const char*)data;
if(!strcmp(name, "rotation_center_coord")){
CTX::instance()->drawRotationCenter = 1;
SPoint3 p(o->general.value[8]->value(),
o->general.value[9]->value(),
o->general.value[10]->value());
drawContext *ctx =
FlGui::instance()->getCurrentOpenglWindow()->getDrawContext();
ctx->recenterForRotationCenterChange(p);
FlGui::instance()->manip->update();
}
else if(!strcmp(name, "rotation_center")){
// pre-fill with cg
for(int i = 0; i < 3; i++)
o->general.value[8 + i]->value(CTX::instance()->cg[i]);
SPoint3 p(CTX::instance()->cg[0],
CTX::instance()->cg[1],
CTX::instance()->cg[2]);
drawContext *ctx =
FlGui::instance()->getCurrentOpenglWindow()->getDrawContext();
ctx->recenterForRotationCenterChange(p);
FlGui::instance()->manip->update();
}
else if(!strcmp(name, "light_value")){
double x, y, z;
......
......@@ -300,7 +300,7 @@ void drawContext::draw3d()
initProjection();
initRenderModel();
if(!CTX::instance()->camera) initPosition();
if(!CTX::instance()->camera) initPosition(true);
drawAxes();
drawGeom();
drawBackgroundImage(true);
......@@ -558,6 +558,14 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick)
vymin -= yborder;
vymax += yborder;
// Put the origin of World coordinates at center of viewport
// (this is necessary for the scaling to be applied at center of viewport
// instead of at initial position of center of gravity)
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]);
pixel_equiv_y = (vymax - vymin) / (viewport[3] - viewport[1]);
......@@ -742,10 +750,14 @@ void drawContext::initRenderModel()
glDisable(GL_LIGHTING);
}
void drawContext::initPosition()
void drawContext::initPosition(bool saveMatrices)
{
// NB: Those operations are applied to 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]);
if(CTX::instance()->rotationCenterCg)
glTranslated(CTX::instance()->cg[0],
CTX::instance()->cg[1],
......@@ -770,8 +782,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]);
......@@ -906,7 +920,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();
......@@ -1077,3 +1091,20 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post,
return true;
return false;
}
void drawContext::recenterForRotationCenterChange(SPoint3 newRotationCenter)
{
// Recompute model translation so that the view is not changed
SPoint3 &p = newRotationCenter;
double vp[3];
gluProject(p.x(), p.y(), p.z(), model, proj, viewport, &vp[0], &vp[1], &vp[2]);
double wnr[3]; // look at mousePosition::recenter()
const double &width = viewport[2];
const double &height = viewport[3];
wnr[0] = (vxmin + vp[0] / width * (vxmax - vxmin)) / s[0]
- t[0] + t_init[0] / s[0];
wnr[1] = (vymin + vp[1] / height * (vymax - vymin)) / s[1]
- t[1] + t_init[1] / s[1];
t[0] += wnr[0] + CTX::instance()->cg[0] - p.x();
t[1] += wnr[1] + CTX::instance()->cg[1] - p.y();
}
......@@ -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]);
......@@ -211,6 +211,7 @@ class drawContext {
std::vector<GFace*> &faces, std::vector<GRegion*> &regions,
std::vector<MElement*> &elements, std::vector<SPoint2> &points,
std::vector<PView*> &views);
void recenterForRotationCenterChange(SPoint3 newRotationCenter);
int fix2dCoordinates(double *x, double *y);
void draw3d();
void draw2d();
......
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