Commit 019f7781 authored by Amaury Johnen's avatar Amaury Johnen

make sure screen stay unchanged after any rotation center modification + origin…

make sure screen stay unchanged after any rotation center modification + origin of world coordinate at center of screen
parent 16269a8d
......@@ -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"
......@@ -233,19 +234,10 @@ static void general_options_rotation_center_select_cb(Fl_Widget *w, void *data)
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];
drawContext *ctx =
FlGui::instance()->getCurrentOpenglWindow()->getDrawContext();
ctx->recenterForRotationCenterChange(pc);
FlGui::instance()->manip->update();
}
CTX::instance()->pickElements = 0;
CTX::instance()->mesh.changed = ENT_ALL;
......@@ -271,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;
......
......@@ -559,11 +559,12 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick)
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)
// vxmin -= CTX::instance()->cg[0];
// vxmax -= CTX::instance()->cg[0];
// vymin -= CTX::instance()->cg[1];
// vymax -= CTX::instance()->cg[1];
// (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]);
......@@ -751,14 +752,12 @@ void drawContext::initRenderModel()
void drawContext::initPosition(bool saveMatrices)
{
// FIXME: Regarder ici
// Those operations are applied at the model in the view coordinates
// in opposite order
// 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]);
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],
......@@ -1092,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();
}
......@@ -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