Skip to content
Snippets Groups Projects
Commit ebeb96d4 authored by Gilles Marckmann's avatar Gilles Marckmann
Browse files

Completion of implementation of camera and stereo in FLTK. Stereo does

not work yet. Commented lines have been commit for CYAN/RED stereo but
this kind of stereo mode is not convincing.
parent eb889f79
No related branches found
No related tags found
No related merge requests found
......@@ -178,7 +178,9 @@ int meshSizeEditor()
if(editor->window->non_modal() && !editor->window->shown())
editor->window->show(); // fix ordering
editor->window->show();
return 0;
return 0;
return CTX::instance()->mesh.lcFactor;
}
// Model chooser
......
......@@ -11,6 +11,7 @@
int arrowEditor(const char *title, double &a, double &b, double &c);
int perspectiveEditor();
int meshSizeEditor();
int modelChooser();
std::string connectionChooser();
std::string patternChooser();
......
......@@ -20,8 +20,7 @@
static void lassoZoom(drawContext *ctx, mousePosition &click1, mousePosition &click2)
{
if(click1.win[0] == click2.win[0] || click1.win[1] == click2.win[1])
return;
if(click1.win[0] == click2.win[0] || click1.win[1] == click2.win[1]) return;
ctx->s[0] *= (double)ctx->viewport[2] / (click2.win[0] - click1.win[0]);
ctx->s[1] *= (double)ctx->viewport[3] / (click2.win[1] - click1.win[1]);
......@@ -36,6 +35,7 @@ static void lassoZoom(drawContext *ctx, mousePosition &click1, mousePosition &cl
ctx->initPosition();
drawContext::global()->draw();
FlGui::instance()->manip->update();
}
openglWindow::openglWindow(int x, int y, int w, int h, const char *l)
......@@ -198,9 +198,9 @@ void openglWindow::draw()
0.0F);
*/
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
if(CTX::instance()->camera){
Camera * cam= &(_ctx->camera);
Camera * cam= &(_ctx->camera);
if(CTX::instance()->camera && !CTX::instance()->stereo ){
if (!cam->on) cam->init();
cam->giveViewportDimension(_ctx->viewport[2],_ctx->viewport[3]);
glMatrixMode(GL_PROJECTION);
......@@ -214,11 +214,112 @@ void openglWindow::draw()
gluLookAt(cam->position.x,cam->position.y,cam->position.z,
cam->target.x,cam->target.y,cam->target.z,
cam->up.x,cam->up.y,cam->up.z);
_ctx->draw3d();
_ctx->draw2d();
_drawScreenMessage();
_drawBorder();
// glPushMatrix();
}
else if(CTX::instance()->stereo ){
if (!cam->on) cam->init();
cam->giveViewportDimension(_ctx->viewport[2],_ctx->viewport[3]);
// for RED/CYAN stereo pairs but not convincing
/*
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_ACCUM_BUFFER_BIT);
glColorMask(GL_FALSE,GL_TRUE,GL_TRUE,GL_TRUE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
XYZ eye =cam->eyesep / 2.0* cam->right;
double left = - cam->screenratio * cam->wd2 - 0.5 * cam->eyesep * cam->ndfl;
double right = cam->screenratio * cam->wd2 - 0.5 * cam->eyesep * cam->ndfl;
double top = cam->wd2;
double bottom = - cam->wd2;
glFrustum(left,right,bottom,top,cam->near,cam->far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(cam->position.x+eye.x, cam->position.y+eye.y, cam->position.z+eye.z,
cam->target.x+eye.x, cam->target.y+eye.y, cam->target.z+eye.z,
cam->up.x, cam->up.y, cam->up.z);
_ctx->draw3d();
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glAccum(GL_LOAD,1.0);
//left eye
glDrawBuffer(GL_BACK);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
left = - cam->screenratio * cam->wd2 + 0.5 * cam->eyesep * cam->ndfl;
right = cam->screenratio * cam->wd2 + 0.5 * cam->eyesep * cam->ndfl;
top = cam->wd2;
bottom = - cam->wd2;
glFrustum(left,right,bottom,top,cam->near,cam->far);
glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_TRUE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(cam->position.x-eye.x, cam->position.y-eye.y, cam->position.z-eye.z,
cam->target.x-eye.x, cam->target.y-eye.y, cam->target.z-eye.z,
cam->up.x, cam->up.y, cam->up.z);
_ctx->draw3d();
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glAccum(GL_ACCUM,1.0);
glAccum(GL_RETURN,1.0);
*/
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
//right eye
XYZ eye =cam->eyesep / 2.0* cam->right;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double left = - cam->screenratio * cam->wd2 - 0.5 * cam->eyesep * cam->ndfl;
double right = cam->screenratio * cam->wd2 - 0.5 * cam->eyesep * cam->ndfl;
double top = cam->wd2;
double bottom = - cam->wd2;
glFrustum(left,right,bottom,top,cam->near,cam->far);
glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(cam->position.x+eye.x, cam->position.y+eye.y, cam->position.z+eye.z,
cam->target.x+eye.x, cam->target.y+eye.y, cam->target.z+eye.z,
cam->up.x, cam->up.y, cam->up.z);
_ctx->draw3d();
_ctx->draw2d();
//left eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
left = - cam->screenratio * cam->wd2 + 0.5 * cam->eyesep * cam->ndfl;
right = cam->screenratio * cam->wd2 + 0.5 * cam->eyesep * cam->ndfl;
top = cam->wd2;
bottom = - cam->wd2;
glFrustum(left,right,bottom,top,cam->near,cam->far);
glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(cam->position.x-eye.x, cam->position.y-eye.y, cam->position.z-eye.z,
cam->target.x-eye.x, cam->target.y-eye.y, cam->target.z-eye.z,
cam->up.x, cam->up.y, cam->up.z);
_ctx->draw3d();
_ctx->draw2d();
glPushMatrix();
}
else{
_ctx->draw3d();
_ctx->draw2d();
_drawScreenMessage();
_drawBorder();
}
}
_lock = false;
}
......@@ -268,7 +369,29 @@ int openglWindow::handle(int event)
_trySelectionXYWH[3] = (int)fabs(_click.win[1] - _curr.win[1]);
}
else{
lassoZoom(_ctx, _click, _curr);
if (CTX::instance()->camera){
Camera * cam= &(_ctx->camera);
double dy=fabs( -_click.win[1] + _curr.win[1] );
double dx=fabs( -_click.win[0] + _curr.win[0] ) ;
double factx = w()/ fabs(dx);
double facty = h()/ fabs(dy);
double fact=.8* std::min(factx, facty);
double x_med=( _click.win[0] + _curr.win[0])/2.;
double y_med=( _click.win[1] + _curr.win[1])/2.;
double theta_x =.96* cam->radians*( w()/2 - x_med )*2. /h() ;
double theta_y =.96* cam->radians*( h()/2 - y_med )*2. /h() ;
cam->moveRight(theta_x);
cam->moveUp(theta_y);
_ctx->camera.zoom(fact);
_ctx->camera.update();
redraw();
}
else{
lassoZoom(_ctx, _click, _curr);
}
}
}
else if(CTX::instance()->mouseSelection){
......@@ -284,9 +407,10 @@ int openglWindow::handle(int event)
(Fl::event_button() == 1 && Fl::event_state(FL_SHIFT))) {
if(!lassoMode && Fl::event_state(FL_CTRL)) {
// make zoom isotropic
_ctx->s[1] = _ctx->s[0];
_ctx->s[2] = _ctx->s[0];
redraw();
_ctx->s[1] = _ctx->s[0];
_ctx->s[2] = _ctx->s[0];
redraw();
}
else if(lassoMode) {
lassoMode = false;
......@@ -309,6 +433,7 @@ int openglWindow::handle(int event)
_trySelectionXYWH[1] = (int)_curr.win[1];
_trySelectionXYWH[2] = 5;
_trySelectionXYWH[3] = 5;
}
}
else {
......@@ -327,7 +452,7 @@ int openglWindow::handle(int event)
}
_click.set(_ctx, Fl::event_x(), Fl::event_y());
_prev.set(_ctx, Fl::event_x(), Fl::event_y());
FlGui::instance()->manip->update();
FlGui::instance()->manip->update();
return 1;
case FL_RELEASE:
......@@ -345,12 +470,19 @@ int openglWindow::handle(int event)
{
double dy = Fl::event_dy();
double fact = (5. * CTX::instance()->zoomFactor * fabs(dy) + h()) / (double)h();
_ctx->s[0] *= ((dy > 0) ? fact : 1./fact);
_ctx->s[1] = _ctx->s[0];
_ctx->s[2] = _ctx->s[0];
_prev.recenter(_ctx);
redraw();
}
if (CTX::instance()->camera){
fact= ((dy > 0) ? fact : 1./fact);
_ctx->camera.zoom(fact);
_ctx->camera.update();
redraw();
}else{
_ctx->s[0] *= ((dy > 0) ? fact : 1./fact);
_ctx->s[1] = _ctx->s[0];
_ctx->s[2] = _ctx->s[0];
_prev.recenter(_ctx);
redraw();
}
}
FlGui::instance()->manip->update();
return 1;
......@@ -390,23 +522,44 @@ int openglWindow::handle(int event)
// but start point is the center of the homothety
else if(Fl::event_button() == 2 ||
(Fl::event_button() == 1 && Fl::event_state(FL_SHIFT))) {
// zoom isotrop in camera mode
if (CTX::instance()->camera){
double dy= (int)_curr.win[1] - (int)_prev.win[1] ;
double fact =( CTX::instance()->zoomFactor * fabs(dy) +(double) h()) / (double)h();
fact= ((dy > 0) ? fact : 1./fact);
_ctx->camera.zoom(fact);
_ctx->camera.update();
redraw();
}
else{
// move in y greater than move in x
if(fabs(dy) > fabs(dx)) {
double fact = (CTX::instance()->zoomFactor * fabs(dy) + h()) / (double)h();
_ctx->s[0] *= ((dy > 0) ? fact : 1./fact);
_ctx->s[1] = _ctx->s[0];
_ctx->s[2] = _ctx->s[0];
_click.recenter(_ctx);
}
// trackball
else if(!CTX::instance()->useTrackball)
_ctx->r[2] += -180. * dx / (double)w();
if(fabs(dy) > fabs(dx)) {
double fact = (CTX::instance()->zoomFactor * fabs(dy) + h()) / (double)h();
_ctx->s[0] *= ((dy > 0) ? fact : 1./fact);
_ctx->s[1] = _ctx->s[0];
_ctx->s[2] = _ctx->s[0];
_click.recenter(_ctx);
}
// trackball
else if(!CTX::instance()->useTrackball)
_ctx->r[2] += -180. * dx / (double)w();
}
}
// other case => translation
else {
_ctx->t[0] += (_curr.wnr[0] - _click.wnr[0]);
_ctx->t[1] += (_curr.wnr[1] - _click.wnr[1]);
_ctx->t[2] = 0.;
if (CTX::instance()->camera){
Camera * cam= &(_ctx->camera);
double theta_x=cam->radians*( -(double)_prev.win[0]+ (double)_curr.win[0] )*2. /h() ;
double theta_y=cam->radians*( -(double)_prev.win[1]+ (double)_curr.win[1] )*2. /h() ;
cam->moveRight(theta_x);
cam->moveUp(theta_y);
}
else{
_ctx->t[0] += (_curr.wnr[0] - _click.wnr[0]);
_ctx->t[1] += (_curr.wnr[1] - _click.wnr[1]);
_ctx->t[2] = 0.;
}
}
CTX::instance()->drawRotationCenter = 1;
if(CTX::instance()->fastRedraw) {
......
......@@ -26,7 +26,8 @@ void Camera::init(){
near=0.1 ;
far=10000;
eye_sep_ratio=.015;
aperture = 40;
// apparent angle of the screen height
aperture = 25;
focallength = 100.;
alongZ();
this->lookAtCg();
......@@ -73,8 +74,8 @@ void Camera::lookAtCg(){
double H=CTX::instance()->max[1]-CTX::instance()->min[1];
double P=CTX::instance()->max[2]-CTX::instance()->min[2];
Lc=sqrt(1.*W*W+1.*H*H+1.*P*P);
//distance=fabs(.5*Lc*4./3./tan(aperture*.01745329/2.));
distance=Lc*1.45;
distance=.8*fabs(.5*Lc*4./3./tan(aperture*.01745329/2.));
//distance=Lc*1.45;
position=target-distance*view;
this->update();
focallength=distance;
......@@ -100,7 +101,7 @@ void Camera::update() {
normalize(up);
normalize(right);
normalize(view);
radians = 0.0174532925 * aperture / 2;
radians = 0.0174532925 * aperture / 2.;
wd2 = near * tan(radians);
ndfl = near / focallength;
}
......@@ -135,7 +136,7 @@ void Camera::affiche() {
void Camera::moveRight(double theta) {
void Camera::moveRight(double& theta) {
this->update();
position=position-distance*tan(theta)*right;
target=position+distance*view;
......@@ -143,7 +144,7 @@ void Camera::moveRight(double theta) {
}
void Camera::moveUp(double theta) {
void Camera::moveUp(double& theta) {
this->update();
position=position+distance*tan(theta)*up;
target=position+distance*view;
......@@ -151,6 +152,12 @@ void Camera::moveUp(double theta) {
}
void Camera::zoom(double& factor) {
distance=fabs(1./factor*ref_distance);
position=target-distance*view;
}
void Camera::rotate(double* q) {
this->update();
// rotation projection in global coordinates
......
......@@ -81,8 +81,9 @@ public:
void lookAtCg();
void init();
void rotate(double* q);
void moveRight(double theta);
void moveUp(double theta);
void moveRight(double& theta);
void moveUp(double& theta);
void zoom(double& factor);
void update();
void affiche();
void alongX();
......
......@@ -344,6 +344,12 @@ void drawContext::drawSmallAxes()
double xx, xy, yx, yy , zx, zy;
if (CTX::instance()->camera) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(camera.position.x,camera.position.y,camera.position.z,
camera.target.x,camera.target.y,camera.target.z,
camera.up.x,camera.up.y,camera.up.z);
glPushMatrix();
glPopMatrix();
float fvViewMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, fvViewMatrix);
......
......@@ -276,16 +276,11 @@ void drawContext::draw3d()
initProjection();
initRenderModel();
if(CTX::instance()->camera) {
}
else{
initPosition();
}
drawAxes();
drawGeom();
drawMesh();
drawPost();
if(!CTX::instance()->camera) initPosition();
drawAxes();
drawGeom();
drawMesh();
drawPost();
}
......@@ -460,7 +455,7 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick)
fabs(CTX::instance()->max[2]));
if(zmax < CTX::instance()->lc) zmax = CTX::instance()->lc;
if (CTX::instance()->camera) { // if we use the new camera mode
if (CTX::instance()->camera ) { // if we use the new camera mode
double clip_near, clip_far;
clip_near = 0.75 * CTX::instance()->clipFactor * zmax;
......@@ -488,7 +483,7 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick)
glEnable(GL_DEPTH_TEST);
}
else{ // if not in camera mode
else if(!CTX::instance()->camera){ // if not in camera mode
double clip_near, clip_far;
if(CTX::instance()->ortho) {
......
......@@ -12,3 +12,4 @@ Plane Surface(6) = {5};
Extrude {0,0.0,1} {
Surface{6};
}
Show "*";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment