From d1d892145b6aa9f44d09b25f8cdab825fea74dbb Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 30 Apr 2005 05:58:19 +0000 Subject: fix newton. fix newton. --- src/GipfelWidget.H | 4 ++- src/GipfelWidget.cxx | 18 ++++++++++-- src/Panorama.cxx | 82 +++++++++++++++++++++++++++++----------------------- src/gipfel.cxx | 5 +++- 4 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 2d05f2c..698887f 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.H,v 1.9 2005/04/24 09:51:17 hofmann Exp $" +// "$Id: GipfelWidget.H,v 1.10 2005/04/30 07:58:19 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -25,6 +25,7 @@ #define GipfelWidget_H #include +#include #include "Panorama.H" class GipfelWidget : public Fl_Widget { @@ -32,6 +33,7 @@ class GipfelWidget : public Fl_Widget { Fl_Image *img; Mountain *cur_mountain; Panorama *pan; + Fl_Menu_Button *mb; int handle(int event); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 365def1..4bdc991 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.cxx,v 1.11 2005/04/24 09:51:17 hofmann Exp $" +// "$Id: GipfelWidget.cxx,v 1.12 2005/04/30 07:58:19 hofmann Exp $" // // PSEditWidget routines. // @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -39,11 +40,18 @@ #include "GipfelWidget.H" - +static Fl_Menu_Item menuitems[] = { + { "&File", 0, 0, 0, FL_SUBMENU }, + { "&Open File...", FL_CTRL + 'o', NULL}, + {0}, + { 0 } +}; + GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) { img = NULL; pan = new Panorama(); cur_mountain = NULL; + mb = NULL; fl_register_images(); } @@ -57,6 +65,12 @@ GipfelWidget::load_image(const char *file) { w(img->w()); h(img->h()); + + mb = new Fl_Menu_Button(x(),y(),w()+x(),h()+y(),"&popup"); + mb->type(Fl_Menu_Button::POPUP3); + mb->box(FL_NO_BOX); + mb->menu(menuitems); + return 0; } diff --git a/src/Panorama.cxx b/src/Panorama.cxx index dee2168..30f8a31 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -1,5 +1,5 @@ // -// "$Id: Panorama.cxx,v 1.12 2005/04/27 19:26:07 hofmann Exp $" +// "$Id: Panorama.cxx,v 1.13 2005/04/30 07:58:19 hofmann Exp $" // // PSEditWidget routines. // @@ -142,12 +142,12 @@ Panorama::comp_params() { return 1; } - x2 = m2->x; - y2 = m2->y; - x1 = m1->x; y1 = m1->y; + x2 = m2->x; + y2 = m2->y; + fprintf(stderr, "center = %f, scale = %f, nick=%f\n", a_center /deg2rad, scale, a_nick/deg2rad); a_center = comp_center_angle(m1->alph, m2->alph, x1, x2); scale = comp_scale(m1->alph, m2->alph, x1, x2); @@ -155,11 +155,43 @@ Panorama::comp_params() { a_nick = atan ((y1 + tan(m1->a_nick) * scale) / ( scale - y1 * tan(m1->a_nick))); // a_nick = comp_center_angle(m1->a_nick, m2->a_nick, -y1, -y2) - pi; fprintf(stderr, "center = %f, scale = %f, nick=%f\n", a_center /deg2rad, scale, a_nick/deg2rad); - update_visible_mountains(); + #if 0 m1 = NULL; m2 = NULL; #endif + + tan_nick_view = tan(a_nick); + tan_dir_view = tan(a_center); + n_scale = scale; + tan_dir_m1 = tan(m1->alph); + tan_nick_m1 = tan(m1->a_nick); + tan_dir_m2 = tan(m2->alph); + tan_nick_m2 = tan(m2->a_nick); + + newton(); + newton(); + newton(); + newton(); + + a_nick = atan(tan_nick_view); + a_center = atan(tan_dir_view); + + if (fabs(a_center - m1->alph) > pi/2.0) { + a_center = a_center + pi; + } + if (a_center > 2.0 * pi) { + a_center = a_center - 2.0 * pi; + } else if (a_center < 0.0) { + a_center = a_center + 2.0 * pi; + } + + scale = n_scale; + + a_tilt = comp_tilt(); + fprintf(stderr, "center = %f, scale = %f, nick=%f tilt %f\n", a_center /deg2rad, scale, a_nick/deg2rad, a_tilt/deg2rad); + update_visible_mountains(); + return 0; } @@ -227,7 +259,7 @@ void Panorama::update_visible_mountains() { Mountain *m = mountains; visible_mountains = NULL; - double x1, y1; + double x_tmp, y_tmp; while (m) { @@ -247,11 +279,11 @@ Panorama::update_visible_mountains() { // fprintf(stderr, "==> %s %f, dist %f km %f\n", m->name, m->alph, distance(m->phi, m->lam)* 6368, m->a_view); if (m->a_view < pi / 2.0 && m->a_view > - pi / 2.0) { m->a_nick = nick(m->dist, m->height); - x1 = tan(m->a_view) * scale; - y1 = - (tan(m->a_nick - a_nick) * scale); + x_tmp = tan(m->a_view) * scale; + y_tmp = - (tan(m->a_nick - a_nick) * scale); // rotate by a_tilt; - m->x = (int) (x1 * cos(a_tilt) - y1 * sin(a_tilt)); - m->y = (int) (x1 * sin(a_tilt) + y1 * cos(a_tilt)); + m->x = (int) rint(x_tmp * cos(a_tilt) - y_tmp * sin(a_tilt)); + m->y = (int) rint(x_tmp * sin(a_tilt) + y_tmp * cos(a_tilt)); m->clear_next_visible(); if (visible_mountains) { @@ -402,14 +434,6 @@ Panorama::newton() { double a_x0[3], f_x0 [3], x0[3]; int ret; - tan_nick_view = tan(a_nick); - tan_dir_view = tan(a_center); - n_scale = scale; - tan_dir_m1 = tan(m1->alph); - tan_nick_m1 = tan(m1->a_nick); - tan_dir_m2 = tan(m2->alph); - tan_nick_m2 = tan(m2->a_nick); - fprintf(stderr, "m1: %d, %d; m2: %d, %d\n", x1, y1, x2, y2); d_m1_2 = pow(x1, 2.0) + pow(y1, 2.0); d_m2_2 = pow(x2, 2.0) + pow(y2, 2.0); @@ -442,25 +466,11 @@ Panorama::newton() { ret = solv(a, b, 3); fprintf(stderr, "solv returned %d\n", ret); - a_nick = atan(b[0]); - a_center = atan(b[1]); - fprintf(stderr, "==> m1->alph %f, a_center = %f\n", m1->alph/deg2rad, - a_center/deg2rad); - if (fabs(a_center - m1->alph) > pi/2.0) { - a_center = a_center + pi; - fprintf(stderr, "==> adding pi => %f\n", a_center); - } - if (a_center > 2.0 * pi) { - a_center = a_center - 2.0 * pi; - } else if (a_center < 0.0) { - a_center = a_center + 2.0 * pi; - } - - scale = b[2]; - a_tilt = comp_tilt(); - fprintf(stderr, "center = %f, scale = %f, nick=%f tilt %f\n", a_center /deg2rad, scale, a_nick/deg2rad, a_tilt/deg2rad); - update_visible_mountains(); + tan_nick_view = b[0]; + tan_dir_view = b[1]; + n_scale = b[2]; + return 0; } diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 8335abb..536a5d4 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -1,5 +1,5 @@ // -// "$Id: gipfel.cxx,v 1.12 2005/04/24 09:51:17 hofmann Exp $" +// "$Id: gipfel.cxx,v 1.13 2005/04/30 07:58:19 hofmann Exp $" // // flpsed program. // @@ -216,6 +216,9 @@ int main(int argc, char** argv) { Fl_Button *b1 = new Fl_Button(250, 60, 20, 15, "opt"); b1->callback(newton_cb); + + + scroll = new Fl_Scroll(0, 75, win->w(), win->h()-75); gipf = new GipfelWidget(0,75,500,500); -- cgit v1.2.3