summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <johannes.hofmann@gmx.de>2005-04-17 18:03:13 +0000
committerJohannes Hofmann <johannes.hofmann@gmx.de>2005-04-17 18:03:13 +0000
commit53ff36907392c1d4775bcfdfb6201bd210fdb23b (patch)
tree84530d4758999c71f86c8710a174986213df29b1
parentd2a7cbd2527455ccf070d748d72c69a43330b6a1 (diff)
nick geht
nick geht
-rw-r--r--src/GipfelWidget.H6
-rw-r--r--src/GipfelWidget.cxx17
-rw-r--r--src/Makefile8
-rw-r--r--src/Panorama.H15
-rw-r--r--src/Panorama.cxx88
-rw-r--r--src/gipfel.cxx14
6 files changed, 104 insertions, 44 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 85585ba..1fc898e 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -1,5 +1,5 @@
//
-// "$Id: GipfelWidget.H,v 1.6 2005/04/14 21:15:45 hofmann Exp $"
+// "$Id: GipfelWidget.H,v 1.7 2005/04/17 20:03:13 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -37,7 +37,7 @@ class GipfelWidget : public Fl_Widget {
int set_cur_mountain(int m_x, int m_y);
- int move_mountain(int m_x, int m_y);
+ int set_mountain(int m_x, int m_y);
public:
GipfelWidget(int X,int Y,int W, int H);
@@ -55,6 +55,8 @@ class GipfelWidget : public Fl_Widget {
void set_scale(double s);
void set_height_dist_ratio(double r);
+
+ int comp_params();
void draw();
};
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 173f889..b10653b 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: GipfelWidget.cxx,v 1.8 2005/04/14 21:48:28 hofmann Exp $"
+// "$Id: GipfelWidget.cxx,v 1.9 2005/04/17 20:03:13 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -127,15 +127,16 @@ GipfelWidget::set_cur_mountain(int m_x, int m_y) {
}
int
-GipfelWidget::move_mountain(int m_x, int m_y) {
+GipfelWidget::set_mountain(int m_x, int m_y) {
int ret;
- int center = w() / 2;
+ int center_x = w() / 2;
+ int center_y = h() / 2;
if (cur_mountain == NULL) {
return 1;
}
- ret = pan->move_mountain(cur_mountain, m_x - center, m_y - center);
+ ret = pan->set_mountain(cur_mountain, m_x - center_x, m_y - center_y);
redraw();
return ret;
@@ -166,6 +167,12 @@ GipfelWidget::set_height_dist_ratio(double r) {
}
int
+GipfelWidget::comp_params() {
+ pan->comp_params();
+ redraw();
+}
+
+int
GipfelWidget::handle(int event) {
int mark_x, mark_y;
@@ -183,7 +190,7 @@ GipfelWidget::handle(int event) {
}
break;
case FL_DRAG:
- move_mountain(Fl::event_x()-x(), Fl::event_y()-y());
+ set_mountain(Fl::event_x()-x(), Fl::event_y()-y());
return 1;
break;
case FL_FOCUS:
diff --git a/src/Makefile b/src/Makefile
index 7edcf67..e42ae7b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,8 +1,8 @@
CC=gcc
CPP=c++
CFLAGS=-g -I/usr/X11R6/include
-CXXFLAGS=-g -I/usr/X11R6/include
-LDFLAGS=-g
+CXXFLAGS=-g -I/usr/X11R6/include -fno-stack-protector
+LDFLAGS=-g -fno-stack-protector
OBJECTS=flmountains.o GipfelWidget.o Mountain.o Panorama.o
@@ -10,10 +10,10 @@ OBJECTS=flmountains.o GipfelWidget.o Mountain.o Panorama.o
# $(CC) -c $(CFLAGS) $*.c
%.o: %.cxx
- $(CPP) -c $(CFLAGS) $*.cxx
+ $(CPP) -c $(CXXFLAGS) $*.cxx
gipfel: $(OBJECTS)
- $(CC) -o gipfel $(OBJECTS) -L/usr/X11R6/lib -lm -lfltk -lfltk_images
+ $(CC) -fno-stack-protector -o gipfel $(OBJECTS) -L/usr/X11R6/lib -lm -lfltk -lfltk_images
flmountains: $(flmountains.o)
$(CPP) -o flmountains flmountains.o -L/usr/X11R6/lib -lm -lfltk -lfltk_images
diff --git a/src/Panorama.H b/src/Panorama.H
index 7bacb09..c8dc77b 100644
--- a/src/Panorama.H
+++ b/src/Panorama.H
@@ -1,5 +1,5 @@
//
-// "$Id: Panorama.H,v 1.4 2005/04/14 21:15:45 hofmann Exp $"
+// "$Id: Panorama.H,v 1.5 2005/04/17 20:03:13 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -34,8 +34,10 @@ class Panorama {
Mountain *visible_mountains;
Mountain *m1, *m2;
double pi, deg2rad;
- double a_center, a_nick;
+ double a_center;
double scale;
+ double a_nick;
+ double a_tilt;
int get_pos(const char *name, double *phi, double *lam, double *height);
@@ -51,11 +53,9 @@ class Panorama {
double nick(double dist, double height);
- double center_angle(double alph_a, double alph_b, double d1, double d2);
+ double comp_center_angle(double alph_a, double alph_b, double d1, double d2);
- int get_x(Mountain *m);
-
- int get_y(Mountain *m);
+ double comp_scale(double alph_a, double alph_b, double d1, double d2);
public:
Panorama();
@@ -70,7 +70,7 @@ class Panorama {
Mountain * get_visible_mountains();
- int move_mountain(Mountain *m, int x, int y);
+ int set_mountain(Mountain *m, int x, int y);
void set_center_angle(double a);
@@ -78,5 +78,6 @@ class Panorama {
void set_scale(double s);
+ int comp_params();
};
#endif
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index f6a5916..e3dfa21 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Panorama.cxx,v 1.6 2005/04/14 21:15:45 hofmann Exp $"
+// "$Id: Panorama.cxx,v 1.7 2005/04/17 20:03:13 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -38,6 +38,7 @@ Panorama::Panorama() {
deg2rad = pi / 180.0;
a_center = 0.0;
a_nick = 0.0;
+ a_tilt = 0.0;
scale = 20.0;
}
@@ -109,64 +110,71 @@ Mountain *
Panorama::get_visible_mountains() {
return visible_mountains;
}
-
-int
-Panorama::get_x(Mountain *m) {
- return (int) (tan(m->a_view) * scale);
-}
-
-int
-Panorama::get_y(Mountain *m) {
- return - (int) (tan(m->a_nick - a_nick) * scale);
-}
int
-Panorama::move_mountain(Mountain *m, int x, int y) {
+Panorama::set_mountain(Mountain *m, int x, int y) {
if (m1 && m2 && m != m1 && m != m2) {
return 1;
}
m->x = x;
+ m->y = y;
if (m1 == NULL) {
m1 = m;
+ fprintf(stderr, "m1=%s\n", m1->name);
} else if (m2 == NULL && m != m1) {
m2 = m;
- } else if (m1 && m2) {
- a_center = center_angle(m1->alph, m2->alph, m1->x, m2->x);
- scale = (m1->x - m2->x) /
- (tan(m1->alph - a_center) - tan(m2->alph - a_center));
- fprintf(stderr, "center = %f, scale = %f\n", a_center /deg2rad, scale);
- update_visible_mountains();
+ fprintf(stderr, "m2=%s\n", m2->name);
+ }
+}
+
+int
+Panorama::comp_params() {
+ if (m1 == NULL || m2 == NULL) {
+ fprintf(stderr, "Position two mountains first.\n");
+ m1 = NULL;
+ m2 = NULL;
+ return 1;
}
+
+ 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, m1->x, m2->x);
+ scale = comp_scale(m1->alph, m2->alph, m1->x, m2->x);
+ fprintf(stderr, "center = %f, scale = %f, nick=%f\n", a_center /deg2rad, scale, a_nick/deg2rad);
+ a_nick = atan ((m1->y + tan(m1->a_nick) * scale) / ( scale - m1->y * tan(m1->a_nick)));
+ // a_nick = comp_center_angle(m1->a_nick, m2->a_nick, -m1->y, -m2->y) - pi;
+ fprintf(stderr, "center = %f, scale = %f, nick=%f\n", a_center /deg2rad, scale, a_nick/deg2rad);
+ update_visible_mountains();
+
+ m1 = NULL;
+ m2 = NULL;
return 0;
}
void
Panorama::set_center_angle(double a) {
a_center = a;
- fprintf(stderr, "--> angle%f\n", a);
update_visible_mountains();
}
void
Panorama::set_nick_angle(double a) {
a_nick = a;
+ fprintf(stderr, "-->nick%f\n", a_nick/deg2rad);
update_visible_mountains();
}
void
Panorama::set_scale(double s) {
scale = s;
- fprintf(stderr, "-->scale %f\n", s);
update_visible_mountains();
}
void
Panorama::set_height_dist_ratio(double r) {
height_dist_ratio = r;
- fprintf(stderr, "-->ratio %f\n", r);
update_visible_mountains();
}
@@ -202,6 +210,7 @@ void
Panorama::update_visible_mountains() {
Mountain *m = mountains;
visible_mountains = NULL;
+ double x1, y1;
while (m) {
m->dist = distance(m->phi, m->lam);
@@ -221,8 +230,12 @@ Panorama::update_visible_mountains() {
if (m->a_view < pi / 2.0 && m->a_view > - pi / 2.0) {
m->a_nick = nick(m->dist, m->height);
- m->x = get_x(m);
- m->y = get_y(m);
+ x1 = tan(m->a_view) * scale;
+ y1 = - (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->clear_next_visible();
if (visible_mountains) {
visible_mountains->append_visible(m);
@@ -271,6 +284,7 @@ Panorama::alpha(double phi, double lam) {
return alph;
}
+#if 0
double
Panorama::center_angle(double alph_a, double alph_b, double d1, double d2) {
double tan_a, tan_b;
@@ -282,6 +296,34 @@ Panorama::center_angle(double alph_a, double alph_b, double d1, double d2) {
fprintf(stderr, "tan_b=%f\n", tan_b);
return alph_a + atan(tan_b);
}
+#endif
+
+double
+Panorama::comp_center_angle(double a1, double a2, double d1, double d2) {
+ double sign1 = 1.0;
+ double tan_acenter, tan_a1, tan_a2;
+
+ tan_a1 = tan(a1);
+ tan_a2 = tan(a2);
+
+ tan_acenter = (((pow(((pow((1.0 + (tan_a1 * tan_a2)), 2.0) * ((d1 * d1) + (d2 * d2))) + (2.0 * d1 * d2 * ((2.0 * ((tan_a2 * tan_a1) - (tan_a2 * tan_a2))) - ((tan_a1 * tan_a1) * (2.0 + (tan_a2 * tan_a2))) - 1.0))), (1.0 / 2.0)) * sign1) + ((1.0 - (tan_a1 * tan_a2)) * (d1 - d2))) / (2.0 * ((d2 * tan_a2) - (d1 * tan_a1))));
+
+ return atan(tan_acenter) + pi;
+}
+
+double
+Panorama::comp_scale(double a1, double a2, double d1, double d2) {
+ double sign1 = 1.0;
+ double sc, tan_a1, tan_a2;
+
+ tan_a1 = tan(a1);
+ tan_a2 = tan(a2);
+
+ sc = ((((1.0 + (tan_a1 * tan_a2)) * (d1 - d2)) - (sign1 * pow((((1.0 + pow((tan_a1 * tan_a2), 2.0)) * ((d1 * d1) + (d2 * d2))) + (2.0 * ((tan_a1 * tan_a2 * pow((d1 + d2), 2.0)) - (d1 * d2 * (((tan_a1 * tan_a1) * (2.0 + (tan_a2 * tan_a2))) + 1.0 + (2.0 * (tan_a2 * tan_a2))))))), (1.0 / 2.0)))) / (2.0 * (tan_a1 - tan_a2)));
+
+ return sc;
+}
+
double
Panorama::nick(double dist, double height) {
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index 3305312..c940a56 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: gipfel.cxx,v 1.9 2005/04/14 21:48:28 hofmann Exp $"
+// "$Id: gipfel.cxx,v 1.10 2005/04/17 20:03:13 hofmann Exp $"
//
// flpsed program.
//
@@ -78,6 +78,12 @@ void h_d_cb(Fl_Slider* o, void*) {
}
}
+void comp_cb(Fl_Widget *, void *) {
+ if (gipf) {
+ gipf->comp_params();
+ }
+}
+
void about_cb() {
fl_message("flpsed -- a pseudo PostScript editor\n"
"(c) Johannes Hofmann 2004, 2005\n\n"
@@ -161,8 +167,8 @@ int main(int argc, char** argv) {
s->type(1);
s->box(FL_THIN_DOWN_BOX);
s->labelsize(10);
- s->step(10.0);
- s->bounds(0.0, 2000.0);
+ s->step(5.0);
+ s->bounds(0.0, 10000.0);
s->slider(FL_UP_BOX);
s->callback((Fl_Callback*)scale_cb);
s->align(FL_ALIGN_LEFT);
@@ -184,6 +190,8 @@ int main(int argc, char** argv) {
r->slider(FL_UP_BOX);
r->callback((Fl_Callback*)h_d_cb);
r->align(FL_ALIGN_LEFT);
+ Fl_Button *b = new Fl_Button(780, 45, 20, 15, "comp");
+ b->callback(comp_cb);
scroll = new Fl_Scroll(0, 60, win->w(), win->h()-60);